public async Task ShouldConfirmBookingIfPayedInFull() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); Assert.True(result.Success); Assert.Equal(1, result.Id); Assert.Empty(result.ValidationErrors); booking = await bookingService.GetBooking(result.Id.Value); Assert.False(string.IsNullOrEmpty(booking.ReferenceNumber)); booking.AddPayment(100); booking.AddPayment(200); result = await bookingService.UpdateBooking("tester", booking); Assert.True(result.Success); Assert.Empty(result.ValidationErrors); booking = await bookingService.GetBooking(booking.ReferenceNumber); Assert.Equal(BookingStatus.Confirmed, booking.Status); }
public async Task ShouldReturnPayments() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var paymentService = new StripePaymentService(dbContext); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); booking.Id = result.Id.Value; booking.AddPayment(100); booking.AddPayment(200); await bookingService.UpdateBooking("tester", booking); var payments = await paymentService.GetPayments(); Assert.NotEmpty(payments); Assert.Equal(2, payments.Count); }
public async Task ShouldNotBeAllowedToUpdateConfirmedBooking() { using var connection = new SqliteConnection("Filename=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DiallogDbContext>() .UseSqlite(connection) .Options; using var dbContext = new DiallogDbContext(options); dbContext.Database.EnsureCreated(); var bookingService = new BookingService(dbContext); var booking = new Booking { GuestUserId = "XXXXXX", GuestName = "XXXXXX", Car = new Car { DailyRentalCost = 100, GasConsumption = "XXXXX", NumberOfUnits = 3 }, StartDateUtc = DateTime.UtcNow, EndDateUtc = DateTime.UtcNow.AddDays(3) }; var result = await bookingService.AddBooking(booking); Assert.True(result.Success); Assert.Equal(1, result.Id); Assert.Empty(result.ValidationErrors); booking.Id = result.Id.Value; booking.AddPayment(300); result = await bookingService.UpdateBooking("tester", booking); Assert.True(result.Success); Assert.Empty(result.ValidationErrors); booking.StartDateUtc = DateTime.UtcNow.AddDays(1); result = await bookingService.UpdateBooking("tester", booking); Assert.False(result.Success); Assert.NotEmpty(result.ValidationErrors); Assert.Equal("Updating of confirmed or cancelled booking is not allowed", result.ValidationErrors["Booking"]); }