public async Task GivenExistingBooking_WhenDeleted_SubTablesShouldBeCleared() { var source = BookingRepositoryTest.GetSimpleBookingForTest(); source.Products.Add(BookingRepositoryTest.GetProductForTest()); var repository = BookingRepositoryTest.GetBookingRepositoryForTest(); var cruise = await CruiseRepositoryTest.GetCruiseForTestAsync(); var result = await repository.CreateAsync(cruise, source); var booking = await repository.FindByReferenceAsync(result.Reference); var paymentRepository = AecPaymentRepositoryTest.GetPaymentRepositoryForTest(); await paymentRepository.CreateAsync(booking, 123.45m); await repository.DeleteAsync(booking); // The booking now has cabins, pax, products and a payment // If we add more data in subtables remember to add and check for it here // All relevant tables should be empty now using (var db = DbUtil.Open()) { Assert.AreEqual(0, db.ExecuteScalar <int>("select count(*) from [Booking]")); Assert.AreEqual(0, db.ExecuteScalar <int>("select count(*) from [BookingCabin]")); Assert.AreEqual(0, db.ExecuteScalar <int>("select count(*) from [BookingPax]")); Assert.AreEqual(0, db.ExecuteScalar <int>("select count(*) from [BookingPayment]")); Assert.AreEqual(0, db.ExecuteScalar <int>("select count(*) from [BookingProduct]")); } }
public async Task GivenExistingBooking_WhenDeleted_ShouldLeaveRecordInDeletedBookings() { var repository = BookingRepositoryTest.GetBookingRepositoryForTest(); var cruise = await CruiseRepositoryTest.GetCruiseForTestAsync(); var booking = await BookingRepositoryTest.GetNewlyCreatedBookingForTestAsync(cruise, repository); var paymentRepository = AecPaymentRepositoryTest.GetPaymentRepositoryForTest(); const decimal amountPaid = 10m; await paymentRepository.CreateAsync(booking, amountPaid); await repository.DeleteAsync(booking); var deletedBookingRepository = GetDeletedBookingRepositoryForTest(); var deleted = (await deletedBookingRepository.FindByReferenceAsync(booking.Reference)).FirstOrDefault(); Assert.IsNotNull(deleted); Assert.AreEqual(booking.CruiseId, deleted.CruiseId); Assert.AreEqual(booking.Reference, deleted.Reference); Assert.AreEqual(booking.FirstName, deleted.FirstName); Assert.AreEqual(booking.LastName, deleted.LastName); Assert.AreEqual(booking.Email, deleted.Email); Assert.AreEqual(booking.PhoneNo, deleted.PhoneNo); Assert.AreEqual(booking.TotalPrice, deleted.TotalPrice); Assert.AreEqual(amountPaid, deleted.AmountPaid); }
public async Task GivenExistingBooking_WhenDeleted_ShouldCeaseToExist() { var repository = BookingRepositoryTest.GetBookingRepositoryForTest(); var cruise = await CruiseRepositoryTest.GetCruiseForTestAsync(); var booking = await BookingRepositoryTest.GetNewlyCreatedBookingForTestAsync(cruise, repository); Assert.AreNotEqual(Guid.Empty, booking.Id); await repository.DeleteAsync(booking); var deletedBooking = await repository.FindByReferenceAsync(booking.Reference); Assert.IsNull(deletedBooking); deletedBooking = await repository.FindByIdAsync(booking.Id); Assert.IsNull(deletedBooking); }
public async Task GivenBooking_WhenPaymentsRegistered_ShouldCalculateCorrectSummary() { var booking = await BookingRepositoryTest.GetNewlyCreatedBookingForTestAsync(); var repository = GetPaymentRepositoryForTest(); decimal amount1 = 409.27m, amount2 = 15000m, amount3 = -927.44m; await repository.CreateAsync(booking, amount1); await repository.CreateAsync(booking, amount2); await repository.CreateAsync(booking, amount3); PaymentSummary summary = await repository.GetSumOfPaymentsByBookingAsync(booking); Assert.AreEqual(amount1 + amount2 + amount3, summary.Total); Assert.AreNotEqual(DateTime.MinValue, summary.Latest); }