public void Test_IsSet_OneLevel()
 {
     Assert.That(DeferredChannelMessageContext.IsSet(), Is.False, "Set beforehand");
     using (new DeferredChannelMessageContext())
     {
         Assert.That(DeferredChannelMessageContext.IsSet(), Is.True, "Not set");
     }
     Assert.That(DeferredChannelMessageContext.IsSet(), Is.False, "Set afterwards");
 }
Example #2
0
        /// <summary>
        /// Flush any deferred messages.
        /// </summary>
        private void FlushDeferredMessageContextMessages()
        {
            if (!DeferredChannelMessageContext.IsSet())
            {
                return;
            }

            using (DeferredChannelMessageContext messageContext = DeferredChannelMessageContext.GetContext())
            {
                messageContext.FlushMessages();
            }
        }
 public void Test_IsSet_TwoLevels()
 {
     Assert.That(DeferredChannelMessageContext.IsSet(), Is.False, "Set beforehand");
     using (new DeferredChannelMessageContext())
     {
         Assert.That(DeferredChannelMessageContext.IsSet(), Is.True, "Not pre-second level");
         using (new DeferredChannelMessageContext())
         {
             Assert.That(DeferredChannelMessageContext.IsSet(), Is.True, "Not second level");
         }
         Assert.That(DeferredChannelMessageContext.IsSet(), Is.True, "Not post-second level");
     }
     Assert.That(DeferredChannelMessageContext.IsSet(), Is.False, "Set afterwards");
 }
        public void Test_GetContext()
        {
            Assert.That(DeferredChannelMessageContext.IsSet(), Is.False, "Set initially");

            using (DeferredChannelMessageContext newContext = new DeferredChannelMessageContext())
            {
                using (DeferredChannelMessageContext attachedContext = DeferredChannelMessageContext.GetContext())
                {
                    Assert.That(newContext.ContextType, Is.EqualTo(ContextType.New), "Incorrect context type");
                    Assert.That(attachedContext.ContextType, Is.EqualTo(ContextType.Attached), "Incorrect context type");
                }

                Assert.That(DeferredChannelMessageContext.IsSet(), Is.True, "Attached Dispose() removed context");
            }

            Assert.That(DeferredChannelMessageContext.IsSet(), Is.False, "New Dispose() did not remove context");
        }