public void EnsuresTest03()
        {
            ConditionValidator <int> ensuresValidator = Condition.Ensures(3);

            const string ValidCondition         = "valid condition";
            const string ValidAdditionalMessage = "valid additional message";
            const ConstraintViolationType InvalidConstraintViolationType = (ConstraintViolationType)666;

            const string AssertMessage = "EnsuresValidator.ThrowException should throw an " +
                                         "ArgumentException when an invalid ConstraintViolationType is supplied.";

            try
            {
                ensuresValidator.ThrowException(ValidCondition, ValidAdditionalMessage,
                                                InvalidConstraintViolationType);

                Assert.Fail(AssertMessage);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(PostconditionException), ex.GetType(), AssertMessage);

                Assert.IsTrue(ex.Message.Contains(ValidCondition),
                              "The exception message does not contain the condition.");
            }
        }
Beispiel #2
0
        public static ConditionValidator <T> MyExtension <T>(
            this ConditionValidator <T> validator, IEnumerable <T> collection)
        {
            if (collection == null || !collection.Contains(validator.Value))
            {
                validator.ThrowException(validator.ArgumentName + " should be in the supplied collection");
            }

            return(validator);
        }
        public void EnsuresTest03()
        {
            ConditionValidator <int> ensuresValidator = Condition.Ensures(3);

            const string ValidCondition         = "valid condition";
            const string ValidAdditionalMessage = "valid additional message";
            const ConstraintViolationType InvalidConstraintViolationType = (ConstraintViolationType)666;

            const string AssertMessage = "EnsuresValidator.ThrowException should throw an " +
                                         "ArgumentException when an invalid ConstraintViolationType is supplied.";

            Action action = () => ensuresValidator.ThrowException(ValidCondition, ValidAdditionalMessage,
                                                                  InvalidConstraintViolationType);

            action.Should().Throw <PostconditionException>(AssertMessage).Which.Message.Should().Contain(ValidCondition, "The exception message does not contain the condition.");
        }
        public void RequiresTest03()
        {
            ConditionValidator <int> requiresValidator = Condition.Requires(3);

            const string ValidCondition         = "valid condition";
            const string ValidAdditionalMessage = "valid additional message";
            const ConstraintViolationType InvalidConstraintViolationType = (ConstraintViolationType)666;

            const string AssertMessage = "RequiresValidator.ThrowException should throw an " +
                                         "ArgumentException when an invalid ConstraintViolationType is supplied.";

            try
            {
                requiresValidator.ThrowException(ValidCondition, ValidAdditionalMessage, InvalidConstraintViolationType);

                Assert.True(false, AssertMessage);
            }
            catch (Exception ex)
            {
                ex.GetType().ShouldBe(typeof(ArgumentException));
                ex.Message.ShouldContain(ValidCondition, "The exception message does not contain the condition.");
            }
        }