2 // Unit tests for System.ServiceModel.CommunicationObject
5 // Moonlight List (moonlight-list@lists.ximian.com)
7 // Copyright (C) 2011 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ServiceModel;
32 using System.ServiceModel.Channels;
34 // the file 'NUnitMoonHelper.cs' makes the Moon's unit test compiles and runs on NUnit
35 using Microsoft.VisualStudio.TestTools.UnitTesting;
36 using Mono.Moonlight.UnitTesting;
38 namespace MonoTests.System.ServiceModel.Channels {
41 public class CommunicationObjectSyncTest {
43 class CommunicationObjectPoker : CommunicationObject {
45 public CommunicationObjectPoker ()
49 public CommunicationObjectPoker (object o)
54 public bool DefaultCloseTimeoutCalled { get; set; }
55 public bool DefaultOpenTimeoutCalled { get; set; }
57 public bool OnBeginCloseCalled { get; set; }
58 public bool OnCloseCalled { get; set; }
59 public bool OnEndCloseCalled { get; set; }
61 public bool OnBeginOpenCalled { get; set; }
62 public bool OnOpenCalled { get; set; }
63 public bool OnEndOpenCalled { get; set; }
65 public bool OnAbortCalled { get; set; }
66 public CommunicationState OnAbortState { get; set; }
68 public bool Disposed {
69 get { return IsDisposed; }
72 protected override TimeSpan DefaultCloseTimeout {
74 DefaultCloseTimeoutCalled = true;
79 protected override TimeSpan DefaultOpenTimeout {
81 DefaultOpenTimeoutCalled = true;
86 protected override void OnAbort ()
89 Assert.AreEqual (OnAbortState, State, "OnAbort/State");
90 Assert.IsFalse (Disposed, "OnAbort/IsDisposed");
93 protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
95 OnBeginCloseCalled = true;
99 protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
101 OnBeginOpenCalled = true;
105 protected override void OnClose (TimeSpan timeout)
107 OnCloseCalled = true;
110 protected override void OnEndClose (IAsyncResult result)
112 OnEndCloseCalled = true;
115 protected override void OnEndOpen (IAsyncResult result)
117 OnEndOpenCalled = true;
120 protected override void OnOpen (TimeSpan timeout)
125 public void _Fault ()
128 Assert.AreEqual (CommunicationState.Faulted, State, "Fault/State");
129 Assert.IsFalse (Disposed, "Fault/IsDisposed");
132 public void _FaultNoAssert ()
137 public object _ThisLock {
138 get { return ThisLock; }
141 public void _ThrowIfDisposed ()
146 public void _ThrowIfDisposedOrImmutable ()
148 ThrowIfDisposedOrImmutable ();
151 public void _ThrowIfDisposedOrNotOpen ()
153 ThrowIfDisposedOrNotOpen ();
158 public void Constructor ()
160 CommunicationObjectPoker co = new CommunicationObjectPoker ();
161 Assert.AreEqual (typeof (object), co._ThisLock.GetType (), "ThisLock/default");
163 co = new CommunicationObjectPoker (null);
164 Assert.IsNull (co._ThisLock, "ThisLock/null");
166 co = new CommunicationObjectPoker (String.Empty);
167 Assert.AreSame (String.Empty, co._ThisLock, "ThisLock/weak");
174 [NUnit.Framework.Ignore]
176 public void Create_Abort ()
181 CommunicationObjectPoker co = new CommunicationObjectPoker ();
182 co.Closing += delegate (object sender, EventArgs e) {
184 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
185 Assert.AreSame (co, sender, "Closing/sender");
186 Assert.AreSame (EventArgs.Empty, e, "Closing/e");
188 Assert.IsFalse (co.Disposed, "Closing/Disposed");
189 Assert.Throws<CommunicationObjectAbortedException> (delegate {
190 co._ThrowIfDisposed ();
191 }, "Closing/ThrowIfDisposed");
192 Assert.Throws<CommunicationObjectAbortedException> (delegate {
193 co._ThrowIfDisposedOrImmutable ();
194 }, "Closing/ThrowIfDisposedOrImmutable");
195 Assert.Throws<CommunicationObjectAbortedException> (delegate {
196 co._ThrowIfDisposedOrNotOpen ();
197 }, "Closing/ThrowIfDisposedOrNotOpen");
199 co.Closed += delegate (object sender, EventArgs e) {
201 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
202 Assert.AreSame (co, sender, "Closed/sender");
203 Assert.AreSame (EventArgs.Empty, e, "Closed/e");
205 Assert.IsTrue (co.Disposed, "Closed/Disposed");
206 Assert.Throws<CommunicationObjectAbortedException> (delegate {
207 co._ThrowIfDisposed ();
208 }, "Closed/ThrowIfDisposed");
209 Assert.Throws<CommunicationObjectAbortedException> (delegate {
210 co._ThrowIfDisposedOrImmutable ();
211 }, "Closed/ThrowIfDisposedOrImmutable");
212 Assert.Throws<CommunicationObjectAbortedException> (delegate {
213 co._ThrowIfDisposedOrNotOpen ();
214 }, "Closed/ThrowIfDisposedOrNotOpen");
216 Assert.AreEqual (CommunicationState.Created, co.State, "State/before");
218 co.OnAbortState = CommunicationState.Closing;
220 Assert.AreEqual (1, closing, "closing");
221 Assert.AreEqual (1, closed, "closed");
223 Assert.AreEqual (CommunicationState.Closed, co.State, "State/after");
224 Assert.IsTrue (co.Disposed, "IsDisposed");
226 Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
227 Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
228 Assert.IsTrue (co.OnAbortCalled, "OnAbortCalled");
230 Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled");
231 Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled");
232 Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled");
234 Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled");
235 Assert.IsFalse (co.OnOpenCalled, "OnOpenCalled");
236 Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled");
243 [NUnit.Framework.Ignore]
245 public void Create_Close ()
252 CommunicationObjectPoker co = new CommunicationObjectPoker ();
253 co.Opening += delegate (object sender, EventArgs e) {
255 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
256 Assert.AreSame (co, sender, "Opening/sender");
257 Assert.AreSame (EventArgs.Empty, e, "Opening/e");
259 co.Opened += delegate (object sender, EventArgs e) {
261 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
262 Assert.AreSame (co, sender, "Opened/sender");
263 Assert.AreSame (EventArgs.Empty, e, "Opened/e");
265 co.Closing += delegate (object sender, EventArgs e) {
267 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
268 Assert.AreSame (co, sender, "Closing/sender");
269 Assert.AreSame (EventArgs.Empty, e, "Closing/e");
271 Assert.IsFalse (co.Disposed, "Closing/Disposed");
272 // note: IsDisposed is false but we still throw!
273 // but this match MSDN docs about ThrowIfDisposed
274 Assert.Throws<ObjectDisposedException> (delegate {
275 co._ThrowIfDisposed ();
276 }, "Closing/ThrowIfDisposed");
277 Assert.Throws<ObjectDisposedException> (delegate {
278 co._ThrowIfDisposedOrImmutable ();
279 }, "Closing/ThrowIfDisposedOrImmutable");
280 Assert.Throws<ObjectDisposedException> (delegate {
281 co._ThrowIfDisposedOrNotOpen ();
282 }, "Closing/ThrowIfDisposedOrNotOpen");
284 co.Closed += delegate (object sender, EventArgs e) {
286 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
287 Assert.AreSame (co, sender, "Closed/sender");
288 Assert.AreSame (EventArgs.Empty, e, "Closed/e");
290 Assert.IsTrue (co.Disposed, "Closed/Disposed");
291 Assert.Throws<ObjectDisposedException> (delegate {
292 co._ThrowIfDisposed ();
293 }, "Closed/ThrowIfDisposed");
294 Assert.Throws<ObjectDisposedException> (delegate {
295 co._ThrowIfDisposedOrImmutable ();
296 }, "Closed/ThrowIfDisposedOrImmutable");
297 Assert.Throws<ObjectDisposedException> (delegate {
298 co._ThrowIfDisposedOrNotOpen ();
299 }, "Closed/ThrowIfDisposedOrNotOpen");
301 Assert.AreEqual (CommunicationState.Created, co.State, "State/before");
303 co.OnAbortState = CommunicationState.Closing;
304 // note: since this is not a "direct" abort then ObjectDisposedException
306 Assert.AreEqual (0, opening, "opening");
307 Assert.AreEqual (0, opened, "opened");
308 Assert.AreEqual (1, closing, "closing");
309 Assert.AreEqual (1, closed, "closed");
311 Assert.AreEqual (CommunicationState.Closed, co.State, "State/after");
312 Assert.IsTrue (co.Disposed, "IsDisposed");
314 Assert.IsTrue (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
315 Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
316 Assert.IsTrue (co.OnAbortCalled, "OnAbortCalled");
318 Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled");
319 Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled");
320 Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled");
322 Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled");
323 Assert.IsFalse (co.OnOpenCalled, "OnOpenCalled");
324 Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled");
326 // 2nd time, no events raised
328 Assert.AreEqual (0, opening, "opening-b");
329 Assert.AreEqual (0, opened, "opened-b");
330 Assert.AreEqual (1, closing, "closing-c");
331 Assert.AreEqual (1, closed, "closed-c");
333 Assert.Throws<ObjectDisposedException> (delegate {
336 Assert.AreEqual (0, opening, "opening-c");
337 Assert.AreEqual (0, opened, "opened-c");
338 Assert.AreEqual (1, closing, "closing-c");
339 Assert.AreEqual (1, closed, "closed-c");
346 [NUnit.Framework.Ignore]
348 public void Create_Close_Fault ()
350 bool faulted = false;
352 CommunicationObjectPoker co = new CommunicationObjectPoker ();
353 co.Faulted += delegate (object sender, EventArgs e) {
354 faulted = true; // won't be hit
357 co.Close (); // real Close, not an implicit Abort since Open was called
358 co._FaultNoAssert (); // don't check State since it won't be Faulted
359 Assert.AreEqual (CommunicationState.Closed, co.State, "State/Fault");
360 Assert.IsFalse (faulted, "Faulted");
367 [NUnit.Framework.Ignore]
369 public void Create_Open_Close_Abort ()
376 CommunicationObjectPoker co = new CommunicationObjectPoker ();
377 co.Opening += delegate (object sender, EventArgs e) {
379 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
380 Assert.AreSame (co, sender, "Opening/sender");
381 Assert.AreSame (EventArgs.Empty, e, "Opening/e");
383 co.Opened += delegate (object sender, EventArgs e) {
385 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
386 Assert.AreSame (co, sender, "Opened/sender");
387 Assert.AreSame (EventArgs.Empty, e, "Opened/e");
389 co.Closing += delegate (object sender, EventArgs e) {
391 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
392 Assert.AreSame (co, sender, "Closing/sender");
393 Assert.AreSame (EventArgs.Empty, e, "Closing/e");
395 co.Closed += delegate (object sender, EventArgs e) {
397 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
398 Assert.AreSame (co, sender, "Closed/sender");
399 Assert.AreSame (EventArgs.Empty, e, "Closed/e");
401 Assert.AreEqual (CommunicationState.Created, co.State, "State/before");
404 Assert.AreEqual (1, opening, "opening");
405 Assert.AreEqual (1, opened, "opened");
406 Assert.AreEqual (0, closing, "closing");
407 Assert.AreEqual (0, closed, "closed");
409 Assert.AreEqual (CommunicationState.Opened, co.State, "State/after/open");
410 Assert.IsFalse (co.Disposed, "IsDisposed/open");
412 Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled/open");
413 Assert.IsTrue (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled/open");
414 Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled/open");
416 Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled/open");
417 Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled/open");
418 Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled/open");
420 Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled/open");
421 Assert.IsTrue (co.OnOpenCalled, "OnOpenCalled/open");
422 Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled/open");
425 Assert.AreEqual (1, opening, "opening-b");
426 Assert.AreEqual (1, opened, "opened-b");
427 Assert.AreEqual (1, closing, "closing-b");
428 Assert.AreEqual (1, closed, "closed-b");
430 Assert.AreEqual (CommunicationState.Closed, co.State, "State/close");
431 Assert.IsTrue (co.Disposed, "IsDisposed/close");
433 Assert.IsTrue (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled/close");
434 Assert.IsTrue (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled/close");
435 Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled/close");
437 Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled/close");
438 Assert.IsTrue (co.OnCloseCalled, "OnCloseCalled/close");
439 Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled/close");
441 Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled/close");
442 Assert.IsTrue (co.OnOpenCalled, "OnOpenCalled/close");
443 Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled/close");
446 Assert.AreEqual (1, opening, "opening-c");
447 Assert.AreEqual (1, opened, "opened-c");
448 Assert.AreEqual (1, closing, "closing-c");
449 Assert.AreEqual (1, closed, "closed-c");
451 Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled/abort");
452 Assert.AreEqual (CommunicationState.Closed, co.State, "State/abort");
459 [NUnit.Framework.Ignore]
461 public void Create_Fault_Abort ()
468 CommunicationObjectPoker co = new CommunicationObjectPoker ();
469 co.Opening += delegate (object sender, EventArgs e) {
471 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
472 Assert.AreSame (co, sender, "Opening/sender");
473 Assert.AreSame (EventArgs.Empty, e, "Opening/e");
475 co.Opened += delegate (object sender, EventArgs e) {
477 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
478 Assert.AreSame (co, sender, "Opened/sender");
479 Assert.AreSame (EventArgs.Empty, e, "Opened/e");
481 co.Closing += delegate (object sender, EventArgs e) {
483 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
484 Assert.AreSame (co, sender, "Closing/sender");
485 Assert.AreSame (EventArgs.Empty, e, "Closing/e");
487 Assert.IsFalse (co.Disposed, "Closing/Disposed");
488 // note: IsDisposed is false but we still throw!
489 // but this match MSDN docs about ThrowIfDisposed
490 Assert.Throws<CommunicationObjectAbortedException> (delegate {
491 co._ThrowIfDisposed ();
492 }, "Closing/ThrowIfDisposed");
493 Assert.Throws<CommunicationObjectAbortedException> (delegate {
494 co._ThrowIfDisposedOrImmutable ();
495 }, "Closing/ThrowIfDisposedOrImmutable");
496 Assert.Throws<CommunicationObjectAbortedException> (delegate {
497 co._ThrowIfDisposedOrNotOpen ();
498 }, "Closing/ThrowIfDisposedOrNotOpen");
500 co.Closed += delegate (object sender, EventArgs e) {
502 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
503 Assert.AreSame (co, sender, "Closed/sender");
504 Assert.AreSame (EventArgs.Empty, e, "Closed/e");
506 Assert.IsTrue (co.Disposed, "Closed/Disposed");
507 Assert.Throws<CommunicationObjectAbortedException> (delegate {
508 co._ThrowIfDisposed ();
509 }, "Closed/ThrowIfDisposed");
510 Assert.Throws<CommunicationObjectAbortedException> (delegate {
511 co._ThrowIfDisposedOrImmutable ();
512 }, "Closed/ThrowIfDisposedOrImmutable");
513 Assert.Throws<CommunicationObjectAbortedException> (delegate {
514 co._ThrowIfDisposedOrNotOpen ();
515 }, "Closed/ThrowIfDisposedOrNotOpen");
517 Assert.AreEqual (CommunicationState.Created, co.State, "State/before");
519 co.OnAbortState = CommunicationState.Closing;
521 Assert.AreEqual (0, opening, "opening");
522 Assert.AreEqual (0, opened, "opened");
523 Assert.AreEqual (0, closing, "closing");
524 Assert.AreEqual (0, closed, "closed");
526 Assert.AreEqual (CommunicationState.Faulted, co.State, "State/after");
527 Assert.IsFalse (co.Disposed, "IsDisposed");
529 Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
530 Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
531 Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled");
533 Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled");
534 Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled");
535 Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled");
537 Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled");
538 Assert.IsFalse (co.OnOpenCalled, "OnOpenCalled");
539 Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled");
542 Assert.AreEqual (0, opening, "opening-b");
543 Assert.AreEqual (0, opened, "opened-b");
544 Assert.AreEqual (1, closing, "closing-c");
545 Assert.AreEqual (1, closed, "closed-c");
552 [NUnit.Framework.Ignore]
554 public void Create_Fault_Open_Close ()
562 CommunicationObjectPoker co = new CommunicationObjectPoker ();
563 co.Faulted += delegate (object sender, EventArgs e) {
565 Assert.AreEqual (CommunicationState.Faulted, co.State, "State/Faulted");
566 Assert.AreSame (co, sender, "sender");
567 Assert.AreSame (EventArgs.Empty, e, "e");
569 co.Opening += delegate (object sender, EventArgs e) {
571 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
572 Assert.AreSame (co, sender, "Opening/sender");
573 Assert.AreSame (EventArgs.Empty, e, "Opening/e");
575 co.Opened += delegate (object sender, EventArgs e) {
577 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
578 Assert.AreSame (co, sender, "Opened/sender");
579 Assert.AreSame (EventArgs.Empty, e, "Opened/e");
581 co.Closing += delegate (object sender, EventArgs e) {
583 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
584 Assert.AreSame (co, sender, "Closing/sender");
585 Assert.AreSame (EventArgs.Empty, e, "Closing/e");
587 co.Closed += delegate (object sender, EventArgs e) {
589 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
590 Assert.AreSame (co, sender, "Closed/sender");
591 Assert.AreSame (EventArgs.Empty, e, "Closed/e");
594 Assert.AreEqual (CommunicationState.Created, co.State, "State/before");
597 Assert.AreEqual (0, opening, "opening");
598 Assert.AreEqual (0, opened, "opened");
599 Assert.AreEqual (0, closing, "closing");
600 Assert.AreEqual (0, closed, "closed");
601 Assert.AreEqual (1, faulted, "faulted");
603 Assert.AreEqual (CommunicationState.Faulted, co.State, "State/after");
604 Assert.IsFalse (co.Disposed, "IsDisposed");
606 // 2nd fault does not throw a CommunicationObjectFaultedException
607 // nor does it raise Faulted again
609 Assert.AreEqual (1, faulted, "faulted(same)");
611 Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
612 Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
613 Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled");
615 Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled");
616 Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled");
617 Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled");
619 Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled");
620 Assert.IsFalse (co.OnOpenCalled, "OnOpenCalled");
621 Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled");
623 Assert.Throws<CommunicationObjectFaultedException> (delegate {
626 Assert.AreEqual (0, opening, "opening-b");
627 Assert.AreEqual (0, opened, "opened-b");
628 Assert.AreEqual (CommunicationState.Faulted, co.State, "State/Open");
630 // calling Close on an Faulted instance will call OnAbort (not OnClose)
631 co.OnAbortState = CommunicationState.Closing;
632 Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled/before");
633 Assert.Throws<CommunicationObjectFaultedException> (delegate {
636 Assert.IsTrue (co.OnAbortCalled, "OnAbortCalled/after");
637 Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled/after");
638 Assert.AreEqual (1, closing, "closing-c");
639 Assert.AreEqual (1, closed, "closed-c");
640 Assert.AreEqual (CommunicationState.Closed, co.State, "State/Close");
647 [NUnit.Framework.Ignore]
649 public void Create_Fault_Open_Abort_Close ()
657 CommunicationObjectPoker co = new CommunicationObjectPoker ();
658 co.Faulted += delegate (object sender, EventArgs e) {
660 Assert.AreEqual (CommunicationState.Faulted, co.State, "State/Faulted");
661 Assert.AreSame (co, sender, "sender");
662 Assert.AreSame (EventArgs.Empty, e, "e");
664 co.Opening += delegate (object sender, EventArgs e) {
666 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
667 Assert.AreSame (co, sender, "Opening/sender");
668 Assert.AreSame (EventArgs.Empty, e, "Opening/e");
670 co.Opened += delegate (object sender, EventArgs e) {
672 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
673 Assert.AreSame (co, sender, "Opened/sender");
674 Assert.AreSame (EventArgs.Empty, e, "Opened/e");
676 co.Closing += delegate (object sender, EventArgs e) {
678 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
679 Assert.AreSame (co, sender, "Closing/sender");
680 Assert.AreSame (EventArgs.Empty, e, "Closing/e");
682 co.Closed += delegate (object sender, EventArgs e) {
684 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
685 Assert.AreSame (co, sender, "Closed/sender");
686 Assert.AreSame (EventArgs.Empty, e, "Closed/e");
689 Assert.AreEqual (CommunicationState.Created, co.State, "State/before");
692 Assert.AreEqual (0, opening, "opening");
693 Assert.AreEqual (0, opened, "opened");
694 Assert.AreEqual (0, closing, "closing");
695 Assert.AreEqual (0, closed, "closed");
696 Assert.AreEqual (1, faulted, "faulted");
698 Assert.AreEqual (CommunicationState.Faulted, co.State, "State/after");
699 Assert.IsFalse (co.Disposed, "IsDisposed");
701 // 2nd fault does not throw a CommunicationObjectFaultedException
702 // nor does it raise Faulted again
704 Assert.AreEqual (1, faulted, "faulted(same)");
706 Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
707 Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
708 Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled");
710 Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled");
711 Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled");
712 Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled");
714 Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled");
715 Assert.IsFalse (co.OnOpenCalled, "OnOpenCalled");
716 Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled");
718 Assert.Throws<CommunicationObjectFaultedException> (delegate {
721 Assert.AreEqual (0, opening, "opening-b");
722 Assert.AreEqual (0, opened, "opened-b");
724 co.OnAbortState = CommunicationState.Closing;
725 // Abort does not throw a CommunicationObjectFaultedException
727 Assert.AreEqual (1, closing, "closing-b");
728 Assert.AreEqual (1, closed, "closed-b");
731 Assert.AreEqual (1, closing, "closing-c");
732 Assert.AreEqual (1, closed, "closed-c");
739 [NUnit.Framework.Ignore]
741 public void Create_Open_Open ()
746 CommunicationObjectPoker co = new CommunicationObjectPoker ();
747 co.Opening += delegate (object sender, EventArgs e) {
749 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
750 Assert.AreSame (co, sender, "Opening/sender");
751 Assert.AreSame (EventArgs.Empty, e, "Opening/e");
753 co.Opened += delegate (object sender, EventArgs e) {
755 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
756 Assert.AreSame (co, sender, "Opened/sender");
757 Assert.AreSame (EventArgs.Empty, e, "Opened/e");
761 Assert.AreEqual (1, opening, "opening");
762 Assert.AreEqual (1, opened, "opened");
763 Assert.AreEqual (CommunicationState.Opened, co.State, "State/after/open");
764 Assert.IsFalse (co.Disposed, "IsDisposed/open");
766 Assert.Throws<InvalidOperationException> (delegate {
769 Assert.AreEqual (1, opening, "opening-b");
770 Assert.AreEqual (1, opened, "openedg-b");
771 Assert.AreEqual (CommunicationState.Opened, co.State, "State/after/openg-b");
772 Assert.IsFalse (co.Disposed, "IsDisposed/openg-b");
776 // http://msdn.microsoft.com/en-us/library/ms789041.aspx
777 // ThrowIfDisposed throws an exception if the state is Closing, Closed or Faulted.
783 [NUnit.Framework.Ignore]
785 public void ThrowIfDisposed_Open_Close ()
787 bool opening = false;
789 bool closing = false;
791 bool faulted = false;
793 CommunicationObjectPoker co = new CommunicationObjectPoker ();
795 co.Opening += delegate (object sender, EventArgs e) {
797 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
798 co._ThrowIfDisposed ();
800 co.Opened += delegate (object sender, EventArgs e) {
802 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
803 co._ThrowIfDisposed ();
805 co.Closing += delegate (object sender, EventArgs e) {
807 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
808 Assert.Throws<ObjectDisposedException> (delegate {
809 co._ThrowIfDisposed ();
810 }, "ThrowIfDisposed/Closing");
812 co.Closed += delegate (object sender, EventArgs e) {
814 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
815 Assert.Throws<ObjectDisposedException> (delegate {
816 co._ThrowIfDisposed ();
817 }, "ThrowIfDisposed/Closed");
819 co.Faulted += delegate (object sender, EventArgs e) {
821 Assert.AreEqual (CommunicationState.Faulted, co.State, "Faulted/State");
822 Assert.Throws<CommunicationObjectFaultedException> (delegate {
823 co._ThrowIfDisposed ();
824 }, "ThrowIfDisposed/Faulted");
827 Assert.AreEqual (CommunicationState.Created, co.State, "Created");
828 co._ThrowIfDisposed ();
834 co._FaultNoAssert ();
836 // ensure all states were tested
837 Assert.IsTrue (opening, "opening");
838 Assert.IsTrue (opened, "opened");
839 Assert.IsTrue (closing, "closing");
840 Assert.IsTrue (closed, "closing");
841 Assert.IsFalse (faulted, "faulted");
849 [NUnit.Framework.Ignore]
851 public void ThrowIfDisposed_Fault_Abort ()
853 bool opening = false;
855 bool closing = false;
857 bool faulted = false;
859 CommunicationObjectPoker co = new CommunicationObjectPoker ();
861 co.Opening += delegate (object sender, EventArgs e) {
863 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
864 co._ThrowIfDisposed ();
866 co.Opened += delegate (object sender, EventArgs e) {
868 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
869 co._ThrowIfDisposed ();
871 co.Closing += delegate (object sender, EventArgs e) {
873 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
874 Assert.Throws<CommunicationObjectAbortedException> (delegate {
875 co._ThrowIfDisposed ();
876 }, "ThrowIfDisposed/Closing");
878 co.Closed += delegate (object sender, EventArgs e) {
880 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
881 Assert.Throws<CommunicationObjectAbortedException> (delegate {
882 co._ThrowIfDisposed ();
883 }, "ThrowIfDisposed/Closed");
885 co.Faulted += delegate (object sender, EventArgs e) {
887 Assert.AreEqual (CommunicationState.Faulted, co.State, "Faulted/State");
888 Assert.Throws<CommunicationObjectFaultedException> (delegate {
889 co._ThrowIfDisposed ();
890 }, "ThrowIfDisposed/Faulted");
893 Assert.AreEqual (CommunicationState.Created, co.State, "Created");
894 co._ThrowIfDisposed ();
896 co._FaultNoAssert ();
898 co.OnAbortState = CommunicationState.Closing;
901 // ensure all states were tested
902 Assert.IsFalse (opening, "opening");
903 Assert.IsFalse (opened, "opened");
904 Assert.IsTrue (closing, "closing");
905 Assert.IsTrue (closed, "closing");
906 Assert.IsTrue (faulted, "faulted");
909 // http://msdn.microsoft.com/en-us/library/ms789041.aspx
910 // ThrowIfDisposedOrImmutable throws an exception if the state is not Created.
916 [NUnit.Framework.Ignore]
918 public void ThrowIfDisposedOrImmutable_Open_Close ()
920 bool opening = false;
922 bool closing = false;
924 bool faulted = false;
926 CommunicationObjectPoker co = new CommunicationObjectPoker ();
928 co.Opening += delegate (object sender, EventArgs e) {
930 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
931 Assert.Throws<InvalidOperationException> (delegate {
932 co._ThrowIfDisposedOrImmutable ();
933 }, "ThrowIfDisposedOrImmutable/Opening");
935 co.Opened += delegate (object sender, EventArgs e) {
937 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
938 Assert.Throws<InvalidOperationException> (delegate {
939 co._ThrowIfDisposedOrImmutable ();
940 }, "ThrowIfDisposedOrImmutable/Opened");
942 co.Closing += delegate (object sender, EventArgs e) {
944 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
945 Assert.Throws<ObjectDisposedException> (delegate {
946 co._ThrowIfDisposedOrImmutable ();
947 }, "ThrowIfDisposedOrImmutable/Closing");
949 co.Closed += delegate (object sender, EventArgs e) {
951 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
952 Assert.Throws<ObjectDisposedException> (delegate {
953 co._ThrowIfDisposedOrImmutable ();
954 }, "ThrowIfDisposedOrImmutable/Closed");
956 co.Faulted += delegate (object sender, EventArgs e) {
958 Assert.AreEqual (CommunicationState.Faulted, co.State, "Faulted/State");
959 Assert.Throws<CommunicationObjectFaultedException> (delegate {
960 co._ThrowIfDisposedOrImmutable ();
961 }, "ThrowIfDisposedOrImmutable/Faulted");
964 Assert.AreEqual (CommunicationState.Created, co.State, "Created");
965 co._ThrowIfDisposedOrImmutable ();
971 co._FaultNoAssert ();
973 // ensure all states were tested
974 Assert.IsTrue (opening, "opening");
975 Assert.IsTrue (opened, "opened");
976 Assert.IsTrue (closing, "closing");
977 Assert.IsTrue (closed, "closing");
978 Assert.IsFalse (faulted, "faulted");
985 [NUnit.Framework.Ignore]
987 public void ThrowIfDisposedOrImmutable_Fault_Abort ()
989 bool opening = false;
991 bool closing = false;
993 bool faulted = false;
995 CommunicationObjectPoker co = new CommunicationObjectPoker ();
997 co.Opening += delegate (object sender, EventArgs e) {
999 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
1000 Assert.Throws<ObjectDisposedException> (delegate {
1001 co._ThrowIfDisposedOrImmutable ();
1002 }, "ThrowIfDisposedOrImmutable/Opening");
1004 co.Opened += delegate (object sender, EventArgs e) {
1006 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
1007 Assert.Throws<ObjectDisposedException> (delegate {
1008 co._ThrowIfDisposedOrImmutable ();
1009 }, "ThrowIfDisposedOrImmutable/Opened");
1011 co.Closing += delegate (object sender, EventArgs e) {
1013 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
1014 Assert.Throws<CommunicationObjectAbortedException> (delegate {
1015 co._ThrowIfDisposedOrImmutable ();
1016 }, "ThrowIfDisposedOrImmutable/Closing");
1018 co.Closed += delegate (object sender, EventArgs e) {
1020 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
1021 Assert.Throws<CommunicationObjectAbortedException> (delegate {
1022 co._ThrowIfDisposedOrImmutable ();
1023 }, "ThrowIfDisposedOrImmutable/Closed");
1025 co.Faulted += delegate (object sender, EventArgs e) {
1027 Assert.AreEqual (CommunicationState.Faulted, co.State, "Faulted/State");
1028 Assert.Throws<CommunicationObjectFaultedException> (delegate {
1029 co._ThrowIfDisposedOrImmutable ();
1030 }, "ThrowIfDisposedOrImmutable/Faulted");
1033 Assert.AreEqual (CommunicationState.Created, co.State, "Created");
1034 co._ThrowIfDisposedOrImmutable ();
1036 co._FaultNoAssert ();
1038 co.OnAbortState = CommunicationState.Closing;
1041 // ensure all states were tested
1042 Assert.IsFalse (opening, "opening");
1043 Assert.IsFalse (opened, "opened");
1044 Assert.IsTrue (closing, "closing");
1045 Assert.IsTrue (closed, "closing");
1046 Assert.IsTrue (faulted, "faulted");
1049 // http://msdn.microsoft.com/en-us/library/ms789041.aspx
1050 // ThrowIfDisposedOrNotOpen throws an exception if the state is not Opened.
1056 [NUnit.Framework.Ignore]
1058 public void ThrowIfDisposedOrNotOpen_Open_Close ()
1060 bool opening = false;
1061 bool opened = false;
1062 bool closing = false;
1063 bool closed = false;
1064 bool faulted = false;
1066 CommunicationObjectPoker co = new CommunicationObjectPoker ();
1068 co.Opening += delegate (object sender, EventArgs e) {
1070 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
1071 Assert.Throws<InvalidOperationException> (delegate {
1072 co._ThrowIfDisposedOrNotOpen ();
1073 }, "ThrowIfDisposedOrNotOpen/Opening");
1075 co.Opened += delegate (object sender, EventArgs e) {
1077 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
1078 co._ThrowIfDisposedOrNotOpen ();
1080 co.Closing += delegate (object sender, EventArgs e) {
1082 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
1083 Assert.Throws<ObjectDisposedException> (delegate {
1084 co._ThrowIfDisposedOrNotOpen ();
1085 }, "ThrowIfDisposedOrNotOpen/Closing");
1087 co.Closed += delegate (object sender, EventArgs e) {
1089 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
1090 Assert.Throws<ObjectDisposedException> (delegate {
1091 co._ThrowIfDisposedOrNotOpen ();
1092 }, "ThrowIfDisposedOrNotOpen/Closed");
1094 co.Faulted += delegate (object sender, EventArgs e) {
1096 Assert.AreEqual (CommunicationState.Faulted, co.State, "Faulted/State");
1097 Assert.Throws<CommunicationObjectFaultedException> (delegate {
1098 co._ThrowIfDisposedOrNotOpen ();
1099 }, "ThrowIfDisposedOrNotOpen/Faulted");
1102 Assert.AreEqual (CommunicationState.Created, co.State, "Created");
1103 Assert.Throws<InvalidOperationException> (delegate {
1104 co._ThrowIfDisposedOrNotOpen ();
1105 }, "ThrowIfDisposedOrNotOpen/Created");
1111 co._FaultNoAssert ();
1113 // ensure all states were tested
1114 Assert.IsTrue (opening, "opening");
1115 Assert.IsTrue (opened, "opened");
1116 Assert.IsTrue (closing, "closing");
1117 Assert.IsTrue (closed, "closing");
1118 Assert.IsFalse (faulted, "faulted");
1125 [NUnit.Framework.Ignore]
1127 public void ThrowIfDisposedOrNotOpen_Fault_Abort ()
1129 bool opening = false;
1130 bool opened = false;
1131 bool closing = false;
1132 bool closed = false;
1133 bool faulted = false;
1135 CommunicationObjectPoker co = new CommunicationObjectPoker ();
1137 co.Opening += delegate (object sender, EventArgs e) {
1139 Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
1140 Assert.Throws<ObjectDisposedException> (delegate {
1141 co._ThrowIfDisposedOrNotOpen ();
1142 }, "ThrowIfDisposedOrNotOpen/Opening");
1144 co.Opened += delegate (object sender, EventArgs e) {
1146 Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
1147 co._ThrowIfDisposedOrNotOpen ();
1149 co.Closing += delegate (object sender, EventArgs e) {
1151 Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
1152 Assert.Throws<CommunicationObjectAbortedException> (delegate {
1153 co._ThrowIfDisposedOrNotOpen ();
1154 }, "ThrowIfDisposedOrNotOpen/Closing");
1156 co.Closed += delegate (object sender, EventArgs e) {
1158 Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
1159 Assert.Throws<CommunicationObjectAbortedException> (delegate {
1160 co._ThrowIfDisposedOrNotOpen ();
1161 }, "ThrowIfDisposedOrNotOpen/Closed");
1163 co.Faulted += delegate (object sender, EventArgs e) {
1165 Assert.AreEqual (CommunicationState.Faulted, co.State, "Faulted/State");
1166 Assert.Throws<CommunicationObjectFaultedException> (delegate {
1167 co._ThrowIfDisposedOrNotOpen ();
1168 }, "ThrowIfDisposedOrNotOpen/Faulted");
1171 Assert.AreEqual (CommunicationState.Created, co.State, "Created");
1172 Assert.Throws<InvalidOperationException> (delegate {
1173 co._ThrowIfDisposedOrNotOpen ();
1174 }, "ThrowIfDisposedOrNotOpen/Created");
1176 co._FaultNoAssert ();
1178 co.OnAbortState = CommunicationState.Closing;
1181 // ensure all states were tested
1182 Assert.IsFalse (opening, "opening");
1183 Assert.IsFalse (opened, "opened");
1184 Assert.IsTrue (closing, "closing");
1185 Assert.IsTrue (closed, "closing");
1186 Assert.IsTrue (faulted, "faulted");
1189 class NoFaultCommunicationObject : CommunicationObjectPoker {
1191 protected override void OnFaulted ()
1193 Assert.AreEqual (CommunicationState.Faulted, State, "OnFaulted/State");
1194 // base not called - Faulted won't be raised
1202 [NUnit.Framework.Ignore]
1204 public void NoOnFault ()
1206 bool faulted = false;
1207 NoFaultCommunicationObject co = new NoFaultCommunicationObject ();
1208 co.Faulted += delegate (object sender, EventArgs e) {
1211 co._FaultNoAssert ();
1212 Assert.AreEqual (CommunicationState.Faulted, co.State, "State");
1213 Assert.IsFalse (faulted, "faulted");
1216 class FaultCommunicationObject : CommunicationObjectPoker {
1218 protected override void OnFaulted ()
1221 throw new NotFiniteNumberException ();
1229 [NUnit.Framework.Ignore]
1231 public void OnFaultThrowing ()
1233 FaultCommunicationObject co = new FaultCommunicationObject ();
1234 Assert.Throws<NotFiniteNumberException> (delegate {
1235 co._FaultNoAssert ();
1237 // OnFault is not called more than one time
1238 co._FaultNoAssert ();
1245 [NUnit.Framework.Ignore]
1247 public void AbortWhileAborting ()
1251 CommunicationObjectPoker co = new CommunicationObjectPoker ();
1252 co.Closing += delegate (object sender, EventArgs e) {
1254 co.OnAbortState = CommunicationState.Closing;
1257 co.Closed += delegate (object sender, EventArgs e) {
1261 co.OnAbortState = CommunicationState.Created;
1262 // Abort will call Closing, which can call Abort...
1265 Assert.AreEqual (1, closing, "closing");
1266 Assert.AreEqual (1, closed, "closed");
1273 [NUnit.Framework.Ignore]
1275 public void AbortWhileClosing ()
1279 CommunicationObjectPoker co = new CommunicationObjectPoker ();
1280 co.Closing += delegate (object sender, EventArgs e) {
1282 co.OnAbortState = CommunicationState.Closing;
1283 // ensure we're not repeating OnClosing
1286 co.Closed += delegate (object sender, EventArgs e) {
1292 Assert.AreEqual (1, closing, "closing");
1293 Assert.AreEqual (1, closed, "closed");
1296 class NoAbortCommunicationObject : CommunicationObjectPoker {
1298 protected override void OnAbort ()
1300 Assert.AreEqual (CommunicationState.Closing, State, "OnAbort/State");
1309 [NUnit.Framework.Ignore]
1311 public void NoOnAbort ()
1313 bool closing = false;
1314 bool closed = false;
1315 NoAbortCommunicationObject co = new NoAbortCommunicationObject ();
1316 co.Closing += delegate (object sender, EventArgs e) {
1319 co.Closed += delegate (object sender, EventArgs e) {
1323 Assert.AreEqual (CommunicationState.Closed, co.State, "State");
1324 Assert.IsTrue (closing, "closing");
1325 Assert.IsTrue (closed, "closed");