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(); }
public void ShouldBeEmptyIfDefaultConstructor() { // Act var collection = new FluentValidatorCollection <Person>(); // Assert collection.Count.ShouldBe(0); }
public void ShouldAddSingleItem() { // Arrange var objectToAdd = new PersonValidator(); // Act var collection = new FluentValidatorCollection <Person> { objectToAdd }; // Assert collection.ShouldContain(objectToAdd); }
public void ShouldBeDirtyOnceValidated() { // Arrange var value = new Person(); var collection = new FluentValidatorCollection <Person> { new PersonValidator() }; // Act collection.Validate(value); // Assert collection.IsDirty.ShouldBe(true); }
public void ShouldContainItemsIfInitializedAsEnumerable() { // Arrange IEnumerable <AbstractValidator <Person> > validators = new List <AbstractValidator <Person> > { new PersonValidator() }; // Act var collection = new FluentValidatorCollection <Person>(validators); // Assert collection.Count.ShouldBe(validators.Count()); collection.ToList().ShouldBeEquivalentTo(validators); }
public void ShouldBeInvalidIfInvalidValue() { // Arrange var value = new Person(); var collection = new FluentValidatorCollection <Person> { new PersonValidator() }; // Act collection.Validate(value); // Assert collection.IsInvalid.ShouldBe(true); }
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); }
public void ShouldAddRangeOfItems() { // Arrange IEnumerable <AbstractValidator <Person> > validators = new List <AbstractValidator <Person> > { new PersonValidator() }; var collection = new FluentValidatorCollection <Person>(); // Act collection.AddRange(validators); // Assert foreach (AbstractValidator <Person> item in validators) { collection.ShouldContain(item); } }
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); }