Exemplo n.º 1
0
        public void Add_EmptyStringIsAllowed()
        {
            // Arrange
            var dict = new AdaptiveCapacityDictionary <string, string>();

            // Act
            dict.Add("", "foo");

            // Assert
            Assert.Equal("foo", dict[""]);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void Add_ListStorage()
        {
            // Arrange
            var dict = new AdaptiveCapacityDictionary <string, object>()
            {
                { "age", 30 },
            };

            // Act
            dict.Add("key", "value");

            // Assert
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); },
                kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); });
            Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage);
        }
Exemplo n.º 5
0
        public void Add_DuplicateKey_CaseInsensitive()
        {
            // Arrange
            var dict = new AdaptiveCapacityDictionary <string, object>(StringComparer.OrdinalIgnoreCase)
            {
                { "key", "value" },
            };

            var message = $"An element with the key 'kEy' already exists in the {nameof(AdaptiveCapacityDictionary<string, string>)}";

            // Act & Assert
            ExceptionAssert.ThrowsArgument(() => dict.Add("kEy", "value2"), "key", message);

            // Assert
            Assert.Collection(
                dict.OrderBy(kvp => kvp.Key),
                kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); });
            Assert.IsType <KeyValuePair <string, object?>[]>(dict._arrayStorage);
        }