public override async Task DeleteWithIdThatDoesntExistThrowsExceptionAsync() { int id = 1000; // arrange (use the context directly - we assume that works) var options = new DbContextOptionsBuilder <Project15Context>() .UseInMemoryDatabase("db_reservation_test_deleteWithNotId").Options; using (var db = new Project15Context(options)); // assert (for assert, once again use the context directly for verify.) using (var db = new Project15Context(options)) { var repo = new ReservationRepository(db); Reservation reservation = await repo.GetByIdAsync(id); Assert.Null(reservation); await Assert.ThrowsAsync <ArgumentException>(() => repo.DeleteAsync(id)); } }
public async Task DeleteReservation_ReservationExisting_ReservationDeleted() { var reservation = new Reservation { Id = 11, CheckIn = checkInDate, CheckOut = checkOutDate, GuestId = thirdGuest, RoomId = secondRoom, TotalPrice = pricePerNight }; await reservationRepository.AddAsync(reservation); await reservationRepository.DeleteAsync(reservation); var reservationCount = await reservationRepository .CountAsync(new GuestReservationSpecification(thirdGuest)); Assert.That(reservationCount, Is.EqualTo(1)); }
public async Task <Reservation> Handle(DeleteReservationCommand request, CancellationToken cancellationToken) { return(await _repository.DeleteAsync(request.Id)); }
public override async Task DeleteWorksAsync() { int id = 0; Reservation reservationSaved = null; Customer customerSaved = null; Room roomSaved = null; var options = new DbContextOptionsBuilder <Project15Context>() .UseInMemoryDatabase("db_reservation_test_delete").Options; using (var db = new Project15Context(options)); // act (for act, only use the repo, to test it) using (var db = new Project15Context(options)) { var repo = new ReservationRepository(db); var customerRepo = new CustomerRepository(db); var roomRepo = new RoomRepository(db); //Create customer Customer customer = new Customer { Name = "Axel", Address1 = "111 Address" }; customer = await customerRepo.CreateAsync(customer); await customerRepo.SaveChangesAsync(); // Create room Room room = new Room { Beds = 1, Cost = 50, RoomType = "Standard" }; room = await roomRepo.CreateAsync(room); await roomRepo.SaveChangesAsync(); // Create reservation Reservation eventCustomer = new Reservation { CustomerId = customer.Id, RoomId = room.Id, Paid = true }; reservationSaved = await repo.CreateAsync(eventCustomer); await repo.SaveChangesAsync(); customerSaved = customer; roomSaved = room; id = reservationSaved.Id; } using (var db = new Project15Context(options)) { var repo = new ReservationRepository(db); Reservation reservation = await repo.GetByIdAsync(id); Assert.NotEqual(0, reservation.Id); Assert.Equal(customerSaved.Id, reservation.CustomerId); Assert.Equal(roomSaved.Id, reservation.RoomId); Assert.True(reservation.Paid); await repo.DeleteAsync(id); await repo.SaveChangesAsync(); reservation = await repo.GetByIdAsync(id); Assert.Null(reservation); } }