This is a mock communication object used for testing.
Inheritance: System.ServiceModel.Channels.CommunicationObject
        public void TestEnsureCleanupUnderNormalCircumstances()
        {
            // Create a CommunicationObject.
            TestCommunicationObject commObj = new TestCommunicationObject();

            // Open and use it.
            commObj.Open();
            CommunicationObjectHelper.EnsureCleanup(commObj,
                delegate { commObj.DoSomeWork(); }
                );

            Assert.AreEqual<CommunicationState>(CommunicationState.Closed, commObj.State,
                                                "Communication object is in an inconsistant state.");
        }
        public void TestEnsureCleanupWhenCommunicationObjectBecomesFaultedDueToAction()
        {
            // Create a CommunicationObject.
            TestCommunicationObject commObj = new TestCommunicationObject();

            // Open and use it.
            commObj.Open();
            CommunicationObjectHelper.EnsureCleanup(commObj,
                delegate
                    {
                        // Do some erroneous work that will make the CommunicationObject
                        // Faulted.
                        commObj.DoSomeErroneousWork();
                    }
                );

            Assert.AreEqual<CommunicationState>(CommunicationState.Closed, commObj.State,
                                                "Communication object is in an inconsistant state.");
        }
        public void TestEnsureCleanupForNullInputHandling()
        {
            // Create a CommunicationObject.
            TestCommunicationObject commObj = new TestCommunicationObject();

            // First try to pass null to action delegate and see 
            // if it results in an ArgumentException.
            try
            {
                CommunicationObjectHelper.EnsureCleanup(commObj, null);
                Assert.Fail("EnsureCleanup was called with null parameters.");
            }
            catch (ArgumentException)
            {
            }

            // Then try to pass null to both parameters and see 
            // if it results in an ArgumentException.
            try
            {
                CommunicationObjectHelper.EnsureCleanup(null, null);
            }
            catch (ArgumentException)
            {
            }
        }