Beispiel #1
0
        public void AddToCurrentTagsWithBuilder()
        {
            ITagContext scopedTags = tagger.EmptyBuilder.Put(KEY_1, VALUE_1).Build();
            IScope      scope1     = tagger.WithTagContext(scopedTags);

            try
            {
                IScope scope2 = tagger.CurrentBuilder.Put(KEY_2, VALUE_2).BuildScoped();
                try
                {
                    Assert.Equal(
                        new List <ITag>()
                    {
                        Tag.Create(KEY_1, VALUE_1), Tag.Create(KEY_2, VALUE_2)
                    },
                        TagsTestUtil.TagContextToList(tagger.CurrentTagContext));
                }
                finally
                {
                    scope2.Dispose();
                }

                Assert.Same(scopedTags, tagger.CurrentTagContext);
            }
            finally
            {
                scope1.Dispose();
            }
        }
Beispiel #2
0
        public void EmptyBuilder()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            Assert.IsType <TagContextBuilder>(builder);
            Assert.Empty(TagsTestUtil.TagContextToList(builder.Build()));
        }
Beispiel #3
0
        public void GetCurrentTagContext_DefaultIsEmptyTagContext()
        {
            ITagContext currentTagContext = tagger.CurrentTagContext;

            Assert.Empty(TagsTestUtil.TagContextToList(currentTagContext));
            Assert.IsType <TagContext>(currentTagContext);
        }
Beispiel #4
0
        public void DefaultTagContext()
        {
            ITagContext defaultTagContext = tagger.CurrentTagContext;

            Assert.Empty(TagsTestUtil.TagContextToList(defaultTagContext));
            Assert.IsType <TagContext>(defaultTagContext);
        }
Beispiel #5
0
        public void CurrentBuilder_DefaultIsEmpty()
        {
            ITagContextBuilder currentBuilder = tagger.CurrentBuilder;

            Assert.IsType <TagContextBuilder>(currentBuilder);
            Assert.Empty(TagsTestUtil.TagContextToList(currentBuilder.Build()));
        }
        public void TestGetCurrentTagContext_DefaultContext()
        {
            ITagContext tags = CurrentTagContextUtils.CurrentTagContext;

            Assert.NotNull(tags);
            Assert.Empty(TagsTestUtil.TagContextToList(tags));
        }
Beispiel #7
0
        public void WithTagContext_SkipNullTag()
        {
            ITagContext tagContextWithNullTag = new SimpleTagContext(TAG1, null, TAG2);
            ITagContext result = GetResultOfWithTagContext(tagContextWithNullTag);

            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2
            }, TagsTestUtil.TagContextToList(result));
        }
Beispiel #8
0
        public void ToBuilder_SkipNullTag()
        {
            ITagContext tagContextWithNullTag = new SimpleTagContext(TAG1, null, TAG2);
            ITagContext newTagContext         = tagger.ToBuilder(tagContextWithNullTag).Build();

            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2
            }, TagsTestUtil.TagContextToList(newTagContext));
        }
Beispiel #9
0
        public void CurrentBuilder_SkipNullTag()
        {
            ITagContext        tagContextWithNullTag = new SimpleTagContext(TAG1, null, TAG2);
            ITagContextBuilder result = GetResultOfCurrentBuilder(tagContextWithNullTag);

            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2
            }, TagsTestUtil.TagContextToList(result.Build()));
        }
Beispiel #10
0
        public void CurrentBuilder()
        {
            ITagContext        tags   = new SimpleTagContext(TAG1, TAG2, TAG3);
            ITagContextBuilder result = GetResultOfCurrentBuilder(tags);

            Assert.IsType <TagContextBuilder>(result);
            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2, TAG3
            }, TagsTestUtil.TagContextToList(result.Build()));
        }
Beispiel #11
0
        public void ToBuilder_ConvertUnknownTagContextToTagContext()
        {
            ITagContext unknownTagContext = new SimpleTagContext(TAG1, TAG2, TAG3);
            ITagContext newTagContext     = tagger.ToBuilder(unknownTagContext).Build();

            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2, TAG3
            }, TagsTestUtil.TagContextToList(newTagContext));
            Assert.IsType <TagContext>(newTagContext);
        }
Beispiel #12
0
        public void WithTagContext_ConvertUnknownTagContextToTagContext()
        {
            ITagContext unknownTagContext = new SimpleTagContext(TAG1, TAG2, TAG3);
            ITagContext result            = GetResultOfWithTagContext(unknownTagContext);

            Assert.IsType <TagContext>(result);
            Assert.Equal(new List <ITag>()
            {
                TAG1, TAG2, TAG3
            }, TagsTestUtil.TagContextToList(result));
        }
