public void verify_parsing_error_catched_by_attribute() { var model = new BrokenModel(); var context = new ValidationContext(model); model.Value = 0; var e = Assert.Throws <ValidationException>(() => Validator.TryValidateObject(model, context, null, true)); Assert.Equal( "AssertThatAttribute: validation applied to Value field failed.", e.Message); Assert.IsType <InvalidOperationException>(e.InnerException); Assert.Equal( @"Parse error on line 1, column 9: ... # ... ^--- Invalid token.", e.InnerException.Message); model.Value = null; e = Assert.Throws <ValidationException>(() => Validator.TryValidateObject(model, context, null, true)); Assert.Equal( "RequiredIfAttribute: validation applied to Value field failed.", e.Message); Assert.IsType <InvalidOperationException>(e.InnerException); Assert.Equal( @"Parse error on line 1, column 9: ... # ... ^--- Invalid token.", e.InnerException.Message); }
public void verify_parsing_error_catched_by_attribute() { var model = new BrokenModel(); var context = new ValidationContext(model); model.Value = 0; var e = Assert.Throws<ValidationException>(() => Validator.TryValidateObject(model, context, null, true)); Assert.Equal( "AssertThatAttribute: validation applied to Value field failed.", e.Message); Assert.IsType<ParseErrorException>(e.InnerException); Assert.Equal( @"Parse error on line 1, column 9: ... # ... ^--- Invalid token.", e.InnerException.Message); model.Value = null; e = Assert.Throws<ValidationException>(() => Validator.TryValidateObject(model, context, null, true)); Assert.Equal( "RequiredIfAttribute: validation applied to Value field failed.", e.Message); Assert.IsType<ParseErrorException>(e.InnerException); Assert.Equal( @"Parse error on line 1, column 9: ... # ... ^--- Invalid token.", e.InnerException.Message); }