-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
CollectionsUtilTests.cs
65 lines (51 loc) · 2.26 KB
/
CollectionsUtilTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Specialized;
using Xunit;
namespace System.Collections.Tests
{
public static class CollectionsUtilTests
{
[Fact]
public static void CreateCaseInsensitiveHashtable()
{
Hashtable hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable();
Assert.Equal(0, hashtable.Count);
hashtable.Add("key1", "value1");
Assert.Equal("value1", hashtable["key1"]);
AssertExtensions.Throws<ArgumentException>(null, () => hashtable.Add("key1", "value1"));
}
[Fact]
public static void CreateCaseInsensitiveHashtable_Capacity()
{
Hashtable hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable(15);
Assert.Equal(0, hashtable.Count);
hashtable.Add("key1", "value1");
Assert.Equal("value1", hashtable["key1"]);
Assert.Equal(1, hashtable.Count);
AssertExtensions.Throws<ArgumentException>(null, () => hashtable.Add("key1", "value1"));
}
[Fact]
public static void CreateCaseInsensitiveHashtable_IDictionary()
{
Hashtable hashtable1 = CollectionsUtil.CreateCaseInsensitiveHashtable();
hashtable1.Add("key1", "value1");
Hashtable hashtable2 = CollectionsUtil.CreateCaseInsensitiveHashtable(hashtable1);
Assert.Equal(1, hashtable2.Count);
hashtable2.Add("key2", "value2");
Assert.Equal("value1", hashtable2["key1"]);
Assert.Equal(2, hashtable2.Count);
AssertExtensions.Throws<ArgumentException>(null, () => hashtable2.Add("key1", "value1"));
}
[Fact]
public static void CreateCaseInsensitiveSortedList()
{
SortedList sortedList = CollectionsUtil.CreateCaseInsensitiveSortedList();
Assert.Equal(0, sortedList.Count);
sortedList.Add("key1", "value1");
Assert.Equal("value1", sortedList["key1"]);
Assert.Equal(1, sortedList.Count);
AssertExtensions.Throws<ArgumentException>(null, () => sortedList.Add("key1", "value1"));
}
}
}