示例#1
0
        public void RunValidation(ExpectedValidationResult expectedValidationResult, String targetPropertyName, Object sut, String expectedMessage, Int32 expectedErrorsCount = 1)
        {
            // act
            var validationResult = _modelRulesInvoker.CheckAllValidationRulesForProperty(sut, targetPropertyName);

            // Assert
            if (expectedValidationResult == ExpectedValidationResult.Pass)
            {
                const Int32 ExpectedErrorsCount = 0;
                Assert.True(validationResult.IsValid, "Expect validation to pass.");
                Assert.True(ExpectedErrorsCount == validationResult.ValidationErrors.Count, "Unexpected number of validation errors.");
            }
            else
            {
                Assert.False(validationResult.IsValid, "Expect validation to fail.");
                Assert.True(expectedErrorsCount == validationResult.ValidationErrors.Count, "Unexpected number of validation errors.");
                Assert.True(expectedMessage == validationResult.ValidationErrors[0].Value.ErrorMessage, "Incorrect error message");
                Assert.True(targetPropertyName == validationResult.ValidationErrors[0].Key, "Incorrect member name");
            }
        }
示例#2
0
        public void WhenURLAndLocalHostPatternEnsureCorrectTestsResults(String targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.LocalHomePage = targetValue;
            const String TargetPropertyName = nameof(_sut.LocalHomePage);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#3
0
        public void WhenCustomPatternEnsureCorrectTestsResults(String targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.UKBankSortCode = targetValue;
            const String TargetPropertyName = nameof(_sut.UKBankSortCode);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#4
0
        public void WhenRuleSetIsProvidedEnsureCorrectTestsAreRun(String value, String ruleSet, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.ActiveRuleSet = ruleSet;
            _sut.LastName      = value;
            const String TargetPropertyName = nameof(_sut.LastName);

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, expectedMessage);
        }
示例#5
0
        public void WhenTargetIsSupposedToBeGreatThanEnsureCorrectTestsResults(Int32 targetValue, Int32 otherPropertyValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.Donation        = targetValue;
            _sut.DonationConfirm = otherPropertyValue;
            const String TargetPropertyName = nameof(_sut.Donation);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#6
0
        public void WhenTargetIsSupposedToBeNotEqualEnsureCorrectTestsResults(String targetValue, String otherPropertyValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.Password        = targetValue;
            _sut.PasswordConfirm = otherPropertyValue;
            const String TargetPropertyName = nameof(_sut.Password);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#7
0
        public void WhenValidatingVeryWeakPasswordEnsureCorrectTestsResults(String value, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.PasswordFour = value;
            const String TargetPropertyName = nameof(_sut.PasswordFour);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#8
0
        public void StringValueMustEqualEnsureCorrectTestsResults(String targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.EmailConfirm = targetValue;
            const String TargetPropertyName = nameof(_sut.EmailConfirm);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#9
0
        public void IntegerValueEnsureCorrectTestsResults(Int32 targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.Donation = targetValue;
            const String TargetPropertyName = nameof(_sut.Donation);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#10
0
        public void DoubleValueEnsureCorrectTestsResults(Double targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.NewStock = targetValue;
            const String TargetPropertyName = nameof(_sut.NewStock);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#11
0
        public void ConvertToTypeDecimalEnsureCorrectTestsResults(String targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.Cost = Convert.ToDecimal(targetValue);
            const String TargetPropertyName = nameof(_sut.Cost);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#12
0
        public void WhenStateAbbreviationRequiredNoEnsureCorrectTestsResults(String targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            _sut.StateNotRequired = targetValue;
            const String TargetPropertyName = nameof(_sut.StateNotRequired);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }
示例#13
0
        public void ConvertToTypeDateInclusiveEnsureCorrectTestsResults(String targetValue, String expectedMessage, ExpectedValidationResult expectedValidationResult)
        {
            // arrange
            if (targetValue == null)
            {
                _sut.HireDate = null;
            }
            else
            {
                _sut.HireDate = Convert.ToDateTime(targetValue);
            }
            const String TargetPropertyName = nameof(_sut.HireDate);
            String       ExpectedMessage    = expectedMessage;

            // act assert
            base.RunValidation(expectedValidationResult, TargetPropertyName, _sut, ExpectedMessage);
        }