Beispiel #1
0
        public void TryTest_ThrowsJsonPatchException_IfTestFails()
        {
            // Arrange
            var     adapter = new DynamicObjectAdapter();
            dynamic target  = new DynamicTestObject();

            target.NewProperty = "Joana";
            var segment = "NewProperty";
            var expectedErrorMessage = $"The current value 'Joana' at path '{segment}' is not equal to the test value 'John'.";
            var options = new JsonSerializerOptions();

            // Act
            var testStatus = adapter.TryTest(target, typeof(DynamicTestObject), segment, options, "John", out string errorMessage);

            // Assert
            Assert.False(testStatus);
            Assert.Equal(expectedErrorMessage, errorMessage);
        }
Beispiel #2
0
        public void TryTest_DoesNotThrowException_IfTestSuccessful()
        {
            var     adapter = new DynamicObjectAdapter();
            dynamic target  = new DynamicTestObject();
            var     value   = new List <object>
            {
                "Joana",
                2,
                new Customer("Joana", 25)
            };

            target.NewProperty = value;
            var segment = "NewProperty";
            var options = new JsonSerializerOptions();

            // Act
            var testStatus = adapter.TryTest(target, typeof(DynamicTestObject), segment, options, value, out string errorMessage);

            // Assert
            Assert.Equal(value, target.NewProperty);
            Assert.True(testStatus);
            Assert.True(string.IsNullOrEmpty(errorMessage), "Expected no error message");
        }