public void WhenTheFieldIsSmallerThanTheMinLength__ThenTheCorrectErrorMessageIsReturned(string input) { // arrange var answerItem = AnswerBuilder.Build.WithDefaultValue(input).AnAnswer(); var properties = new TextInputValidationProperties { MinLength = 3, MinLengthMessage = Fx.Create <string>() }; InFlightQuestion = new InFlightQuestion { Answer = answerItem }; // act TestService = new TextInputValidation(properties); var result = Act(); // assert Assert.False(result.IsValid); Assert.Contains(properties.MinLengthMessage, result.Errors.Select(x => x.ErrorMessage)); }
public void WhenTheFieldIsNotRequired__ThenNoErrorIsReturned(string input) { // arrange var answerItem = AnswerBuilder.Build.WithDefaultValue(input).AnAnswer(); var properties = new TextInputValidationProperties { IsRequired = false }; InFlightQuestion = new InFlightQuestion { Answer = answerItem }; // act TestService = new TextInputValidation(properties); var result = Act(); // assert Assert.True(result.IsValid); Assert.Empty(result.Errors); }
public void WhenTheValidationRequiresANumber__AndTheInputIsNotANumber__ThenCorrectErrorMessageIsReturned(string input) { // arrange var answerItem = AnswerBuilder.Build.WithDefaultValue(input).AnAnswer(); var properties = new TextInputValidationProperties { IsNumber = true, IsNumberMessage = Fx.Create <string>() }; InFlightQuestion = new InFlightQuestion { Answer = answerItem }; // act TestService = new TextInputValidation(properties); var result = Act(); // assert Assert.False(result.IsValid); Assert.Contains(properties.IsNumberMessage, result.Errors.Select(x => x.ErrorMessage)); }