Ejemplo n.º 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.");
                    //}
                }
            }
Ejemplo n.º 2
0
            public void CheckAvailabilityWithoutMockingToChangeRatePlanOfBookingReturnsAllRatePlansApplicable()
            {
                using (new TestDataHelper(TestDataQueriesLimited.PopulateCheckRatePlanAvailabilityTestData, TestDataQueriesLimited.CleanupTestData))
                {
                    // Arrange
                    var serviceWithoutMock = new LimitedMobileService
                    {
                        DisableAccessRightsCheck = true,
                        FakeAuthenticationForDebugging = true,
                        AvailabilityManager = new AvailabilityManager {RoomAvailabilityDao = new RoomsAvailabilityDao()},
                        BookingManager = new BookingManager {BookingDao = new BookingDao()},
                        BusinessManager = new BusinessManager {BusinessDao = new BusinessDao()}
                    };

                    const long BUSINESS_ID = 1;
                    
                    // Create booking
                    var booking = new BookingDto
                    {
                            BusinessId = BUSINESS_ID,
                            Customer = new CustomerDto
                            {
                                BusinessId = BUSINESS_ID,
                                Surname = "Test Customer",
                                Email = "*****@*****.**"
                            },
                            StartDateUTC = DateTime.Now,
                            EndDateUTC = DateTime.Now.AddDays(1),
                            NumberOfAdults = 2,
                            IsBookingConfirmed = true,
                            IsOffline = true,
                            RoomTypeId = 1,
                            RoomId = 1,
                            RatePlanId = 1,
                            IsProvisional = false,
                            Cost = new decimal(50),
                            BookingScenarioType = BookingScenarioTypeDto.OnAccountBooking
                        };

                    booking = serviceWithoutMock.CreateBooking(BUSINESS_ID, booking);
                    Assert.IsNotNull(booking.Id, "Booking Id is not attributed upon creation.");
                    
                    // Build availability Search criteria
                    var searchCriteria = new AvailabilitySearchCriteriaDto
                    {
                        BusinessId = booking.BusinessId,
                        StartDate = new CalendarDateDto
                        {
                            Day = booking.StartDateUTC.Day,
                            Month = booking.StartDateUTC.Month,
                            Year = booking.StartDateUTC.Year
                        },
                        EndDate = new CalendarDateDto
                        {
                            Day = booking.EndDateUTC.Day,
                            Month = booking.EndDateUTC.Month,
                            Year = booking.EndDateUTC.Year
                        },
                        NumberOfAdults = booking.NumberOfAdults,
                        NumberOfChildren = booking.NumberOfChildren,
                        RoomTypeId = booking.RoomTypeId,
                        RoomId = booking.RoomId,
                        ModifyBookingId = booking.Id
                    };

                    // Act
                    AvailabilitySearchResultDto searchResult = serviceWithoutMock.CheckAvailability(booking.BusinessId, searchCriteria);

                    // Assert
                    Assert.IsNotNull(searchResult, "AvailabilitySearchResult is null");
                    Assert.AreEqual(1, searchResult.BusinessCandidates.Count, "Total number of business candidates returned is incorrect.");
                    Assert.IsTrue(searchResult.BusinessCandidates[0].BusinessId == booking.BusinessId, "BusinessId returned on search results is incorrect.");
                    AvailabilityResultBusinessDto businessCandidate = searchResult.BusinessCandidates[0];
                    Assert.AreEqual(1, businessCandidate.RoomTypes.Count, "Number of roomTypes returned is incorrect.");
                    Assert.AreEqual(booking.RoomTypeId, businessCandidate.RoomTypes[0].RoomTypeId, "RoomTypeId returned is incorrect.");

                    Assert.AreEqual(1, businessCandidate.RoomTypes[0].RoomIds.Count, "Number of rooms returned is incorrect.");
                    Assert.AreEqual(booking.RoomId, businessCandidate.RoomTypes[0].RoomIds[0], "RoomId returned is incorrect.");

                    // Check Rateplans
                    // There should be additional rateplans returned as available.
                    Assert.AreEqual(2, businessCandidate.RoomTypes[0].RatePlans.Count, "Total number of rateplans returned is incorrect.");
                    Assert.IsNotNull(businessCandidate.RoomTypes[0].RatePlans.Find(r => r.RatePlanId == booking.RatePlanId), "The rateplan for which the booking is made is not returned as available.");
                    Assert.IsNotNull(businessCandidate.RoomTypes[0].RatePlans.Find(r => r.RatePlanId != booking.RatePlanId), "Additional rateplan is not returned as available.");

                    // Since we have not setup price as part of test data, NoRateDefined reason code should be returned at RoomType level.
                    Assert.AreEqual(UnavailabilityReasonCodeDto.NoRateDefined, businessCandidate.RoomTypes[0].UnAvailabilityReasonCode, "UnAvailabilityReasonCode at RoomType level is incorrect.");
                }
            }
