From 52427b5f4fd8bd53e9ad0eb12ed22000fc58e0a8 Mon Sep 17 00:00:00 2001 From: Mykyta-Panchenko Date: Fri, 7 Feb 2025 12:06:49 +0200 Subject: [PATCH] Refactored BookingShould.cs Description: Extracted CreateBooking() helper method to remove redundant object instantiation. Allowed passing custom start and end dates for more flexible test cases. Improved maintainability by centralizing booking creation logic. Enhanced test readability by reducing boilerplate setup in each test. Closes #63 --- .../test/Booking.Tests/BookingShould.cs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/csharp/csharp-booking-01_base/test/Booking.Tests/BookingShould.cs b/examples/csharp/csharp-booking-01_base/test/Booking.Tests/BookingShould.cs index 6b484c12..2ab18704 100644 --- a/examples/csharp/csharp-booking-01_base/test/Booking.Tests/BookingShould.cs +++ b/examples/csharp/csharp-booking-01_base/test/Booking.Tests/BookingShould.cs @@ -13,19 +13,23 @@ private void GetTheCorrectStatusWhenTheBookingHasNotStartedYet() var bookingStartDate = new DateTime(2020, 6, 26, 19, 0, 0); var bookingEndDate = new DateTime(2020, 7, 14, 16, 0, 0); - var booking = new Booking( - new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"), - bookingStartDate, - bookingEndDate, - new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"), - new CustomerName("Perico Los Palotes"), - new EmailAddress("perico.los.palotes@mail.com"), - BookingType.VACATION, - DiscountType.NONE, - new DiscountValue(0), - TaxType.NONE, - new TaxValue(0) - ); + private Booking CreateBooking(DateTime startDate, DateTime endDate) + { + return new Booking( + new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"), + startDate, + endDate, + new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"), + new CustomerName("Perico Los Palotes"), + new EmailAddress("perico.los.palotes@mail.com"), + BookingType.VACATION, + DiscountType.NONE, + new DiscountValue(0), + TaxType.NONE, + new TaxValue(0) + ); + } + Assert.Equal(BookingStatus.NOT_STARTED, booking.StatusFor(dateBeforeBookingHasStarted)); }