public async void AddTourAsync_ValidTour_Success() { // Arrange var mock = new Mock <IUnitOfWork>(); mock.Setup(unitOfWork => unitOfWork.TourRepository.AddAsync(It.IsAny <TourEntity>())).Verifiable(); mock.Setup(unitOfWork => unitOfWork.CommitAsync()).Verifiable(); var tourService = new TourService(mock.Object); TourDto tour = new TourDto() { Name = "TourId", Price = 5 }; // Act await tourService.AddTourAsync(tour); // Assert mock.Verify(moq => moq.CommitAsync(), Times.Once); }
public async void AddTour_MemoryDb_ShouldBePresentInDb() { string tourName = "Tour1"; var options = new DbContextOptionsBuilder <ExploreDb>().UseInMemoryDatabase(databaseName: "Add_writes_to_database").Options; using (var context = new ExploreDb(options)) { var tourRepo = new TourRepository(context); var unit = new UnitOfWork(context, tourRepo, new ReservationRepository(context)); var tourService = new TourService(unit); var tour = new TourDto() { Name = tourName }; await tourService.AddTourAsync(tour); var result = await context.Tours.SingleAsync(); Assert.Equal(result.Name, tourName); } }