public void Should_NotRunValidation_When_NullableHasNoValue(bool?shouldExecuteInfo, int?errorId, object errorModeBoxed, string path) { var commandScope = new NullableCommandScope <decimal>(); var executionCounter = 0; commandScope.ExecutionCondition = !shouldExecuteInfo.HasValue ? (Predicate <decimal?>)null : m => { m.Should().BeNull(); executionCounter++; return(shouldExecuteInfo.Value); }; commandScope.ErrorId = errorId; commandScope.ErrorMode = (ErrorMode)errorModeBoxed; commandScope.Path = path; commandScope.ScopeId = 123; var validationContext = Substitute.For <IValidationContext>(); commandScope.ShouldValidate( null, validationContext, shouldExecuteInfo, context => { }); validationContext.DidNotReceiveWithAnyArgs().EnterScope <decimal>(default, default);
public void Should_RunValidation(bool?shouldExecuteInfo, int?errorId, object errorModeBoxed, string path) { var commandScope = new NullableCommandScope <decimal>(); var model = (decimal?)667; var executionCounter = 0; commandScope.ExecutionCondition = !shouldExecuteInfo.HasValue ? (Predicate <decimal?>)null : m => { m.Should().Be(model); executionCounter++; return(shouldExecuteInfo.Value); }; commandScope.ErrorId = errorId; commandScope.ErrorMode = (ErrorMode)errorModeBoxed; commandScope.Path = path; commandScope.ScopeId = 123; var validationContext = Substitute.For <IValidationContext>(); commandScope.ShouldValidate( model, validationContext, shouldExecuteInfo, context => { context.Received().EnterScope(Arg.Is(123), Arg.Is(model)); }); executionCounter.Should().Be(shouldExecuteInfo.HasValue ? 1 : 0); }