public void Setup() { _oneValue = new KeyValuePair <string, string>("a", "b"); _tenValues = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("a", "b"), new KeyValuePair <string, string>("c", "d"), new KeyValuePair <string, string>("e", "f"), new KeyValuePair <string, string>("g", "h"), new KeyValuePair <string, string>("i", "j"), new KeyValuePair <string, string>("k", "l"), new KeyValuePair <string, string>("m", "n"), new KeyValuePair <string, string>("o", "p"), new KeyValuePair <string, string>("q", "r"), new KeyValuePair <string, string>("s", "t"), }; _smallCapDict = new AdaptiveCapacityDictionary <string, string>(capacity: 1, StringComparer.OrdinalIgnoreCase); _smallCapDictTen = new AdaptiveCapacityDictionary <string, string>(capacity: 10, StringComparer.OrdinalIgnoreCase); _filledSmallDictionary = new AdaptiveCapacityDictionary <string, string>(capacity: 10, StringComparer.OrdinalIgnoreCase); foreach (var a in _tenValues) { _filledSmallDictionary[a.Key] = a.Value; } _dict = new Dictionary <string, string>(1, StringComparer.OrdinalIgnoreCase); _dictTen = new Dictionary <string, string>(10, StringComparer.OrdinalIgnoreCase); _filledDictTen = new Dictionary <string, string>(10, StringComparer.OrdinalIgnoreCase); foreach (var a in _tenValues) { _filledDictTen[a.Key] = a.Value; } }
private void AppendToExpandingAccumulator(string key, string value, StringValues values) { // When there are some values for the same key, so switch to expanding accumulator, and // add a zero count marker in the accumulator to indicate that switch. if (values.Count != 0) { _accumulator[key] = default; if (_expandingAccumulator is null) { _expandingAccumulator = new AdaptiveCapacityDictionary <string, List <string> >(capacity: 5, StringComparer.OrdinalIgnoreCase); } // Already 2 (1 existing + the new one) entries so use List's expansion mechanism for more var list = new List <string>(); list.AddRange(values); list.Add(value); _expandingAccumulator[key] = list; } else { // The marker indicates we are in the expanding accumulator, so just append to the list. _expandingAccumulator[key].Add(value); } }
public void Comparer_IsOrdinalIgnoreCase() { // Arrange // Act var dict = new AdaptiveCapacityDictionary <string, string>(StringComparer.OrdinalIgnoreCase); // Assert Assert.Same(StringComparer.OrdinalIgnoreCase, dict.Comparer); }
public void IndexGet_EmptyStorage_ReturnsNull() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act var value = dict["key"]; // Assert Assert.Null(value); }
public void Add_EmptyStringIsAllowed() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act dict.Add("", "foo"); // Assert Assert.Equal("foo", dict[""]); }
public void IndexGet_EmptyStringIsAllowed() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act var value = dict[""]; // Assert Assert.Null(value); }
public void IndexSet_EmptyStringIsAllowed() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act dict[""] = "foo"; // Assert Assert.Equal("foo", dict[""]); }
public void Remove_EmptyStringIsAllowed() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act var result = dict.Remove(""); // Assert Assert.False(result); }
public void ContainsKey_EmptyStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act var result = dict.ContainsKey("key"); // Assert Assert.False(result); }
public void CreateFromNull() { // Arrange // Act var dict = new AdaptiveCapacityDictionary <string, string>(); // Assert Assert.Empty(dict); Assert.Empty(dict._arrayStorage); Assert.Null(dict._dictionaryStorage); }
public void Count_EmptyStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act var count = dict.Count; // Assert Assert.Equal(0, count); }
public void TryAdd_EmptyStringIsAllowed() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act var result = dict.TryAdd("", "foo"); // Assert Assert.True(result); }
public void Clear_EmptyStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act dict.Clear(); // Assert Assert.Empty(dict); }
public void IsReadOnly_False() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(); // Act var result = ((ICollection <KeyValuePair <string, object?> >)dict).IsReadOnly; // Assert Assert.False(result); }
public void Remove_KeyAndOutValue_EmptyStringIsAllowed() { // Arrange var dict = new AdaptiveCapacityDictionary <string, string>(); // Act var result = dict.Remove("", out var removedValue); // Assert Assert.False(result); Assert.Null(removedValue); }
public void Values_EmptyStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(); // Act var values = dict.Values; // Assert Assert.Empty(values); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void IndexSet_EmptyStorage_UpgradesToList() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(); // Act dict["key"] = "value"; // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void Add_EmptyStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(); // Act dict.Add("key", "value"); // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void CreateFromIEnumerableStringValuePair_CopiesValues() { // Arrange & Act var dict = new AdaptiveCapacityDictionary <string, string>(IEnumerableStringValuePairData, capacity: 3, StringComparer.OrdinalIgnoreCase); // Assert Assert.IsType <KeyValuePair <string, string>[]>(dict._arrayStorage); Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("First Name", kvp.Key); Assert.Equal("James", kvp.Value); }, kvp => { Assert.Equal("Last Name", kvp.Key); Assert.Equal("Henrik", kvp.Value); }, kvp => { Assert.Equal("Middle Name", kvp.Key); Assert.Equal("Bob", kvp.Value); }); }
public void TryAdd_EmptyStorage_CanAdd() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(); // Act var result = dict.TryAdd("key", "value"); // Assert Assert.True(result); Assert.Collection( dict._arrayStorage, kvp => Assert.Equal(new KeyValuePair <string, object?>("key", "value"), kvp), kvp => Assert.Equal(default, kvp),
public void IndexGet_ArrayStorage_NoMatch_ReturnsNull() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(); dict.Add("age", 30); // Act var value = dict["key"]; // Assert Assert.Null(value); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void IndexSet_ListStorage_MatchIgnoreCase_SetsValue() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>() { { "key", "value" }, }; // Act dict["key"] = "value"; // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void Count_ListStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>() { { "key", "value" }, }; // Act var count = dict.Count; // Assert Assert.Equal(1, count); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void ContainsKey_ListStorage_True_CaseInsensitive() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "key", "value" }, }; // Act var result = dict.ContainsKey("kEy"); // Assert Assert.True(result); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void ContainsKey_ListStorage_False() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>() { { "key", "value" }, }; // Act var result = dict.ContainsKey("other"); // Assert Assert.False(result); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void Values_ListStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>() { { "key", "value" }, }; // Act var values = dict.Values; // Assert Assert.Equal(new object[] { "value" }, values); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void IndexGet_ListStorage_MatchIgnoreCase_ReturnsValue() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "key", "value" }, }; // Act var value = dict["kEy"]; // Assert Assert.Equal("value", value); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void Remove_ListStorage_False() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>() { { "key", "value" }, }; // Act var result = dict.Remove("other"); // Assert Assert.False(result); Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }
public void Clear_ListStorage() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>() { { "key", "value" }, }; // Act dict.Clear(); // Assert Assert.Empty(dict); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); Assert.Null(dict._dictionaryStorage); }
public void Remove_ListStorage_True() { // Arrange var dict = new AdaptiveCapacityDictionary <string, object>() { { "key", "value" }, }; // Act var result = dict.Remove("key"); // Assert Assert.True(result); Assert.Empty(dict); Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage); }