public void Handler_ShouldWork(string name, string driverLicense, string dob, string street, string city, string zipcode, string email, string phone) { var customerRepository = A.Fake <ICustomerRepository>(); var uow = A.Fake <IUnitOfWork>(); var command = new CreateCustomerCommand(name, driverLicense, DateTime.Parse(dob), street, city, zipcode, email, phone); var handler = new CreateCustomerCommand.Handler(customerRepository, uow, APITestsHelper.GetMapper()); var result = handler.Handle(command, new CancellationToken()).Result; A.CallTo(() => customerRepository.Add(A <Customer> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => uow.CommitAsync(A <CancellationToken> ._)).MustHaveHappenedOnceExactly(); Assert.Equal(name, result.Name); Assert.Equal(driverLicense, result.DriverLicense); Assert.Equal(DateTime.Parse(dob), result.DOB); Assert.Equal(street, result.Street); Assert.Equal(city, result.City); Assert.Equal(zipcode, result.ZipCode); Assert.Equal(email, result.Email); Assert.Equal(phone, result.Phone); }
public void Handler_ShouldWork(string make, string model, string registration, int year, int odometer) { var carRepositoryMock = new Mock <ICarRepository>(); var uowMock = new Mock <IUnitOfWork>(); var handler = new CreateCarCommand.Handler(carRepositoryMock.Object, uowMock.Object, APITestsHelper.GetMapper()); var createCarCommand = new CreateCarCommand(model, make, registration, odometer, year); var result = handler.Handle(createCarCommand, new CancellationToken()).Result; carRepositoryMock.Verify(t => t.Add(It.IsAny <Car>()), Times.Once); uowMock.Verify(t => t.CommitAsync(It.IsAny <CancellationToken>()), Times.Once); Assert.Equal(make, result.Make); Assert.Equal(model, result.Model); Assert.Equal(registration, result.Registration); Assert.Equal(year, result.Year); Assert.Equal(odometer, result.Odometer); }