示例#1
0
        public void RemoveFromListInvalidPositionTooSmall_LogsError()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Remove<int>(o => o.IntegerList, -1);

            var logger = new TestErrorLogger<SimpleDTO>();

            // Act
            patchDoc.ApplyTo(doc, logger.LogErrorMessage);

            // Assert
            Assert.Equal("Property does not exist at path '/integerlist/-1'.", logger.ErrorMessage);
        }
示例#2
0
        public void RemoveFromListInvalidPositionTooLarge_LogsError()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Remove<int>(o => o.IntegerList, 3);

            var logger = new TestErrorLogger<SimpleDTO>();

            // Act
            patchDoc.ApplyTo(doc, logger.LogErrorMessage);

            // Assert
            Assert.Equal(
                "For operation 'remove' on array property at path '/integerlist/3', the index is " +
                    "larger than the array size.",
                logger.ErrorMessage);
        }
示例#3
0
        public void AddToListInvalidPositionTooLarge_LogsError()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                SimpleDTO = new SimpleDTO()
                {
                    IntegerList = new List<int>() { 1, 2, 3 }
                }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Add<int>(o => o.SimpleDTO.IntegerList, 4, 4);

            var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();

            // Act
            patchDoc.ApplyTo(doc, logger.LogErrorMessage);

            //Assert
            Assert.Equal(
                "For operation 'add' on array property at path '/simpledto/integerlist/4', the index is larger than " +
                    "the array size.",
                logger.ErrorMessage);

        }
示例#4
0
        public void AddToListInvalidPositionTooSmall_LogsError()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<int>(o => o.IntegerList, 4, -1);

            var logger = new TestErrorLogger<SimpleDTO>();

            patchDoc.ApplyTo(doc, logger.LogErrorMessage);
             
            // Assert
            Assert.Equal(
                "For operation 'add' on array property at path '/integerlist/-1', the index is negative.",
                logger.ErrorMessage);
        }
示例#5
0
        public void RemoveFromListInvalidPositionTooSmall_LogsError()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                SimpleDTO = new SimpleDTO()
                {
                    IntegerList = new List<int>() { 1, 2, 3 }
                }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, -1);

            var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();


            patchDoc.ApplyTo(doc, logger.LogErrorMessage);

            // Assert
            Assert.Equal("For operation 'remove' on array property at path '/simpledto/integerlist/-1', the index is negative.", logger.ErrorMessage);
        }