public void WhenAllPropertiesAreValid() { // Arrange var dbContextStub = _Fixture.CreateUserContextStub(); var validator = new UserAddValidator(dbContextStub); // Act var errors = validator.ValidateAdd(_TestUser); // Assert Assert.Empty(errors); }
public void WhenUserWithTheSameEmailExists() { // Arrange var dbContextStub = _Fixture.CreateUserContextStub(_TestUser); var validator = new UserAddValidator(dbContextStub); // Act var errors = validator.ValidateAdd(_TestUser); // Assert Assert.True(errors.Any(e => e.Contains("email address already exists"))); }
/// <summary> /// Sets the specified property to the specified value and tests that validation /// fails /// </summary> /// <param name="propertyToTest">The property to test</param> /// <param name="propertyValue">The property value to test with</param> private void ValidationFailsForPropertyWithValue(Expression <Func <UserServiceUser, string> > propertyToTest, string propertyValue) { // Arrange var propertyName = GetPropertyNameFromExpression(propertyToTest); var user = GetUserFromExpression(propertyToTest); var dbContextStub = _Fixture.CreateUserContextStub(); var validator = new UserAddValidator(dbContextStub); // Act SetPropertyValue(user, propertyName, propertyValue); var errors = validator.ValidateAdd(user); // Assert var expectedError = string.Format("{0} property is required", propertyName.ToLower()); Assert.True(errors.Any(e => e.ToLower().Contains(expectedError))); }