public async Task Add_CorrectData_RentalCreated() { var repository = MockRentalsRepository(); var service = new RentalsService(repository.Object); var rental = new Rental { Id = 1, BookId = 1, CustomerId = Guid.NewGuid(), StartDate = new DateTime(2012, 12, 12) }; await service.Add(rental); repository.Verify(repository => repository.Add(rental), Times.AtLeastOnce); }
public async Task Add_InvalidData_ExceptionThrown(int id, int bookId, Guid customerId, DateTime startDate, DateTime endDate) { var repository = MockRentalsRepository(); var service = new RentalsService(repository.Object); var rental = new Rental { BookId = bookId, CustomerId = customerId, Id = id, StartDate = startDate, EndDate = endDate }; try { await service.Add(rental); } catch (ArgumentException) { Assert.Pass(); } Assert.Fail(); }