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.");
        }