Пример #1
0
            public void CancelBookingWithoutMockingIsSuccessful()
            {
                using (new TestDataHelper(TestDataQueriesLimited.PopulateCheckInCheckOutBookingTestData, TestDataQueriesLimited.CleanupTestData))
                {
                    // Arrange
                    var serviceWithoutMock = new LimitedMobileService
                                                                  {
                                                                      DisableAccessRightsCheck = true,
                                                                      FakeAuthenticationForDebugging = true
                                                                  };
                    var bookingManager = new BookingManager {BookingDao = new BookingDao()};
                    var roomsAvailabilityDao = new RoomsAvailabilityDao();                    

                    const long BUSINESS_ID = 11111;
                    const int BOOKING_ID = 1;
                    const bool USER_OPTION_TO_REFUND = false;
                    DateTime startDate = DateTime.Now;
                    DateTime endDate = DateTime.Now.AddDays(1);
                    const int ROOM_ID = 1;

                    

                    // Update Room availability to false because the script PopulateCheckInCheckOutBookingTestData does not update availability
                    roomsAvailabilityDao.UpdateRoomAvailability(BUSINESS_ID, ROOM_ID, startDate, endDate, false, new Guid("11111111-1111-1111-1111-111111111111"));

                    // Get availability before cancelling the booking
                    RoomsAvailability roomsAvailabilityBefore = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID,
                                                                                                        ROOM_ID,
                                                                                                        startDate.Year);

                    Assert.IsFalse(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityBefore, startDate.DayOfYear,
                                                                       endDate.DayOfYear), "The rooms for the dates booked are available.");

                    // TODO UPDATE THIS TO REFERENCE THE NEW AUDITING DAO AND METHODS ONCE THE NEW AUDITING HAS BEEN IMPLEMENTED
                    // Check Audit records before cancellation
                    // Search recent tables. Recent tables hold information temporarily until AuditServiceTask service can pick it up and move it to the history table
                    //List<BookingRecordAudit> auditRecordsBeforeCancellation = auditDao.GetAllForRecentTable(0);
                    //if (auditRecordsBeforeCancellation.Count == 0)
                    //{
                    //    auditRecordsBeforeCancellation = auditDao.GetAllForRecentTable(1);
                    //}
                    //Assert.AreNotEqual(0, auditRecordsBeforeCancellation.Count, "There are no booking audit records created in the database.");

                    //// Get audit records related to update. AuditActionTypeId = 2 indicates update.
                    //List<BookingRecordAudit> auditRecordsBeforeCancellationSpecificToBooking =
                    //    auditRecordsBeforeCancellation.FindAll(b => b.BookingReferenceNumber == "REF0001" && b.AuditActionTypeId == 2);
                    //Assert.AreEqual(0, auditRecordsBeforeCancellationSpecificToBooking.Count, "Booking audit records for cancellation should be null.");

                    // Act
                    bool isSuccess = serviceWithoutMock.CancelBooking(BUSINESS_ID, BOOKING_ID, USER_OPTION_TO_REFUND);

                    // Assert
                    Assert.IsTrue(isSuccess, "Booking is not cancelled successfully.");
                    Booking bookingAfterCancellation = bookingManager.GetByKey(BOOKING_ID, BUSINESS_ID);
                    Assert.AreEqual(BookingStatusType.Cancelled, bookingAfterCancellation.BookingStatus, "Booking Status after cancelling is incorrect.");
                    Assert.IsTrue(bookingAfterCancellation.IsCancelled, "The booking is not yet cancelled.");

                    // Check Rooms availability after cancellation
                    RoomsAvailability roomsAvailabilityAfter = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID,
                                                                                                       bookingAfterCancellation.RoomId,
                                                                                                       DateTime.UtcNow.Year);

                    Assert.IsFalse(RoomAvailabilityHelper.IsAvailabilityTheSame(roomsAvailabilityBefore, roomsAvailabilityAfter), "Make sure availability has changed for the room.");

                    // Check if the rooms are available again.
                    Assert.IsTrue(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityAfter, bookingAfterCancellation.StartDateUTC.DayOfYear,
                                                                      bookingAfterCancellation.EndDateUTC.DayOfYear), "The rooms for the dates booked are unavailable.");

                    // TODO UPDATE THIS TO REFERENCE THE NEW AUDITING DAO AND METHODS ONCE THE NEW AUDITING HAS BEEN IMPLEMENTED
                    // Audit table should be updated to record cancellation event.
                    // Search recent tables. Recent tables hold information temporarily until AuditServiceTask service can pick it up and move it to the history table
                    //List<BookingRecordAudit> auditRecordsAfterCancellation = auditDao.GetAllForRecentTable(0);
                    //if(auditRecordsAfterCancellation.Count == 0)
                    //{
                    //    auditRecordsAfterCancellation = auditDao.GetAllForRecentTable(1);
                    //}
                    //Assert.AreNotEqual(0, auditRecordsAfterCancellation.Count, "There are no booking audit records created in the database.");

                    //// Get audit records related to update. AuditActionTypeId = 2 indicates update.
                    //List<BookingRecordAudit> auditRecordsAfterCancellationSpecificToBooking =
                    //    auditRecordsAfterCancellation.FindAll(b => b.BookingReferenceNumber == "REF0001" && b.AuditActionTypeId == 2);
                    //Assert.IsNotNull(auditRecordsAfterCancellationSpecificToBooking, "Booking audit records for cancellation is null.");
                    //Assert.AreNotEqual(0, auditRecordsAfterCancellationSpecificToBooking.Count, "Total number of booking audit records created in the database for the cancelled booking is incorrect.");

                    //foreach (BookingRecordAudit bookingRecordAudit in auditRecordsAfterCancellationSpecificToBooking)
                    //{
                    //    // Check OldIsCancelled field
                    //    Assert.IsNotNull(bookingRecordAudit.OldIsCancelled, "OldIsCancelled field should have a value.");
                    //    Assert.IsFalse(bookingRecordAudit.OldIsCancelled.Value, "OldIsCancelled field should be false.");

                    //    // Check IsCancelled field
                    //    Assert.IsNotNull(bookingRecordAudit.IsCancelled, "IsCancelled field should have a value.");
                    //    Assert.IsTrue(bookingRecordAudit.IsCancelled.Value, "IsCancelled field should be true.");

                    //    // Check if UpdatedByUserId and LastUpdatedDateTimeUTC fields are updated correctly.
                    //    Assert.AreNotEqual(Guid.Empty, bookingRecordAudit.UpdatedByUserId, "UpdatedByUserId field should have a value.");
                    //    Assert.AreNotEqual(DateTime.MinValue, bookingRecordAudit.LastUpdatedDateTimeUTC, "LastUpdatedDateTimeUTC field should be true.");
                    //}
                }
            }
