Exemplo n.º 1
0
        public void Constructor_WithArguments_ExpectedValues()
        {
            // Setup
            const string parameterName = "ParameterName";

            var    random     = new Random(21);
            double lowerLimit = random.NextDouble();
            double value      = random.NextDouble();

            // Call
            var rule = new ComparableParameterGreaterOrEqualToRule <double>(parameterName, value, lowerLimit);

            // Assert
            Assert.That(rule, Is.InstanceOf <ParameterRuleBase>());
        }
Exemplo n.º 2
0
        public void Execute_WithValuesSatisfyingLimit_ReturnsValidResult(double offset)
        {
            // Setup
            const string parameterName = "ParameterName";

            var    random     = new Random(21);
            double lowerLimit = random.NextDouble();
            double value      = lowerLimit + offset;

            var rule = new ComparableParameterGreaterOrEqualToRule <double>(parameterName, value, lowerLimit);

            // Precondition
            Assert.That(lowerLimit.CompareTo(value), Is.LessThanOrEqualTo(0));

            // Call
            ValidationRuleResult result = rule.Execute();

            // Assert
            Assert.That(result, Is.SameAs(ValidationRuleResult.ValidResult));
        }
Exemplo n.º 3
0
        public void Execute_WithValuesNotSatisfyingLimit_ReturnsInvalidResult(double offset)
        {
            // Setup
            const string parameterName = "ParameterName";

            var    random       = new Random(21);
            double lowerLimit   = random.NextDouble();
            double invalidValue = lowerLimit + offset;

            var rule = new ComparableParameterGreaterOrEqualToRule <double>(parameterName, invalidValue, lowerLimit);

            // Precondition
            Assert.That(lowerLimit.CompareTo(invalidValue), Is.GreaterThan(0));

            // Call
            ValidationRuleResult result = rule.Execute();

            // Assert
            Assert.That(result.IsValid, Is.False);
            var expectedMessage = $"{parameterName} must be >= {lowerLimit}. Current value: {invalidValue}";

            Assert.That(result.ValidationMessage, Is.EqualTo(expectedMessage));
        }