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");
		}
		public void ThrowIfDisposed_Fault_Abort ()
		{
			bool opening = false;
			bool opened = false;
			bool closing = false;
			bool closed = false;
			bool faulted = false;

			CommunicationObjectPoker co = new CommunicationObjectPoker ();

			co.Opening += delegate (object sender, EventArgs e) {
				opening = true;
				Assert.AreEqual (CommunicationState.Opening, co.State, "Opening/State");
				co._ThrowIfDisposed ();
			};
			co.Opened += delegate (object sender, EventArgs e) {
				opened = true;
				Assert.AreEqual (CommunicationState.Opened, co.State, "Opened/State");
				co._ThrowIfDisposed ();
			};
			co.Closing += delegate (object sender, EventArgs e) {
				closing = true;
				Assert.AreEqual (CommunicationState.Closing, co.State, "Closing/State");
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposed ();
				}, "ThrowIfDisposed/Closing");
			};
			co.Closed += delegate (object sender, EventArgs e) {
				closed = true;
				Assert.AreEqual (CommunicationState.Closed, co.State, "Closed/State");
				Assert.Throws<CommunicationObjectAbortedException> (delegate {
					co._ThrowIfDisposed ();
				}, "ThrowIfDisposed/Closed");
			};
			co.Faulted += delegate (object sender, EventArgs e) {
				faulted = true;
				Assert.AreEqual (CommunicationState.Faulted, co.State, "Faulted/State");
				Assert.Throws<CommunicationObjectFaultedException> (delegate {
					co._ThrowIfDisposed ();
				}, "ThrowIfDisposed/Faulted");
			};

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

			co._FaultNoAssert ();

			co.OnAbortState = CommunicationState.Closing;
			co.Abort (); 

			// ensure all states were tested
			Assert.IsFalse (opening, "opening");
			Assert.IsFalse (opened, "opened");
			Assert.IsTrue (closing, "closing");
			Assert.IsTrue (closed, "closing");
			Assert.IsTrue (faulted, "faulted");
		}
		public void Create_Abort ()
		{
			int closing = 0;
			int closed = 0;

			CommunicationObjectPoker co = new CommunicationObjectPoker ();
			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");
				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.Abort ();
			Assert.AreEqual (1, closing, "closing");
			Assert.AreEqual (1, closed, "closed");

			Assert.AreEqual (CommunicationState.Closed, co.State, "State/after");
			Assert.IsTrue (co.Disposed, "IsDisposed");

			Assert.IsFalse (co.DefaultCloseTimeoutCalled, "DefaultCloseTimeoutCalled");
			Assert.IsFalse (co.DefaultOpenTimeoutCalled, "DefaultOpenTimeoutCalled");
			Assert.IsTrue (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");
		}