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)); }
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); }
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()); }
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); }