Esempio n. 1
0
            public void Should_ReturnNoErrors_IfValid()
            {
                var modelScope = new ModelScope <MemberClass>(c => true);

                var errors = modelScope.TryGetErrors(new MemberClass(), new ExecutionContextStub(), ValidationStrategy.Complete, 0, out var errorsCollection);

                Assert.False(errors);
                Assert.True(errorsCollection.IsEmpty);
            }
Esempio n. 2
0
            public void Should_ReturnRuleSingleError_IfValid()
            {
                var modelScope = new ModelScope <MemberClass>(c => false);

                modelScope.RuleSingleError = new Error("single error");

                var errors = modelScope.TryGetErrors(new MemberClass(), new ExecutionContextStub(), ValidationStrategy.Complete, 0, out var errorsCollection);

                Assert.True(errors);
                Assert.Single(errorsCollection.Errors);
                Assert.Equal("single error", errorsCollection.Errors.Single().Message);
            }
Esempio n. 3
0
            public void Should_PassStrategy(ValidationStrategy validationStrategy)
            {
                var model = new MemberClass();

                var executed = 0;

                var modelScope = new ModelScope <MemberClass>(c =>
                {
                    Assert.Same(c, model);
                    executed = 1;

                    return(true);
                });

                modelScope.TryGetErrors(model, new ExecutionContextStub(), validationStrategy, 0, out _);

                Assert.Equal(validationStrategy == ValidationStrategy.Force ? 0 : 1, executed);
            }
Esempio n. 4
0
            public void Should_PassValue()
            {
                var model = new MemberClass();

                var executed = 0;

                Predicate <MemberClass> isValid = c =>
                {
                    Assert.Same(c, model);
                    executed++;

                    return(true);
                };

                var modelScope = new ModelScope <MemberClass>(isValid);

                modelScope.TryGetErrors(model, new ExecutionContextStub(), ValidationStrategy.Complete, 0, out _);

                Assert.Equal(1, executed);
            }
Esempio n. 5
0
            public void Should_ThrowException_When_NullExecutionContext()
            {
                var modelScope = new ModelScope <MemberClass>(c => true);

                Assert.Throws <ArgumentNullException>(() => { modelScope.TryGetErrors(new MemberClass(), null, ValidationStrategy.Complete, 0, out _); });
            }