public void Unexpected_message_check(string withoutErrMsg, string[] errMessages)
        {
            var validator = new InlineValidator <Person>();

            foreach (var msg in errMessages)
            {
                validator.Add(v => v.RuleFor(x => x.Surname).NotNull().WithMessage(msg));
            }

            var ex = Assert.Throws <ValidationTestException>(() =>
                                                             validator.TestValidate(new Person {
            }).ShouldHaveAnyValidationError().WithoutErrorMessage(withoutErrMsg));

            ex.Message.ShouldEqual($"Found an unexpected error message of '{withoutErrMsg}'");
        }
예제 #2
0
        public void Unexpected_message_check(string withoutErrMsg, string[] errMessages)
        {
            bool exceptionCaught = false;

            try {
                var validator = new InlineValidator <Person>();
                foreach (var msg in errMessages)
                {
                    validator.Add(v => v.RuleFor(x => x.Surname).NotNull().WithMessage(msg));
                }
                validator.TestValidate(new Person {
                }).Result.Errors.WithoutErrorMessage(withoutErrMsg);
            }
            catch (ValidationTestException e) {
                exceptionCaught = true;

                e.Message.ShouldEqual($"Found an unexpected error message of '{withoutErrMsg}'");
            }

            exceptionCaught.ShouldEqual(errMessages.Contains(withoutErrMsg));
        }