private Customer GetCustomer(CustomerRecord customerRecord) { var id = new CustomerIdentity(customerRecord.Id); var referenceNumber = CustomerReferenceNumber.Parse(customerRecord.ReferenceNumber); var firstName = customerRecord.FirstName; var lastName = customerRecord.LastName; return(new Customer(id, referenceNumber, firstName, lastName)); }
public async Task HandleAsync_Valid() { var customerRepositoryMock = new Mock <ICustomerRepository>(); var mapperMock = new Mock <IMapper>(); var id = Guid.Parse("926a4480-61f5-416a-a16f-5c722d8463f7"); var command = new EditCustomerCommand { Id = id, FirstName = "Mary 2", LastName = "Smith 2", }; var customerId = new CustomerIdentity(id); var referenceNumber = new CustomerReferenceNumber(DateTime.Now, "ABC12"); var customer = new Customer(customerId, referenceNumber, "Mary", "Smith"); var updatedCustomer = new Customer(customerId, referenceNumber, "Mary 2", "Smith 2"); var expectedResponse = new EditCustomerCommandResponse { Id = id, FirstName = "Mary 2", LastName = "Smith 2", }; customerRepositoryMock .Setup(e => e.FindAsync(customerId)) .ReturnsAsync(customer); customerRepositoryMock .Setup(e => e.UpdateAsync(updatedCustomer)); mapperMock .Setup(e => e.Map <Customer, EditCustomerCommandResponse>(updatedCustomer)) .Returns(expectedResponse); var handler = new EditCustomerCommandHandler(customerRepositoryMock.Object, mapperMock.Object); var response = await handler.HandleAsync(command); customerRepositoryMock.Verify(e => e.FindAsync(customerId), Times.Once()); customerRepositoryMock.Verify(e => e.UpdateAsync(updatedCustomer), Times.Once()); mapperMock.Verify(e => e.Map <Customer, EditCustomerCommandResponse>(customer), Times.Once()); response.Should().BeEquivalentTo(expectedResponse); }
public async Task HandleAsync_Valid() { var applicationUserContextMock = new Mock <IApplicationUserContext>(); var customerFactoryMock = new Mock <ICustomerFactory>(); var customerRepositoryMock = new Mock <ICustomerRepository>(); var mapperMock = new Mock <IMapper>(); var command = new CreateCustomerCommand { FirstName = "Mary", LastName = "Smith", }; var id = Guid.Parse("926a4480-61f5-416a-a16f-5c722d8463f7"); var referenceNumber = new CustomerReferenceNumber(DateTime.Now, "ABC12"); var customer = new Customer(new CustomerIdentity(id), referenceNumber, "Mary", "Smith");; var expectedResponse = new CreateCustomerCommandResponse { Id = id, FirstName = "Mary", LastName = "Smith", }; customerFactoryMock .Setup(e => e.CreateCustomer("Mary", "Smith")) .Returns(customer); customerRepositoryMock .Setup(e => e.AddAsync(customer)); mapperMock .Setup(e => e.Map <Customer, CreateCustomerCommandResponse>(customer)) .Returns(expectedResponse); var handler = new CreateCustomerCommandHandler(applicationUserContextMock.Object, customerFactoryMock.Object, customerRepositoryMock.Object, mapperMock.Object); var response = await handler.HandleAsync(command); customerFactoryMock.Verify(e => e.CreateCustomer("Mary", "Smith"), Times.Once()); customerRepositoryMock.Verify(e => e.AddAsync(customer), Times.Once()); mapperMock.Verify(e => e.Map <Customer, CreateCustomerCommandResponse>(customer), Times.Once()); response.Should().BeEquivalentTo(expectedResponse); }