Пример #1
0
        public void TestNegativeCases()
        {
            TagList list = new TagList {
                new KeyValuePair <string, object?>("1", 1), new KeyValuePair <string, object?>("2", 2)
            };
            KeyValuePair <string, object?> kvp = default;

            Assert.Throws <ArgumentOutOfRangeException>(() => kvp      = list[2]);
            Assert.Throws <ArgumentOutOfRangeException>(() => list[2]  = kvp);
            Assert.Throws <ArgumentOutOfRangeException>(() => kvp      = list[-1]);
            Assert.Throws <ArgumentOutOfRangeException>(() => list[-2] = kvp);

            KeyValuePair <string, object?>[] array = new KeyValuePair <string, object?> [1];
            Assert.Throws <ArgumentException>(() => list.CopyTo(array.AsSpan()));
            Assert.Throws <ArgumentException>(() => list.CopyTo(array, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.CopyTo(array, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.CopyTo(array, -1));
            Assert.Throws <ArgumentNullException>(() => list.CopyTo(null, 0));

            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(-1, default));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(3, default));

            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(2));
        }
Пример #2
0
 public void TestCopyTo()
 {
     for (int i = 0; i < 20; i++)
     {
         CreateTagList(i, out TagList tagList);
         KeyValuePair <string, object?>[] array = new KeyValuePair <string, object?> [tagList.Count];
         tagList.CopyTo(array.AsSpan());
         ValidateTags(tagList, array);
         array = new KeyValuePair <string, object?> [tagList.Count];
         tagList.CopyTo(array);
         ValidateTags(tagList, array);
     }
 }
Пример #3
0
        public void TestConstruction()
        {
            for (int i = 0; i < 30; i++)
            {
                CreateTagList(i, out TagList tagList);
                ValidateTags(in tagList, i);
                Assert.False(tagList.IsReadOnly);

                KeyValuePair <string, object?>[] array = new KeyValuePair <string, object?> [tagList.Count];
                tagList.CopyTo(array);
                TagList list = new TagList(array.AsSpan());
                ValidateTags(in tagList, i);
            }
        }