Exemplo n.º 1
0
        public void ModelErrorsPopulatedWithValidationErrors(string json, Type type, int expectedErrors)
        {
            JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();

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


            JsonNetSerializationTest.Deserialize(json, type, formatter, mockLogger.Object);

            mockLogger.Verify(mock => mock.LogError(It.IsAny <string>(), It.IsAny <Exception>()), Times.Exactly(expectedErrors));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }