public void Handle_CustomerDoesNotExist_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.IndividualCustomer> > customerRepoMock, AddIndividualCustomerEmailAddressCommandHandler sut, string accountNumber ) { // Arrange var command = new AddIndividualCustomerEmailAddressCommand { AccountNumber = accountNumber, EmailAddress = EmailAddress.Create("*****@*****.**").Value }; customerRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetIndividualCustomerSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((Entities.IndividualCustomer)null); //Act Func <Task> func = async() => await sut.Handle(command, CancellationToken.None); //Assert func.Should().Throw <ArgumentNullException>() .WithMessage("Value cannot be null. (Parameter 'individualCustomer')"); }
public async Task Handle_CustomerExist_AddIndividualCustomerEmailAddress( [Frozen] Mock <IRepository <Entities.IndividualCustomer> > customerRepoMock, AddIndividualCustomerEmailAddressCommandHandler sut, Entities.Person person, string accountNumber ) { //Arrange var command = new AddIndividualCustomerEmailAddressCommand { AccountNumber = accountNumber, EmailAddress = EmailAddress.Create("*****@*****.**").Value }; //Act customerRepoMock.Setup(_ => _.GetBySpecAsync( It.IsAny <GetIndividualCustomerSpecification>(), It.IsAny <CancellationToken>() ) ) .ReturnsAsync(new Entities.IndividualCustomer(person)); var result = await sut.Handle(command, CancellationToken.None); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.UpdateAsync( It.IsAny <Entities.IndividualCustomer>(), It.IsAny <CancellationToken>() )); }