public void Replace_NonExistingKey_Fails() { // Arrange var nameKey = "Name"; var dictionary = new Dictionary <string, object>(StringComparer.Ordinal); var dictionaryAdapter = new DictionaryAdapter <string, object>(); var resolver = new DefaultContractResolver(); // Act var replaceStatus = dictionaryAdapter.TryReplace(dictionary, nameKey, resolver, "Mike", out var message); // Assert Assert.False(replaceStatus); Assert.Equal("The target location specified by path segment 'Name' was not found.", message); Assert.Empty(dictionary); }
public void Replace_NonExistingKey_Fails() { // Arrange var nameKey = "Name"; var dictionary = new Dictionary <string, object>(StringComparer.Ordinal); var dictionaryAdapter = new DictionaryAdapter <string, object>(); var options = new JsonSerializerOptions(); // Act var replaceStatus = dictionaryAdapter.TryReplace(dictionary, typeof(Dictionary <string, object>), nameKey, options, "Mike", out var message); // Assert Assert.False(replaceStatus); Assert.Equal("The target location specified by path segment 'Name' was not found.", message); Assert.Empty(dictionary); }
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("The value 'test' is invalid for target location.", message); Assert.Equal(5, dictionary[guidKey]); }
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]); }
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]); }
public void ReplacingExistingItem_WithGuidKey() { // Arrange var guidKey = new Guid(); var dictionary = new Dictionary <Guid, object> { { guidKey, "Mike" } }; var dictionaryAdapter = new DictionaryAdapter <Guid, object>(); var options = new JsonSerializerOptions(); // Act var replaceStatus = dictionaryAdapter.TryReplace(dictionary, typeof(Dictionary <Guid, object>), guidKey.ToString(), options, "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]); }
public void ReplacingExistingItem() { // Arrange var nameKey = "Name"; var dictionary = new Dictionary <string, object>(StringComparer.Ordinal) { { nameKey, "Mike" } }; var dictionaryAdapter = new DictionaryAdapter <string, object>(); var options = new JsonSerializerOptions(); // Act var replaceStatus = dictionaryAdapter.TryReplace(dictionary, typeof(Dictionary <string, object>), nameKey, options, "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]); }
public void ReplacingWithInvalidValue_ThrowsInvalidValueForPropertyException() { // Arrange var guidKey = new Guid(); var dictionary = new Dictionary <Guid, int> { { guidKey, 5 } }; var dictionaryAdapter = new DictionaryAdapter <Guid, int>(); var options = new JsonSerializerOptions(); // Act var replaceStatus = dictionaryAdapter.TryReplace(dictionary, typeof(Dictionary <Guid, int>), guidKey.ToString(), options, "test", out var message); // Assert Assert.False(replaceStatus); Assert.Equal("The value 'test' is invalid for target location.", message); Assert.Equal(5, dictionary[guidKey]); }
public void Replace_UsesCustomConverter() { // Arrange var nameKey = "Name"; var dictionary = new Dictionary <string, Rectangle>(StringComparer.Ordinal); dictionary.Add(nameKey, new Rectangle() { RectangleProperty = "Mike" }); var dictionaryAdapter = new DictionaryAdapter <string, Rectangle>(); var resolver = new RectangleContractResolver(); // 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].RectangleProperty); }