protected NullableNumericValidator <TEntity, TProperty> RuleFor <TProperty>(Expression <Func <TEntity, TProperty?> > getterExpression) where TProperty : struct, IComparable { var getter = PropertyExpressionHelper.InitializeGetter(getterExpression); var propertyName = PropertyExpressionHelper.GetPropertyName(getterExpression); var intValidator = new NullableNumericValidator <TEntity, TProperty>(o => getter((TEntity)o), propertyName); _validators.Add(intValidator); return(intValidator); }
public void TestParameterNotEqualToPasses( string parameterName, sbyte?parameterValue, sbyte?valueToCompare, NullableNumericValidator <sbyte> validatorBase) { "Given a new ValidatorBase" .x(() => validatorBase = Validate.That(parameterName, parameterValue)); "Testing that the parameter value is equal to the value to compare against" .x(() => validatorBase.IsNotEqualTo(valueToCompare).OtherwiseThrowException()); "Should not result in an exception" .x(() => validatorBase.CurrentException.Should().BeNull()); }
public void TestParameterConditionOrPasses( string parameterName, sbyte?parameterValue, sbyte?lowerBound, sbyte?upperBound, NullableNumericValidator <sbyte> validatorBase) { "Given a new ValidatorBase" .x(() => validatorBase = Validate.That(parameterName, parameterValue)); "Testing that the parameter value is less than or equal to the lower bound or greater than or equal to the upper bound" .x(() => validatorBase.IsLessThanOrEqualTo(lowerBound).Or.IsGreaterThanOrEqualTo(upperBound).OtherwiseThrowException()); "Should not result in an exception" .x(() => validatorBase.CurrentException.Should().BeNull()); }
public void TestParameterNotEqualToFails( string parameterName, sbyte?parameterValue, sbyte?valueToCompare, NullableNumericValidator <sbyte> validatorBase, Action act) { "Given a new ValidatorBase" .x(() => validatorBase = Validate.That(parameterName, parameterValue)); "Testing that the parameter value is equal to the value to compare against" .x(() => act = () => validatorBase.IsNotEqualTo(valueToCompare).OtherwiseThrowException()); "Should throw an exception" .x(() => act.ShouldThrow <ArgumentEqualityException>() .WithMessage(string.Format(Resources.MustNotBeEqualToX + "\r\nParameter name: {1}", valueToCompare, parameterName))); }
public void TestParameterConditionAndFailsLower( string parameterName, sbyte?parameterValue, sbyte?lowerBound, sbyte?upperBound, NullableNumericValidator <sbyte> validatorBase, Action act) { "Given a new ValidatorBase" .x(() => validatorBase = Validate.That(parameterName, parameterValue)); "Testing that the parameter value is greater or equal to the lower bound and less than or equal to the upper bound" .x(() => act = () => validatorBase.IsGreaterThanOrEqualTo(lowerBound).And.IsLessThanOrEqualTo(upperBound).OtherwiseThrowException()); "Should throw an exception" .x(() => act.ShouldThrow <ArgumentOutOfRangeException>() .WithMessage(string.Format(Resources.MustBeGreaterThanOrEqualToX + "\r\nParameter name: {1}", lowerBound, parameterName))); }
public void TestParameterIsPositivePasses(string parameterName, sbyte?parameterValue, NullableNumericValidator <sbyte> validatorBase) { "Given a new ValidatorBase" .x(() => validatorBase = Validate.That(parameterName, parameterValue)); "Testing that the parameter is false" .x(() => validatorBase.IsPositive().OtherwiseThrowException()); "Should not result in an exception" .x(() => validatorBase.CurrentException.Should().BeNull()); }
public void TestParameterIsPositiveFails(string parameterName, sbyte?parameterValue, NullableNumericValidator <sbyte> validatorBase, Action act) { "Given a new ValidatorBase" .x(() => validatorBase = Validate.That(parameterName, parameterValue)); "Testing that the parameter is false" .x(() => act = () => validatorBase.IsPositive().OtherwiseThrowException()); "Should throw an exception" .x(() => act.ShouldThrow <ArgumentOutOfRangeException>() .WithMessage(string.Format(Resources.MustBePositive + "\r\nParameter name: {0}", parameterName))); }
public static NullableNumericValidator <sbyte> That(string nameOfParameter, sbyte?parameterValue) { return(NullableNumericValidator <sbyte> .GetInstance(nameOfParameter, parameterValue)); }
public static NullableNumericValidator <float> That(string nameOfParameter, float?parameterValue) { return(NullableNumericValidator <float> .GetInstance(nameOfParameter, parameterValue)); }
public static NullableNumericValidator <decimal> That(string nameOfParameter, decimal?parameterValue) { return(NullableNumericValidator <decimal> .GetInstance(nameOfParameter, parameterValue)); }