Пример #1
0
        public void TagCollections_IndexerGet_ThrowsOnTagKeyThatDoesNotExistTest()
        {
            // ReSharper disable AccessToDisposedClosure

            using (var scope = TagScopeManager.CreateScope())
            {
                scope.Tags.Add("tag", "value");

                // Access to existing tag. Expected result: success.
                Assert.AreEqual("value", scope.Tags["tag"]);

                // Access to tag that does not exist.
                // Expected result: ArgumentException( "The given tag key was not present in the tag collection." )
                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    Assert.IsNull(scope.Tags["not_a_tag"]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    Assert.IsNull(scope.InheritedTags["not_a_tag"]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    Assert.IsNull(scope.EffectiveTags["not_a_tag"]);
                }));

                TestWithNestedScope();
            }

            // ReSharper restore AccessToDisposedClosure
        }
Пример #2
0
        /// <summary>
        /// This fragment implemented as a separate method
        /// to isolate nested scope from parent scope
        /// and prevent some really annoying problems with
        /// mess with acident "scope" and "nestedScope" calls
        /// while they are in one method.
        /// </summary>
        static void TestWithNestedScope()
        {
            // ReSharper disable AccessToDisposedClosure

            using (var nestedScope = TagScopeManager.CreateScope())
            {
                // Access to tag that does not exist.
                // Expected result: ArgumentException( "The given tag key was not present in the tag collection." )
                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    Assert.IsNull(nestedScope.Tags["not_a_tag"]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    Assert.IsNull(nestedScope.InheritedTags["not_a_tag"]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    Assert.IsNull(nestedScope.EffectiveTags["not_a_tag"]);
                }));
            }

            // ReSharper restore AccessToDisposedClosure
        }
Пример #3
0
        public void TagCollections_IndexerGet_ThrowsOnTagKeyThatIsNull()
        {
            using (var scope = TagScopeManager.CreateScope())
            {
                scope.Tags.Add("tag", "value");

                // Access to existing tag. Expected result: success.
                Assert.AreEqual("value", scope.Tags["tag"]);

                // Access to tag that does not exist.
                // Expected result: ArgumentNullException( "Tag key cannot be null." )
                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentNullException>(() =>
                {
                    Assert.IsNull(scope.Tags[null]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentNullException>(() =>
                {
                    Assert.IsNull(scope.InheritedTags[null]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentNullException>(() =>
                {
                    Assert.IsNull(scope.EffectiveTags[null]);
                }));

                TestWithNestedScope();
            }
        }
Пример #4
0
 public void LogAdapter_UnableToSetNullAsLogAdapter()
 {
     Assert.IsTrue(ExceptionTest.IsThrown <ArgumentNullException>(() =>
     {
         TagScopeManager.LogAdapter = null;
     }));
 }
Пример #5
0
        /// <summary>
        /// This fragment implemented as a separate method
        /// to isolate nested scope from parent scope
        /// and prevent some really annoying problems with
        /// mess with acident "scope" and "nestedScope" calls
        /// while they are in one method.
        /// </summary>
        static void TestWithNestedScope()
        {
            using (var nestedScope = TagScopeManager.CreateScope())
            {
                // Expected result: ArgumentNullException( "Tag key cannot be null." )
                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentNullException>(() =>
                {
                    Assert.IsNull(nestedScope.Tags[null]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentNullException>(() =>
                {
                    Assert.IsNull(nestedScope.InheritedTags[null]);
                }));

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentNullException>(() =>
                {
                    Assert.IsNull(nestedScope.EffectiveTags[null]);
                }));
            }
        }
Пример #6
0
        public void TagCollections_RemoveThrowsOnTagKeyThatIsNull()
        {
            // ReSharper disable AccessToDisposedClosure

            using (var scope = TagScopeManager.CreateScope())
            {
                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    scope.Tags.Remove(null);
                }));

                scope.Tags.Add("tag1", "value1");
                scope.Tags.Add("tag2", "value2");

                Assert.IsTrue(ExceptionTest.IsThrown <ArgumentException>(() =>
                {
                    scope.Tags.Remove(null);
                }));
            }

            // ReSharper restore AccessToDisposedClosure
        }
 void ExplicitRemove(ITagScope scope)
 {
     Assert.IsTrue(ExceptionTest.IsThrown <Exception>(
                       () => scope.Tags.Remove(Constants.ThreadCorrelationIdTagKey)));
 }
 void ExplicitUpdate(ITagScope scope)
 {
     Assert.IsTrue(ExceptionTest.IsThrown <Exception>(
                       () => scope.Tags[ThreadCorrelationIdValue] = Constants.ThreadCorrelationIdTagKey));
 }
 void ExplicitAdd(ITagScope scope)
 {
     Assert.IsTrue(ExceptionTest.IsThrown <Exception>(
                       () => scope.Tags[Constants.ThreadCorrelationIdTagKey] = ThreadCorrelationIdValue));
 }