示例#1
0
        public async Task ModelErrorsPopulatedWithValidationErrors(string json, Type type, int expectedErrors)
        {
            JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();

            formatter.RequiredMemberSelector = new SimpleRequiredMemberSelector();
            Mock <IFormatterLogger> mockLogger = new Mock <IFormatterLogger>()
            {
            };

            await JsonNetSerializationTest.DeserializeAsync(json, type, formatter, mockLogger.Object);

            mockLogger.Verify(mock => mock.LogError(It.IsAny <string>(), It.IsAny <Exception>()), Times.Exactly(expectedErrors));
        }
示例#2
0
        public void ModelErrorsPopulatedWithValidationErrors(string json, Type type, int expectedErrors)
        {
            JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();

            formatter.RequiredMemberSelector = new SimpleRequiredMemberSelector();

            int errors = 0;
            Mock <IFormatterLogger> mockLogger = new Mock <IFormatterLogger>();

            mockLogger.Setup(mock => mock.LogError(It.IsAny <string>(), It.IsAny <string>())).Callback(() => errors++);


            Assert.DoesNotThrow(() => JsonNetSerializationTest.Deserialize(json, type, formatter, mockLogger.Object));
            Assert.Equal(expectedErrors, errors);
        }
示例#3
0
        public void HittingMaxDepthRaisesOnlyOneValidationError()
        {
            // Arrange
            JsonMediaTypeFormatter  formatter  = new JsonMediaTypeFormatter();
            Mock <IFormatterLogger> mockLogger = new Mock <IFormatterLogger>();

            StringBuilder sb = new StringBuilder("{'A':null}");

            for (int i = 0; i < 5000; i++)
            {
                sb.Insert(0, "{'A':");
                sb.Append('}');
            }
            string json = sb.ToString();

            // Act
            JsonNetSerializationTest.Deserialize(json, typeof(Nest), formatter, mockLogger.Object);

            // Assert
            mockLogger.Verify(mock => mock.LogError(It.IsAny <string>(), It.IsAny <Exception>()), Times.Once());
        }
示例#4
0
        public void HittingMaxDepthRaisesOnlyOneValidationError()
        {
            // Arrange
            JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();
            int errors = 0;
            Mock <IFormatterLogger> mockLogger = new Mock <IFormatterLogger>();

            mockLogger.Setup(mock => mock.LogError(It.IsAny <string>(), It.IsAny <string>())).Callback(() => errors++);

            StringBuilder sb = new StringBuilder("{'A':null}");

            for (int i = 0; i < 5000; i++)
            {
                sb.Insert(0, "{'A':");
                sb.Append('}');
            }
            string json = sb.ToString();

            // Act
            Assert.DoesNotThrow(() => JsonNetSerializationTest.Deserialize(json, typeof(Nest), formatter, mockLogger.Object));

            // Assert
            Assert.Equal(1, errors);
        }