Beispiel #13
0
        public void WithTagContext_RemoveDuplicatesFromUnknownTagContext()
        {
            ITag        tag1 = Tag.Create(K1, V1);
            ITag        tag2 = Tag.Create(K1, V2);
            ITagContext tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
            ITagContext result = GetResultOfWithTagContext(tagContextWithDuplicateTags);

            Assert.Equal(new List <ITag>()
            {
                tag2
            }, TagsTestUtil.TagContextToList(result));
        }
Beispiel #14
0
        public void ToBuilder_RemoveDuplicatesFromUnknownTagContext()
        {
            ITag        tag1 = Tag.Create(K1, V1);
            ITag        tag2 = Tag.Create(K1, V2);
            ITagContext tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
            ITagContext newTagContext = tagger.ToBuilder(tagContextWithDuplicateTags).Build();

            Assert.Equal(new List <ITag>()
            {
                tag2
            }, TagsTestUtil.TagContextToList(newTagContext));
        }
Beispiel #15
0
        public void CurrentBuilder_RemoveDuplicateTags()
        {
            ITag               tag1 = Tag.Create(K1, V1);
            ITag               tag2 = Tag.Create(K1, V2);
            ITagContext        tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
            ITagContextBuilder result = GetResultOfCurrentBuilder(tagContextWithDuplicateTags);

            Assert.Equal(new List <ITag>()
            {
                tag2
            }, TagsTestUtil.TagContextToList(result.Build()));
        }
        public void TestWithTagContext()
        {
            Assert.Empty(TagsTestUtil.TagContextToList(CurrentTagContextUtils.CurrentTagContext));

            IScope scopedTags = CurrentTagContextUtils.WithTagContext(tagContext);

            try
            {
                Assert.Same(tagContext, CurrentTagContextUtils.CurrentTagContext);
            }
            finally
            {
                scopedTags.Dispose();
            }
            Assert.Empty(TagsTestUtil.TagContextToList(CurrentTagContextUtils.CurrentTagContext));
        }
        public void TestGetCurrentTagContext_ContextSetToNull()
        {
            var orig = AsyncLocalContext.CurrentTagContext;

            AsyncLocalContext.CurrentTagContext = null;
            try
            {
                ITagContext tags = CurrentTagContextUtils.CurrentTagContext;
                Assert.NotNull(tags);
                Assert.Empty(TagsTestUtil.TagContextToList(tags));
            }
            finally
            {
                AsyncLocalContext.CurrentTagContext = orig;
            }
        }
        public void WithTagContext()
        {
            Assert.Empty(TagsTestUtil.TagContextToList(tagger.CurrentTagContext));
            ITagContext scopedTags = tagger.EmptyBuilder.Put(KEY_1, VALUE_1).Build();
            IScope      scope      = tagger.WithTagContext(scopedTags);

            try
            {
                Assert.Same(scopedTags, tagger.CurrentTagContext);
            }
            finally
            {
                scope.Dispose();
            }
            Assert.Empty(TagsTestUtil.TagContextToList(tagger.CurrentTagContext));
        }
        public void SetCurrentTagsWithBuilder()
        {
            Assert.Empty(TagsTestUtil.TagContextToList(tagger.CurrentTagContext));
            IScope scope = tagger.EmptyBuilder.Put(KEY_1, VALUE_1).BuildScoped();

            try
            {
                Assert.Equal(new List <ITag>()
                {
                    Tag.Create(KEY_1, VALUE_1)
                }, TagsTestUtil.TagContextToList(tagger.CurrentTagContext));
            }
            finally
            {
                scope.Dispose();
            }
            Assert.Empty(TagsTestUtil.TagContextToList(tagger.CurrentTagContext));
        }
        public void CreateBuilderFromCurrentTags()
        {
            ITagContext scopedTags = tagger.EmptyBuilder.Put(KEY_1, VALUE_1).Build();
            IScope      scope      = tagger.WithTagContext(scopedTags);

            try
            {
                ITagContext newTags = tagger.CurrentBuilder.Put(KEY_2, VALUE_2).Build();
                Assert.Equal(new List <ITag>()
                {
                    Tag.Create(KEY_1, VALUE_1), Tag.Create(KEY_2, VALUE_2)
                },
                             TagsTestUtil.TagContextToList(newTags));
                Assert.Same(scopedTags, tagger.CurrentTagContext);
            }
            finally
            {
                scope.Dispose();
            }
        }
Beispiel #21
0
 public void Empty()
 {
     Assert.Empty(TagsTestUtil.TagContextToList(tagger.Empty));
     Assert.IsType <TagContext>(tagger.Empty);
 }