public void ThenAnExceptionIsThrownIfTheCommandIsInvalid() { //Arrange _validator.Setup(x => x.Validate(It.IsAny <UpsertRegisteredUserCommand>())) .Returns(new ValidationResult( new List <ValidationFailure> { new ValidationFailure("TEST", "ERROR") } )); var command = new UpsertRegisteredUserCommand(); //Act & Assert Assert.ThrowsAsync <ValidationException>(() => _handler.Handle(command, new CancellationToken())); }
public void ThenDisplayNameIsMandatory() { //Arrange var command = new UpsertRegisteredUserCommand { UserRef = "UserRef", Email = "Email", Ukprn = 12345 }; //Act var result = _validator.Validate(command); //Assert Assert.IsFalse(result.IsValid); Assert.IsTrue(result.Errors.Any(x => x.PropertyName.Contains(nameof(UpsertRegisteredUserCommand.DisplayName)))); }
public void ThenCommandIsValidIfAllFieldsAreProvided() { //Arrange var command = new UpsertRegisteredUserCommand { UserRef = "UserRef", DisplayName = "Displayname", Email = "Email", Ukprn = 12345 }; //Act var result = _validator.Validate(command); //Assert Assert.IsTrue(result.IsValid); }
public void Arrange() { _validator = new Mock <IValidator <UpsertRegisteredUserCommand> >(); _validator.Setup(v => v.Validate(It.IsAny <UpsertRegisteredUserCommand>())) .Returns(new ValidationResult()); _userRepository = new Mock <IUserRepository>(); _handler = new UpsertRegisteredUserCommandHandler(_validator.Object, _userRepository.Object); _command = new UpsertRegisteredUserCommand { UserRef = Guid.NewGuid().ToString(), FirstName = "User", LastName = "One", EmailAddress = "*****@*****.**" }; }
public async Task ThenTheRepositoryIsCalledToUpsertRegisteredUser() { //Arrange var command = new UpsertRegisteredUserCommand { UserRef = "UserRef", DisplayName = "DisplayName", Email = "Email", Ukprn = 12345 }; //Act await _handler.Handle(command, new CancellationToken()); //Assert _repository.Verify(x => x.Upsert( It.Is <User>( user => user.UserRef == command.UserRef && user.DisplayName == command.DisplayName && user.Email == command.Email && user.Ukprn == command.Ukprn )), Times.Once); }