예제 #1
0
        public void Add_IntKeyWhichAlreadyExists_ReplacesExistingValue()
        {
            // Arrange
            var intKey     = 1;
            var dictionary = new Dictionary <int, object>();

            dictionary[intKey] = "Mike";
            var dictionaryAdapter = new DictionaryAdapter <int, object>();
            var resolver          = new DefaultContractResolver();

            // Act
            var addStatus = dictionaryAdapter.TryAdd(dictionary, intKey.ToString(CultureInfo.InvariantCulture), resolver, "James", out var message);

            // Assert
            Assert.True(addStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Single(dictionary);
            Assert.Equal("James", dictionary[intKey]);
        }
예제 #2
0
        public void ReplacingExistingItem_WithGuidKey()
        {
            // Arrange
            var guidKey    = new Guid();
            var dictionary = new Dictionary <Guid, object>();

            dictionary.Add(guidKey, "Mike");
            var dictionaryAdapter = new DictionaryAdapter <Guid, object>();
            var resolver          = new DefaultContractResolver();

            // Act
            var replaceStatus = dictionaryAdapter.TryReplace(dictionary, guidKey.ToString(), resolver, "James", out var message);

            // Assert
            Assert.True(replaceStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Single(dictionary);
            Assert.Equal("James", dictionary[guidKey]);
        }
예제 #3
0
        public void Add_KeyWhichAlreadyExists_ReplacesExistingValue()
        {
            // Arrange
            var key        = "Status";
            var dictionary = new Dictionary <string, int>(StringComparer.Ordinal);

            dictionary[key] = 404;
            var dictionaryAdapter = new DictionaryAdapter <string, int>();
            var resolver          = new DefaultContractResolver();

            // Act
            var addStatus = dictionaryAdapter.TryAdd(dictionary, key, resolver, 200, out var message);

            // Assert
            Assert.True(addStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Single(dictionary);
            Assert.Equal(200, dictionary[key]);
        }
예제 #4
0
        public void ReplacingExistingItem()
        {
            // Arrange
            var nameKey    = "Name";
            var dictionary = new Dictionary <string, object>(StringComparer.Ordinal);

            dictionary.Add(nameKey, "Mike");
            var dictionaryAdapter = new DictionaryAdapter <string, object>();
            var resolver          = new DefaultContractResolver();

            // Act
            var replaceStatus = dictionaryAdapter.TryReplace(dictionary, nameKey, resolver, "James", out var message);

            // Assert
            Assert.True(replaceStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
            Assert.Single(dictionary);
            Assert.Equal("James", dictionary[nameKey]);
        }
예제 #5
0
        public void ReplacingWithInvalidValue_ThrowsInvalidValueForPropertyException()
        {
            // Arrange
            var guidKey    = new Guid();
            var dictionary = new Dictionary <Guid, int>();

            dictionary.Add(guidKey, 5);
            var dictionaryAdapter = new DictionaryAdapter <Guid, int>();
            var resolver          = new DefaultContractResolver();

            // Act
            var replaceStatus = dictionaryAdapter.TryReplace(dictionary, guidKey.ToString(), resolver, "test", out var message);

            // Assert
            Assert.False(replaceStatus);
            Assert.Equal(
                string.Format("The value '{0}' is invalid for target location.", "test"),
                message);
            Assert.Equal(5, dictionary[guidKey]);
        }
예제 #6
0
        public void Test_DoesNotThrowException_IfTestIsSuccessful()
        {
            // Arrange
            var key        = "Name";
            var dictionary = new Dictionary <string, List <object> >();
            var value      = new List <object>()
            {
                "James",
                2,
                new Customer("James", 25)
            };

            dictionary[key] = value;
            var dictionaryAdapter = new DictionaryAdapter <string, List <object> >();
            var resolver          = new DefaultContractResolver();

            // Act
            var testStatus = dictionaryAdapter.TryTest(dictionary, key, resolver, value, out var message);

            //Assert
            Assert.True(testStatus);
            Assert.True(string.IsNullOrEmpty(message), "Expected no error message");
        }