public void TestNullValue()
        {
            var entry = new DistributedContextEntry("foo", null);

            Assert.Equal("foo", entry.Key);
            Assert.Empty(entry.Value);
        }
        public void TestNullKeyNullValue()
        {
            var entry = new DistributedContextEntry(null, null);

            Assert.Empty(entry.Key);
            Assert.Empty(entry.Value);
        }
Exemplo n.º 3
0
        public void CurrentBuilder_RemoveDuplicateTags()
        {
            var         tag1 = new DistributedContextEntry(K1, V1);
            var         tag2 = new DistributedContextEntry(K1, V2);
            ITagContext tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
            var         result = GetResultOfCurrentBuilder(tagContextWithDuplicateTags);

            Assert.Equal(new List <DistributedContextEntry>()
            {
                tag2
            }, TagsTestUtil.TagContextToList(result.Build()));
        }
Exemplo n.º 4
0
        public void WithTagContext_RemoveDuplicatesFromUnknownTagContext()
        {
            var         tag1 = new DistributedContextEntry(K1, V1);
            var         tag2 = new DistributedContextEntry(K1, V2);
            ITagContext tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
            var         result = GetResultOfWithTagContext(tagContextWithDuplicateTags);

            Assert.Equal(new List <DistributedContextEntry>()
            {
                tag2
            }, TagsTestUtil.TagContextToList(result));
        }
Exemplo n.º 5
0
        public void ToBuilder_RemoveDuplicatesFromUnknownTagContext()
        {
            var         tag1 = new DistributedContextEntry(K1, V1);
            var         tag2 = new DistributedContextEntry(K1, V2);
            ITagContext tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
            var         newTagContext = tagger.ToBuilder(tagContextWithDuplicateTags).Build();

            Assert.Equal(new List <DistributedContextEntry>()
            {
                tag2
            }, TagsTestUtil.TagContextToList(newTagContext));
        }
        public void TestTagEquals()
        {
            var tag1 = new DistributedContextEntry("Key", "foo");
            var tag2 = new DistributedContextEntry("Key", "foo");
            var tag3 = new DistributedContextEntry("Key", "bar");
            var tag4 = new DistributedContextEntry("Key2", "foo");

            Assert.Equal(tag1, tag2);
            Assert.NotEqual(tag1, tag3);
            Assert.NotEqual(tag1, tag4);
            Assert.NotEqual(tag2, tag3);
            Assert.NotEqual(tag2, tag4);
            Assert.NotEqual(tag3, tag4);
        }
        /// <summary>
        /// Check whether <see cref="DistributedContextEntry"/> matches this filter pattern.
        /// </summary>
        /// <param name="entry">Distributed Context entry to check.</param>
        /// <returns>True if <see cref="DistributedContextEntry"/> matches this filter, false - otherwise.</returns>
        public bool IsMatch(DistributedContextEntry entry)
        {
            bool result = false;

            switch (this.Operator)
            {
            case FilterMatchOperator.Equal: result = entry.Key.Equals(this.MatchString); break;

            case FilterMatchOperator.NotEqual: result = !entry.Key.Equals(this.MatchString); break;

            case FilterMatchOperator.HasPrefix: result = entry.Key.StartsWith(this.MatchString, StringComparison.Ordinal); break;
            }

            if (result)
            {
                this.Action(entry);
            }

            return(result);
        }
 private static void EncodeTag(DistributedContextEntry tag, MemoryStream byteArrayDataOutput)
 {
     byteArrayDataOutput.WriteByte(TagFieldId);
     EncodeString(tag.Key, byteArrayDataOutput);
     EncodeString(tag.Value, byteArrayDataOutput);
 }