public void ShouldValidateAllItemsInEnumeration()
        {
            var member1 = new Member(null);
            var member2 = new Member(null);
            var club = new Club(new Member("president"), member1, member2);
            var report = new ValidationReport();
            _en1.Validate(club, report, ValidationReportDepth.FieldShortCircuit);

            var memberNameExp = new EquatableExpression(ExpressionHelper.New<Member, string>(mm => mm.Name));
            Assert.IsTrue(report.HasError(member1, memberNameExp), "Expected validation failure for member1. Name was null...");
            Assert.IsTrue(report.HasError(member2, memberNameExp), "Expected validation failure for member2. Name was null...");
        }
Exemple #2
0
        public void ShouldSkipValidationWhenShortCircuiting()
        {
            var president     = new Member(null);
            var club          = new Club(president);
            var report        = new ValidationReport();
            var memberNameExp = new EquatableExpression(ExpressionHelper.New <Member, string>(mm => mm.Name));
            var presidentExp  = new EquatableExpression(ExpressionHelper.New <Club, Member>(cc => cc.President));

            //Report an error on the President expression...
            report.AddError(new ValidationError(new EqualRule <int>(2), presidentExp, new object[0], club, club, presidentExp));
            _en1.Validate(club, report, ValidationReportDepth.FieldShortCircuit);
            //because an error has already been reported on the club's president, the member's name rule would not have been invoked
            Assert.IsFalse(report.HasError(president, memberNameExp));

            //Now try this again without short-circuiting
            _en1.Validate(club, report, ValidationReportDepth.All);
            Assert.IsTrue(report.HasError(president, memberNameExp));
        }
Exemple #3
0
        public void ShouldCulpabiliseComposition()
        {
            var builder = new Fluent.FluentBuilder();

            builder.For <Foo>()
            .Setup(f => f.Foo1.Value)
            .MustEqual(1);

            var engine = builder.Build();
            var foo    = new Foo(1)
            {
                Foo1 = new Foo(0)
            };
            var report = new ValidationReport(engine);

            Assert.IsFalse(report.Validate(foo));
            ValidationError[] errors;
            Assert.IsTrue(report.HasError(foo.Foo1, f => f.Value, out errors));
        }
Exemple #4
0
 public bool HasError <T, R>(T value, System.Linq.Expressions.Expression <Func <T, R> > expression, out ValidationError[] validationErrors)
 {
     return(_innerReport.HasError <T, R>(value, expression, out validationErrors));
 }
        public void ShouldCulpabiliseComposition()
        {
            var builder = new Fluent.FluentBuilder();
            builder.For<Foo>()
                    .Setup(f => f.Foo1.Value)
                        .MustEqual(1);

            var engine = builder.Build();
            var foo = new Foo(1) { Foo1 = new Foo(0) };
            var report = new ValidationReport(engine);
            
            Assert.IsFalse(report.Validate(foo));
            ValidationError[] errors;
            Assert.IsTrue(report.HasError(foo.Foo1, f => f.Value, out errors));

        }
        public void ShouldSkipValidationWhenShortCircuiting()
        {
            var president = new Member(null);
            var club = new Club(president);
            var report = new ValidationReport();
            var memberNameExp = new EquatableExpression(ExpressionHelper.New<Member, string>(mm => mm.Name));
            var presidentExp = new EquatableExpression(ExpressionHelper.New<Club, Member>(cc => cc.President));

            //Report an error on the President expression...
            report.AddError(new ValidationError(new EqualRule<int>(2), presidentExp, new object[0], club, club, presidentExp));
            _en1.Validate(club, report, ValidationReportDepth.FieldShortCircuit);
            //because an error has already been reported on the club's president, the member's name rule would not have been invoked
            Assert.IsFalse(report.HasError(president, memberNameExp));

            //Now try this again without short-circuiting
            _en1.Validate(club, report, ValidationReportDepth.All);
            Assert.IsTrue(report.HasError(president, memberNameExp));
        }