Ejemplo n.º 3
0
            /// <summary>
            /// To do non-mocking tests of check availability in a bit more easily done manner
            /// </summary>
            /// <param name="includeRoomType">If room type should be in search criteria</param>
            /// <param name="expectedRoomTypeIds">A list of the expected room type ids</param>
            /// <param name="includeRatePlan">If rate plan should be in search criteria</param>
            /// <param name="expectedRatePlanIdsForRoomType">A list of the expected rate plan ids for each room type</param>
            /// <param name="includeRoomId">If Room Id should be in search criteria</param>
            /// <param name="expectedRoomIdsForRoomType">A list of the expected room ids for each room type</param>
            /// <param name="numberOfAdults">Set a number of adults in the search criteria</param>
            /// <param name="numberOfChildren">Set a number of children in the search criteria</param>
            /// <remarks>Room type is only one verified to work correctly. Check asserts if using the rate plan or room id flags</remarks>
            private void CheckAvailabilityWithoutMockingForBookingModifyTests(bool includeRoomType = false, List<int> expectedRoomTypeIds = null, 
                bool includeRatePlan = false, Dictionary<int, List<int>> expectedRatePlanIdsForRoomType = null, bool includeRoomId = false,
                Dictionary<int, List<int>> expectedRoomIdsForRoomType = null, int? numberOfAdults = null, int? numberOfChildren = null)
            {
                using (new TestDataHelper(TestDataQueriesLimited.PopulateCheckRatePlanAvailabilityTestData, TestDataQueriesLimited.CleanupTestData))
                {
                    // Arrange
                    var serviceWithoutMock = new LimitedMobileService
                    {
                        DisableAccessRightsCheck = true,
                        FakeAuthenticationForDebugging = true,
                        AvailabilityManager = new AvailabilityManager
                        {
                            RoomAvailabilityDao = new RoomsAvailabilityDao()
                        },
                        BookingManager = new BookingManager
                        {
                            BookingDao = new BookingDao()
                        },
                        BusinessManager = new BusinessManager
                        {
                            BusinessDao = new BusinessDao()
                        }
                    };

                    const long BUSINESS_ID = 1;

                    // Create booking
                    var booking = new BookingDto
                    {
                        BusinessId = BUSINESS_ID,
                        Customer = new CustomerDto
                        {
                            BusinessId = BUSINESS_ID,
                            Surname = "Test Customer",
                            Email = "*****@*****.**"
                        },
                        StartDateUTC = DateTime.Now,
                        EndDateUTC = DateTime.Now.AddDays(1),
                        NumberOfAdults = 2,
                        IsBookingConfirmed = true,
                        IsOffline = true,
                        RoomTypeId = 1,
                        RoomId = 1,
                        RatePlanId = 1,
                        IsProvisional = false,
                        Cost = new decimal(50),
                        BookingScenarioType = BookingScenarioTypeDto.OnAccountBooking
                    };

                    booking = serviceWithoutMock.CreateBooking(BUSINESS_ID, booking);
                    Assert.IsNotNull(booking.Id, "Booking Id is not attributed upon creation.");

                    // Build availability Search criteria
                    var searchCriteria = new AvailabilitySearchCriteriaDto
                    {
                        BusinessId = booking.BusinessId,
                        StartDate = new CalendarDateDto
                        {
                            Day = booking.StartDateUTC.Day,
                            Month = booking.StartDateUTC.Month,
                            Year = booking.StartDateUTC.Year
                        },
                        EndDate = new CalendarDateDto
                        {
                            Day = booking.EndDateUTC.Day,
                            Month = booking.EndDateUTC.Month,
                            Year = booking.EndDateUTC.Year
                        },
                        NumberOfAdults = numberOfAdults ?? booking.NumberOfAdults,
                        NumberOfChildren = numberOfChildren ?? booking.NumberOfChildren,
                        RoomTypeId = includeRoomType ? (int?)booking.RoomTypeId : null,
                        RatePlanId = includeRatePlan ? booking.RatePlanId : null,
                        RoomId = includeRoomId ? (int?)booking.RoomId : null,
                        ModifyBookingId = booking.Id
                    };

                    // Act
                    AvailabilitySearchResultDto searchResult = serviceWithoutMock.CheckAvailability(booking.BusinessId, searchCriteria);

                    // Assert
                    Assert.IsNotNull(searchResult, "AvailabilitySearchResult is null");
                    Assert.AreEqual(1, searchResult.BusinessCandidates.Count, "Total number of business candidates returned is incorrect.");
                    Assert.IsTrue(searchResult.BusinessCandidates[0].BusinessId == booking.BusinessId, "BusinessId returned on search results is incorrect.");

                    AvailabilityResultBusinessDto businessCandidate = searchResult.BusinessCandidates[0];

                    if (expectedRoomTypeIds == null && includeRoomType)
                    {
                        // Default to booking room type id if it is to be included
                        expectedRoomTypeIds = new List<int> { booking.RoomTypeId };
                    }

                    if (expectedRoomTypeIds != null)
                    {
                        // Validate room types
                        Assert.AreEqual(expectedRoomTypeIds.Count, businessCandidate.RoomTypes.Count, "Number of roomTypes returned is incorrect.");

                        foreach (var expectedRoomTypeId in expectedRoomTypeIds)
                        {
                            var roomType = businessCandidate.RoomTypes.Find(x => x.RoomTypeId == expectedRoomTypeId);
                            Assert.IsNotNull(roomType, "An expected room type was not returned");

                            // Validate rooms
                            if (expectedRoomIdsForRoomType == null && includeRoomId)
                            {
                                // Default to booking room id if it is to be included
                                expectedRoomIdsForRoomType = new Dictionary<int, List<int>>
                                    {
                                        { booking.RoomTypeId, new List<int> { booking.RoomId } }
                                    };
                            }

                            if (expectedRoomIdsForRoomType != null)
                            {
                                List<int> roomIds;
                                expectedRoomIdsForRoomType.TryGetValue(expectedRoomTypeId, out roomIds);

                                if (roomIds != null)
                                {
                                    Assert.IsNotNull(roomType.RoomIds, "Room ids are not retrieved for roomType.");
                                    Assert.AreEqual(roomIds.Count, roomType.RoomIds.Count, "Number of rooms returned is incorrect.");
                                }
                            }

                            // Validate rate plans
                            if (expectedRatePlanIdsForRoomType == null && includeRatePlan)
                            {
                                // Default to booking room id if it is to be included
                                expectedRatePlanIdsForRoomType = new Dictionary<int, List<int>>
                                    {
                                        { booking.RoomTypeId, new List<int> { booking.RatePlanId.Value } }
                                    };
                            }

                            if (expectedRatePlanIdsForRoomType != null)
                            {
                                List<int> ratePlanIds;
                                expectedRatePlanIdsForRoomType.TryGetValue(expectedRoomTypeId, out ratePlanIds);

                                if (ratePlanIds != null && ratePlanIds.Count > 0)
                                {
                                    Assert.IsNotNull(roomType.RatePlans, "RatePlans are not retrieved for roomType.");
                                    Assert.AreEqual(ratePlanIds.Count, roomType.RatePlans.Count, "Number of rate plans returned is incorrect.");

                                    foreach (var ratePlanId in ratePlanIds)
                                    {
                                        Assert.IsTrue(roomType.RatePlans.Any(x => x.RatePlanId == ratePlanId), "The rate plan returned is incorrect.");
                                    }
                                }
                                else
                                {
                                    Assert.IsNull(roomType.RatePlans, "RatePlan should not exist for room type.");
                                }
                            }
                        }
                    }

                    // NoRateDefined or NoAvailability reason code should be returned at RoomType level if there is no priced defined or weekly availability criteria is not met
                    Assert.IsTrue(businessCandidate.RoomTypes[0].UnAvailabilityReasonCode == UnavailabilityReasonCodeDto.NoRateDefined
                        || businessCandidate.RoomTypes[0].UnAvailabilityReasonCode == UnavailabilityReasonCodeDto.NoAvailability, 
                        "UnAvailabilityReasonCode at RoomType level is incorrect.");
                }
            }
Ejemplo n.º 4
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.");
                }
            }