Exemplo n.º 1
0
        public void CurrentBuilder_DefaultIsEmpty()
        {
            ITagContextBuilder currentBuilder = tagger.CurrentBuilder;

            Assert.IsType <TagContextBuilder>(currentBuilder);
            Assert.Empty(TagsTestUtil.TagContextToList(currentBuilder.Build()));
        }
Exemplo n.º 2
0
        public void EmptyBuilder()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            Assert.IsType <TagContextBuilder>(builder);
            Assert.Empty(TagsTestUtil.TagContextToList(builder.Build()));
        }
        public void TestRoundtrip_TagContextWithMaximumSize()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            for (int i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8; i++)
            {
                // Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
                // Add 1024 tags, the total size should just be 8192.
                String str;
                if (i < 10)
                {
                    str = "000" + i;
                }
                else if (i < 100)
                {
                    str = "00" + i;
                }
                else if (i < 1000)
                {
                    str = "0" + i;
                }
                else
                {
                    str = "" + i;
                }
                builder.Put(TagKey.Create(str), TagValue.Create(str));
            }
            TestRoundtripSerialization(builder.Build());
        }
        public void TestSerializeTooLargeTagContext()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            for (int i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
            {
                // Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
                String str;
                if (i < 10)
                {
                    str = "000" + i;
                }
                else if (i < 100)
                {
                    str = "00" + i;
                }
                else if (i < 1000)
                {
                    str = "0" + i;
                }
                else
                {
                    str = i.ToString();
                }
                builder.Put(TagKey.Create(str), TagValue.Create(str));
            }
            // The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
            // more than limit.
            builder.Put(TagKey.Create("last"), TagValue.Create("last1"));

            ITagContext tagContext = builder.Build();

            Assert.Throws <TagContextSerializationException>(() => serializer.ToByteArray(tagContext));
        }
        private void TestSerialize(params ITag[] tags)
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            foreach (var tag in tags)
            {
                builder.Put(tag.Key, tag.Value);
            }

            byte[]        actual          = serializer.ToByteArray(builder.Build());
            var           tagsList        = tags.ToList();
            var           tagPermutation  = Permutate(tagsList, tagsList.Count);
            ISet <String> possibleOutPuts = new HashSet <String>();

            foreach (List <ITag> list in tagPermutation)
            {
                MemoryStream expected = new MemoryStream();
                expected.WriteByte(SerializationUtils.VersionId);
                foreach (ITag tag in list)
                {
                    expected.WriteByte(SerializationUtils.TagFieldId);
                    EncodeString(tag.Key.Name, expected);
                    EncodeString(tag.Value.AsString, expected);
                }
                var bytes = expected.ToArray();
                possibleOutPuts.Add(Encoding.UTF8.GetString(bytes));
            }
            var exp = Encoding.UTF8.GetString(actual);

            Assert.Contains(exp, possibleOutPuts);
        }
Exemplo n.º 6
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()));
        }
Exemplo n.º 7
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()));
        }
Exemplo n.º 8
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()));
        }