Beispiel #1
0
        public async Task ValidateAsync_AllRulesSucceed_DoesNotThrow()
        {
            var foo = new Foo();

            var ruleMocks = new List <Mock <IValidationRule <Foo> > >
            {
                this.SetupRuleMock(foo, ValidationResult.Valid)
            };

            var validatorStub = new FooValidator(ruleMocks.Select(p => p.Object).ToList());

            await validatorStub.ValidateAsync(foo);
        }
Beispiel #2
0
        public async Task ValidateAsync_OneRuleFails_Throws()
        {
            var foo = new Foo();

            var ruleMocks = new List <Mock <IValidationRule <Foo> > >
            {
                this.SetupRuleMock(foo, ValidationResult.Error("rule1"))
            };

            var validatorStub = new FooValidator(ruleMocks.Select(p => p.Object).ToList());

            var exception = await Assert.ThrowsAsync <ValidationException>(() => validatorStub.ValidateAsync(foo));

            Assert.NotNull(exception.Result);
            Assert.False(exception.Result.IsValid);
            Assert.Equal("rule1", exception.Result.Errors.Single().Message);
        }