Пример #2
0
            public void ModifyBookingWithoutMockingIsSuccessful()
            {
                using (new TestDataHelper(TestDataQueriesLimited.PopulateBookingsAndCloseOutsTestData, TestDataQueriesLimited.CleanupTestData))
                {
                    // Arrange
                    var serviceWithoutMock = new LimitedMobileService
                    {
                        DisableAccessRightsCheck = true,
                        FakeAuthenticationForDebugging = true
                    };
                    Cache.Business.Invalidate();

                    var bookingManager = new BookingManager {BookingDao = new BookingDao()};
                    var roomsAvailabilityDao = new RoomsAvailabilityDao();
                    
                    const long BUSINESS_ID = 1;
                    const int BOOKING_ID = 1;
                    const bool FORCE_MODIFY = false;

                    const int ROOM_ID = 1;

                    // Fetch the booking to modify
                    Booking bookingToModify = bookingManager.GetByKey(BOOKING_ID, BUSINESS_ID);
                    BookingDto bookingToModifyDto = LimitedDataTransferObjectsConverter.ConvertBookingToDto(bookingToModify);

                    Assert.IsNotNull(bookingToModifyDto, "booking was null after fetch");

                    // Update Room availability to false because the script PopulateBookingsAndCloseOutsTestData does not update availability
                    roomsAvailabilityDao.UpdateRoomAvailability(bookingToModifyDto.BusinessId, bookingToModifyDto.RoomId, 
                                                                bookingToModifyDto.StartDateUTC, bookingToModifyDto.EndDateUTC, false,
                                                                new Guid("11111111-1111-1111-1111-111111111111"));

                    // Get availability before Modifying the booking
                    RoomsAvailability roomsAvailabilityBefore = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID,
                                                                                                        ROOM_ID,
                                                                                                        bookingToModifyDto.StartDateUTC.Year);

                    // modify start / end date
                    DateTime startDate = bookingToModifyDto.StartDateUTC;
                    DateTime endDate = bookingToModifyDto.EndDateUTC;

                    bookingToModifyDto.StartDateUTC = new DateTime(DateTime.UtcNow.Year + 1, bookingToModifyDto.StartDateUTC.Month, bookingToModifyDto.StartDateUTC.Day);
                    bookingToModifyDto.EndDateUTC = new DateTime(DateTime.UtcNow.Year + 1, bookingToModifyDto.EndDateUTC.Month, bookingToModifyDto.EndDateUTC.Day);

                    DateTime modifiedStartDate = bookingToModifyDto.StartDateUTC;
                    DateTime modifiedEndDate = bookingToModifyDto.EndDateUTC;

                    Assert.IsFalse(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityBefore, startDate.DayOfYear,
                                                   endDate.DayOfYear), "The rooms for the dates booked are available in the old date range.");

                    // Act
                    bool isSuccess = serviceWithoutMock.ModifyBooking(BUSINESS_ID, FORCE_MODIFY, bookingToModifyDto);

                    // Assert
                    Assert.IsTrue(isSuccess, "Booking is not Modified successfully.");
                    Booking bookingAfterModify = bookingManager.GetByKey(BOOKING_ID, BUSINESS_ID);

                    Assert.AreEqual(modifiedStartDate, bookingAfterModify.StartDateUTC, "Booking Start date after modify is incorrect.");
                    Assert.AreEqual(modifiedEndDate, bookingAfterModify.EndDateUTC, "Booking End date after modify is incorrect.");
                    
                    // Check Rooms availability after Modify
                    RoomsAvailability roomsAvailabilityAfter = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID,
                                                                                                       bookingAfterModify.RoomId,
                                                                                                       bookingToModifyDto.EndDateUTC.Year);

                    Assert.IsTrue(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityAfter, startDate.DayOfYear, modifiedStartDate.DayOfYear), 
                        "Make sure availability has changed for the room.");

                    // Check if the rooms are not available for the new range of dates.
                    Assert.IsFalse(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityAfter, bookingAfterModify.StartDateUTC.DayOfYear,
                                                                      bookingAfterModify.EndDateUTC.DayOfYear), "The rooms for the dates booked are available.");
                }
            }