Esempio n. 1
0
        public void TryAdd_ThrowsJsonPatchException_IfPropertyDoesNotExist()
        {
            // Arrange
            var adapter          = new PocoAdapter();
            var contractResolver = new DefaultContractResolver();
            var model            = new Customer
            {
                Name = "Joana"
            };
            var expectedErrorMessage = "The target location specified by path segment 'LastName' was not found.";

            // Act
            var addStatus = adapter.TryAdd(model, "LastName", contractResolver, "Smith", out var errorMessage);

            // Assert
            Assert.False(addStatus);
            Assert.Equal(expectedErrorMessage, errorMessage);
        }
Esempio n. 2
0
        public void TryAdd_ReplacesExistingProperty()
        {
            // Arrange
            var adapter          = new PocoAdapter();
            var contractResolver = new DefaultContractResolver();
            var model            = new Customer
            {
                Name = "Joana"
            };

            // Act
            var addStatus = adapter.TryAdd(model, "Name", contractResolver, "John", out var errorMessage);

            // Assert
            Assert.Equal("John", model.Name);
            Assert.True(addStatus);
            Assert.True(string.IsNullOrEmpty(errorMessage), "Expected no error message");
        }