public void GivenWhenValidatorConstructing_ThenRulesForCanUseCouponAreConfiguredCorrectly()
 {
     // Assert
     _validator.ShouldHaveRules(x => x.CanUseCoupon, BaseVerifiersSetComposer.Build()
                                .AddPropertyValidatorVerifier <NotNullValidator>()
                                .Create());
 }
Ejemplo n.º 2
0
 public void Given_Name_IsEmpty_When_Validating_Then_Error()
 {
     // Assert
     _validator.ShouldHaveRules(x => x.Name, BaseVerifiersSetComposer.Build()
                                .AddPropertyValidatorVerifier <NotEmptyValidator>()
                                .Create());
 }
 public void GivenWhenValidatorConstructing_ThenRulesForClientReferenceAreConfiguredCorrectly()
 {
     // Assert
     _validator.ShouldHaveRules(x => x.ClientReference, BaseVerifiersSetComposer.Build()
                                .AddPropertyValidatorVerifier <NotEmptyValidator>()
                                .Create());
 }
Ejemplo n.º 4
0
 public void Given_When_PersonValidatorConstructing_Then_RulesForWeightAreConfiguredCorrectly()
 {
     // Assert
     this.personValidator.ShouldHaveRules(x => x.Weight,
                                          BaseVerifiersSetComposer.Build()
                                          .AddScalePrecisionValidatorVerifier(2, 4)
                                          .Create());
 }
Ejemplo n.º 5
0
 public void Given_When_PersonValidatorConstructing_Then_RulesForHeightInMetersValidatorAreConfiguredCorrectly()
 {
     // Assert
     this.personValidator.ShouldHaveRules(x => x.HeightInMeters,
                                          BaseVerifiersSetComposer.Build()
                                          .AddBetweenValidatorVerifier <InclusiveBetweenValidator>(0.0, 2.5)
                                          .Create());
 }
Ejemplo n.º 6
0
 public void Given_When_PersonValidatorConstructing_Then_RulesForFavouriteDayAreConfiguredCorrectly()
 {
     // Assert
     this.personValidator.ShouldHaveRules(x => x.FavouriteDay,
                                          BaseVerifiersSetComposer.Build()
                                          .AddEnumValidatorVerifier(typeof(DayOfWeek))
                                          .Create());
 }
 public void GivenWhenValidatorConstructing_ThenRulesForUserNameAreConfiguredCorrectly()
 {
     // Assert
     _validator.ShouldHaveRules(x => x.UserName, BaseVerifiersSetComposer.Build()
                                .AddPropertyValidatorVerifier <NotEmptyValidator>()
                                .AddPropertyValidatorVerifier <RegularExpressionValidator>(@"\A\S+\z")
                                .Create());
 }
Ejemplo n.º 8
0
 public void Given_When_PersonValidatorConstructing_Then_RulesForEmailAreConfiguredCorrectly()
 {
     // Assert
     this.personValidator.ShouldHaveRules(x => x.Email,
                                          BaseVerifiersSetComposer.Build()
                                          .AddPropertyValidatorVerifier <RegularExpressionValidator>("^[_a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$")
                                          .Create());
 }
 public void Given_Password_IsEmpty_When_Validating_Then_Error()
 {
     // Assert
     _validator.ShouldHaveRules(x => x.Password, BaseVerifiersSetComposer.Build()
                                .AddPropertyValidatorVerifier <NotEmptyValidator>()
                                .AddPropertyValidatorVerifier <MinimumLengthValidator>()
                                .Create());
 }
Ejemplo n.º 10
0
 public void Given_When_PersonValidatorConstructing_Then_RulesForAddressValidatorAreConfiguredCorrectly()
 {
     // Assert
     this.personValidator.ShouldHaveRules(x => x.Address,
                                          BaseVerifiersSetComposer.Build()
                                          .AddChildValidatorVerifier <AddressValidator, Person, Address>()
                                          .Create());
 }
Ejemplo n.º 11
0
        public void Given_When_BuildNewRuleSet_Then_NoVerifiersInList()
        {
            // Act
            var composer = BaseVerifiersSetComposer.Build();

            // Assert
            Assert.Empty(composer.Create());
        }
Ejemplo n.º 12
0
 public void Given_When_PersonValidatorConstructing_Then_RulesForHeightAreConfiguredCorrectly()
 {
     // Assert
     this.personValidator.ShouldHaveRules(x => x.HeightInCentimeters,
                                          BaseVerifiersSetComposer.Build()
                                          .AddPropertyValidatorVerifier <GreaterThanValidator>(0)
                                          .AddPropertyValidatorVerifier <LessThanOrEqualValidator>(250)
                                          .Create());
 }
Ejemplo n.º 13
0
 public void Given_When_PersonValidatorConstructing_Then_RulesForLastNameAreConfiguredCorrectly()
 {
     // Assert
     this.personValidator.ShouldHaveRules(x => x.LastName,
                                          BaseVerifiersSetComposer.Build()
                                          .AddPropertyValidatorVerifier <NotNullValidator>()
                                          .AddPropertyValidatorVerifier <NotEmptyValidator>()
                                          .AddPropertyValidatorVerifier <LengthValidator>(0, 20)
                                          .Create());
 }
Ejemplo n.º 14
0
        public void Given_Composer_When_AddingPropertyValidatorVerifier_Then_CorrectRuleSet()
        {
            // Arrange
            var composer = BaseVerifiersSetComposer.Build();

            // Act
            var rules = composer.AddPropertyValidatorVerifier <FakePropertyValidator>().Create();

            // Assert
            Assert.Equal(new[] { typeof(TypeValidatorVerifier <FakePropertyValidator>) }, rules.Select(x => x.GetType()).ToArray());
        }
Ejemplo n.º 15
0
        public void Given_Composer_When_AddingCollectionValidatorVerifier_Then_CorrectRuleSet()
        {
            // Arrange
            var composer = BaseVerifiersSetComposer.Build();

            // Act
            var rules = composer.AddChildCollectionValidatorVerifier <int>().Create();

            // Assert
            Assert.Equal(new[] { typeof(ChildCollectionValidatorVerifier <int>) }, rules.Select(x => x.GetType()).ToArray());
        }
Ejemplo n.º 16
0
        public void Given_Composer_When_AddingPlaceholderVerifier_Then_CorrectRuleSet()
        {
            // Arrange
            var composer = BaseVerifiersSetComposer.Build();

            // Act
            var rules = composer.AddPlaceholderVerifier().Create();

            // Assert
            Assert.Equal(new[] { typeof(PlaceholderVerifier) }, rules.Select(x => x.GetType()).ToArray());
        }
Ejemplo n.º 17
0
        public void Given_Composer_When_AddingAnyValidatorVerifier_Then_CorrectRuleSet()
        {
            // Arrange
            var composer = BaseVerifiersSetComposer.Build();
            var fakeValidatorVerifier = new FakeValidatorVerifier();

            // Act
            var rules = composer.AddVerifier(fakeValidatorVerifier).Create();

            // Assert
            Assert.Equal(new IValidatorVerifier[] { fakeValidatorVerifier }, rules.ToArray());
        }
Ejemplo n.º 18
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));
        }
Ejemplo n.º 19
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.º 20
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));
        }
        public void CreateTodoItemValidator_HasCorrectValidators()
        {
            // Arrange
            var sut = new CreateTodoItemValidator();

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

            // Assert
        }
Ejemplo n.º 22
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.º 23
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.º 24
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));
        }
Ejemplo n.º 25
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));
        }