public void Create_Fault_Open_Abort_Close ()
		{
			int opening = 0;
			int opened = 0;
			int closing = 0;
			int closed = 0;
			int faulted = 0;

			CommunicationObjectPoker co = new CommunicationObjectPoker ();
			co.Faulted += delegate (object sender, EventArgs e) {
				faulted++;
				Assert.AreEqual (CommunicationState.Faulted, co.State, "State/Faulted");
				Assert.AreSame (co, sender, "sender");
				Assert.AreSame (EventArgs.Empty, e, "e");
			};
			co.Opening += delegate (object sender, EventArgs e) {
				opening++;
				Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
				Assert.AreSame (co, sender, "Opening/sender");
				Assert.AreSame (EventArgs.Empty, e, "Opening/e");
			};
			co.Opened += delegate (object sender, EventArgs e) {
				opened++;
				Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
				Assert.AreSame (co, sender, "Opened/sender");
				Assert.AreSame (EventArgs.Empty, e, "Opened/e");
			};
			co.Closing += delegate (object sender, EventArgs e) {
				closing++;
				Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
				Assert.AreSame (co, sender, "Closing/sender");
				Assert.AreSame (EventArgs.Empty, e, "Closing/e");
			};
			co.Closed += delegate (object sender, EventArgs e) {
				closed++;
				Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
				Assert.AreSame (co, sender, "Closed/sender");
				Assert.AreSame (EventArgs.Empty, e, "Closed/e");
			};

			Assert.AreEqual (CommunicationState.Created, co.State, "State/before");

			co._Fault ();
			Assert.AreEqual (0, opening, "opening");
			Assert.AreEqual (0, opened, "opened");
			Assert.AreEqual (0, closing, "closing");
			Assert.AreEqual (0, closed, "closed");
			Assert.AreEqual (1, faulted, "faulted");

			Assert.AreEqual (CommunicationState.Faulted, co.State, "State/after");
			Assert.IsFalse (co.Disposed, "IsDisposed");

			// 2nd fault does not throw a CommunicationObjectFaultedException
			// nor does it raise Faulted again
			co._Fault ();
			Assert.AreEqual (1, faulted, "faulted(same)");

			Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
			Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
			Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled");

			Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled");
			Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled");
			Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled");

			Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled");
			Assert.IsFalse (co.OnOpenCalled, "OnOpenCalled");
			Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled");

			Assert.Throws<CommunicationObjectFaultedException> (delegate {
				co.Open ();
			}, "Open");
			Assert.AreEqual (0, opening, "opening-b");
			Assert.AreEqual (0, opened, "opened-b");

			co.OnAbortState = CommunicationState.Closing;
			// Abort does not throw a CommunicationObjectFaultedException
			co.Abort ();
			Assert.AreEqual (1, closing, "closing-b");
			Assert.AreEqual (1, closed, "closed-b");

			co.Close ();
			Assert.AreEqual (1, closing, "closing-c");
			Assert.AreEqual (1, closed, "closed-c");
		}
		public void Create_Fault_Abort ()
		{
			int opening = 0;
			int opened = 0;
			int closing = 0;
			int closed = 0;

			CommunicationObjectPoker co = new CommunicationObjectPoker ();
			co.Opening += delegate (object sender, EventArgs e) {
				opening++;
				Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
				Assert.AreSame (co, sender, "Opening/sender");
				Assert.AreSame (EventArgs.Empty, e, "Opening/e");
			};
			co.Opened += delegate (object sender, EventArgs e) {
				opened++;
				Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
				Assert.AreSame (co, sender, "Opened/sender");
				Assert.AreSame (EventArgs.Empty, e, "Opened/e");
			};
			co.Closing += delegate (object sender, EventArgs e) {
				closing++;
				Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
				Assert.AreSame (co, sender, "Closing/sender");
				Assert.AreSame (EventArgs.Empty, e, "Closing/e");

				Assert.IsFalse (co.Disposed, "Closing/Disposed");
				// note: IsDisposed is false but we still throw! 
				// but this match MSDN docs about ThrowIfDisposed
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposed ();
				}, "Closing/ThrowIfDisposed");
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposedOrImmutable ();
				}, "Closing/ThrowIfDisposedOrImmutable");
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposedOrNotOpen ();
				}, "Closing/ThrowIfDisposedOrNotOpen");
			};
			co.Closed += delegate (object sender, EventArgs e) {
				closed++;
				Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
				Assert.AreSame (co, sender, "Closed/sender");
				Assert.AreSame (EventArgs.Empty, e, "Closed/e");

				Assert.IsTrue (co.Disposed, "Closed/Disposed");
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposed ();
				}, "Closed/ThrowIfDisposed");
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposedOrImmutable ();
				}, "Closed/ThrowIfDisposedOrImmutable");
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposedOrNotOpen ();
				}, "Closed/ThrowIfDisposedOrNotOpen");
			};
			Assert.AreEqual (CommunicationState.Created, co.State, "State/before");

			co.OnAbortState = CommunicationState.Closing;
			co._Fault ();
			Assert.AreEqual (0, opening, "opening");
			Assert.AreEqual (0, opened, "opened");
			Assert.AreEqual (0, closing, "closing");
			Assert.AreEqual (0, closed, "closed");

			Assert.AreEqual (CommunicationState.Faulted, co.State, "State/after");
			Assert.IsFalse (co.Disposed, "IsDisposed");

			Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
			Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
			Assert.IsFalse (co.OnAbortCalled, "OnAbortCalled");

			Assert.IsFalse (co.OnBeginCloseCalled, "OnBeginCloseCalled");
			Assert.IsFalse (co.OnCloseCalled, "OnCloseCalled");
			Assert.IsFalse (co.OnEndCloseCalled, "OnEndCloseCalled");

			Assert.IsFalse (co.OnBeginOpenCalled, "OnBeginOpenCalled");
			Assert.IsFalse (co.OnOpenCalled, "OnOpenCalled");
			Assert.IsFalse (co.OnEndOpenCalled, "OnEndCloseCalled");

			co.Abort ();
			Assert.AreEqual (0, opening, "opening-b");
			Assert.AreEqual (0, opened, "opened-b");
			Assert.AreEqual (1, closing, "closing-c");
			Assert.AreEqual (1, closed, "closed-c");
		}