Exemple #1
0
            public void ShouldValidateComplexObjectWithMultipleValidators()
            {
                // Arrange
                var value = new Staff
                {
                    Name        = "Joe Bloggs",
                    JobTitle    = null,                      // Invalid job title
                    Department  = "Build",
                    DateOfBirth = DateTime.UtcNow.AddDays(1) // Invalid birth date
                };

                var collection = new FluentValidatorCollection <Person> {
                    new PersonValidator(), new StaffValidator()
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.FeedbackMessages.ShouldNotBeEmpty();
                collection.FeedbackMessages.Count().ShouldBe(2);
                collection.FeedbackMessages.FirstOrDefault(x => x.Equals(PersonValidator.DateOfBirthValidationMessage,
                                                                         StringComparison.InvariantCultureIgnoreCase)).ShouldNotBeNull();
                collection.FeedbackMessages.FirstOrDefault(x => x.Equals(StaffValidator.JobTitleValidationMessage,
                                                                         StringComparison.InvariantCultureIgnoreCase)).ShouldNotBeNull();
            }
Exemple #2
0
            public void ShouldBeDirtyOnceValidated()
            {
                // Arrange
                var value = new Person();

                var collection = new FluentValidatorCollection <Person> {
                    new PersonValidator()
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.IsDirty.ShouldBe(true);
            }
Exemple #3
0
            public void ShouldBeInvalidIfInvalidValue()
            {
                // Arrange
                var value = new Person();

                var collection = new FluentValidatorCollection <Person> {
                    new PersonValidator()
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.IsInvalid.ShouldBe(true);
            }
Exemple #4
0
            public void ShouldBeValidIfValidValue()
            {
                // Arrange
                var value = new Person {
                    Name = "Joe Bloggs", DateOfBirth = new DateTime(1992, 01, 01)
                };

                var collection = new FluentValidatorCollection <Person> {
                    new PersonValidator()
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.IsInvalid.ShouldBe(false);
            }
Exemple #5
0
            public void ShouldHaveFeedbackMessagesIfInvalidValue()
            {
                // Arrange
                var value = new Person
                {
                    Name        = "Joe Bloggs",
                    DateOfBirth = DateTime.UtcNow.AddDays(1) // Invalid birth date
                };

                var collection = new FluentValidatorCollection <Person> {
                    new PersonValidator()
                };

                // Act
                collection.Validate(value);

                // Assert
                collection.FeedbackMessages.ShouldNotBeEmpty();
                collection.FeedbackMessages.Count().ShouldBe(1);
                collection.FeedbackMessages.FirstOrDefault().ShouldBe(PersonValidator.DateOfBirthValidationMessage);
            }