Пример #1
0
        public void TryRemove_SetsPropertyToNull()
        {
            // Arrange
            var adapter          = new PocoAdapter();
            var contractResolver = new DefaultContractResolver();
            var model            = new Customer
            {
                Name = "Joana"
            };

            // Act
            var removeStatus = adapter.TryRemove(model, "Name", contractResolver, out var errorMessage);

            // Assert
            Assert.Null(model.Name);
            Assert.True(removeStatus);
            Assert.True(string.IsNullOrEmpty(errorMessage), "Expected no error message");
        }
Пример #2
0
        public void TryRemove_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 removeStatus = adapter.TryRemove(model, "LastName", contractResolver, out var errorMessage);

            // Assert
            Assert.False(removeStatus);
            Assert.Equal(expectedErrorMessage, errorMessage);
        }