Ejemplo n.º 1
0
        public void Given_Composer_When_AddEnumValidatorVerifierNotGeneric_Then_CorrectRuleSet()
        {
            // Arrange
            var composer      = BaseVerifiersSetComposer.Build();
            var enumValidator = new EnumValidator(typeof(FakeEnum));

            // Act
            var rules = composer.AddEnumValidatorVerifier(typeof(FakeEnum)).Create();

            // Assert
            Assert.Equal(new[] { typeof(EnumValidatorVerifier <EnumValidator>) }, rules.Select(x => x.GetType()).ToArray());
            AssertExtension.NotThrows(() => rules[0].Verify(enumValidator));
        }
Ejemplo n.º 2
0
        public void Given_Composer_When_AddScalePrecisionValidatorVerifierGeneric_Then_CorrectRuleSet()
        {
            // Arrange
            var composer = BaseVerifiersSetComposer.Build();
            var scalePrecisionValidator = new ScalePrecisionValidator(1, 2);

            // Act
            var rules = composer.AddScalePrecisionValidatorVerifier <ScalePrecisionValidator>(1, 2).Create();

            // Assert
            Assert.Equal(new[] { typeof(ScalePrecisionValidatorVerifier <ScalePrecisionValidator>) }, rules.Select(x => x.GetType()).ToArray());
            AssertExtension.NotThrows(() => rules[0].Verify(scalePrecisionValidator));
        }
        public void CreateTodoItemValidator_HasCorrectValidators()
        {
            // Arrange
            var sut = new CreateTodoItemValidator();

            // Act & Assert
            sut.ShouldHaveRules(x => x.Description,
                                BaseVerifiersSetComposer.Build()
                                .AddPropertyValidatorVerifier <NotEmptyValidator>()
                                .Create());

            // Assert
        }
Ejemplo n.º 4
0
        public void Given_Composer_When_AddMinimumLenghtValidatorVerifierGeneric_Then_CorrectRuleSet()
        {
            // Arrange
            var composer             = BaseVerifiersSetComposer.Build();
            var exactLengthValidator = new MinimumLengthValidator(10);

            // Act
            var rules = composer.AddMinimumLengthValidatorVerifier(10).Create();

            // Assert
            Assert.Equal(new[] { typeof(MinimumLengthValidatorVerifier) }, rules.Select(x => x.GetType()).ToArray());
            AssertExtension.NotThrows(() => rules[0].Verify(exactLengthValidator));
        }
Ejemplo n.º 5
0
        public void Given_Composer_When_AddingPropertyValidatorVerifierWithExpression_Then_CorrectRuleSet()
        {
            // Arrange
            var composer = BaseVerifiersSetComposer.Build();
            var regularExpressionValidator = new FakeRegularExpressionValidator {
                Expression = "regex"
            };

            // Act
            var rules = composer.AddPropertyValidatorVerifier <FakeRegularExpressionValidator>("regex").Create();

            // Assert
            Assert.Equal(new[] { typeof(RegularExpressionValidatorVerifier <FakeRegularExpressionValidator>) }, rules.Select(x => x.GetType()).ToArray());
            AssertExtension.NotThrows(() => rules[0].Verify(regularExpressionValidator));
        }
Ejemplo n.º 6
0
        public void Given_Composer_When_AddingPropertyValidatorVerifierWithRange_Then_CorrectRuleSet()
        {
            // Arrange
            var composer            = BaseVerifiersSetComposer.Build();
            var fakeLengthValidator = new FakeLengthValidator {
                Min = 1, Max = 10
            };

            // Act
            var rules = composer.AddPropertyValidatorVerifier <FakeLengthValidator>(1, 10).Create();

            // Assert
            Assert.Equal(new[] { typeof(LengthValidatorVerifier <FakeLengthValidator>) }, rules.Select(x => x.GetType()).ToArray());
            AssertExtension.NotThrows(() => rules[0].Verify(fakeLengthValidator));
        }
Ejemplo n.º 7
0
        public void Given_Composer_When_AddingPropertyValidatorVerifierWithObjectToCompare_Then_CorrectRuleSet()
        {
            // Arrange
            var composer = BaseVerifiersSetComposer.Build();
            var fakeComparisonValidator = new FakeComparisonValidator {
                ValueToCompare = 10, Comparison = Comparison.Equal
            };

            // Act
            var rules = composer.AddPropertyValidatorVerifier <FakeComparisonValidator>(10, Comparison.Equal).Create();

            // Assert
            Assert.Equal(new[] { typeof(ComparisonValidatorVerifier <FakeComparisonValidator>) }, rules.Select(x => x.GetType()).ToArray());
            AssertExtension.NotThrows(() => rules[0].Verify(fakeComparisonValidator));
        }
Ejemplo n.º 8
0
        public void Given_Composer_When_AddBetweenValidatorVerifierGeneric_Then_CorrectRuleSet()
        {
            // Arrange
            var composer         = BaseVerifiersSetComposer.Build();
            var betweenValidator = new FakeBetweenValidator {
                From = 1, To = 2
            };

            // Act
            var rules = composer.AddBetweenValidatorVerifier <FakeBetweenValidator>(1, 2).Create();

            // Assert
            Assert.Equal(new[] { typeof(BetweenValidatorVerifier <FakeBetweenValidator>) }, rules.Select(x => x.GetType()).ToArray());
            AssertExtension.NotThrows(() => rules[0].Verify(betweenValidator));
        }