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); }
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); }
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); }
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); }
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 _); }); }