示例#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 async Task 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
            await JsonNetSerializationTest.DeserializeAsync(json, typeof(Nest), formatter, mockLogger.Object);

            // Assert
            mockLogger.Verify(mock => mock.LogError(It.IsAny <string>(), It.IsAny <Exception>()), Times.Once());
        }