public void Test_ValidationFailedResult_ToStringEmpty() { // Arrange var modelState = new ModelStateDictionary(); // Act var res = new ValidationFailedResult(modelState); var str = res.ToString(); // Assert str.Should().Be("Validation Error (400): Model could not be validated."); }
/// <summary> /// Called when [action executing]. /// </summary> /// <param name="context">The context.</param> /// <inheritdoc /> public override void OnActionExecuting(ActionExecutingContext context) { if (!context.ModelState.IsValid) { var validationFailedResult = new ValidationFailedResult(context.ModelState); if (_logMessage) { var logger = (ILogger)context.HttpContext.RequestServices.GetService(typeof(ILogger)); logger?.LogInformation(validationFailedResult.ToString()); } context.Result = validationFailedResult; } }
public void Test_ValidationFailedResult_ToString() { // Arrange var modelState = new ModelStateDictionary(); modelState.AddModelError("TestKey1", "TestValue1"); modelState.AddModelError("TestKey2", "TestValue2"); // Act var res = new ValidationFailedResult(modelState); var str = res.ToString(); // Assert str.Should().Be("Validation Error (400): Model could not be validated. TestKey1 - TestValue1, TestKey2 - TestValue2"); }