/// <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."); } }
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."); } }
public void CheckAdditionalRatePlanAvailabilityByRoomTypeIsSuccessful() { // Arrange const int BUSINESS_ID = 1; var availabilityManager = MockRepository.GenerateStub<IAvailabilityManager>(); CalendarDate startDate = CalendarDate.ConvertToCalendarDate(DateTime.UtcNow); CalendarDate endDate = CalendarDate.ConvertToCalendarDate(DateTime.UtcNow).AddDays(1); var searchDto = new AvailabilitySearchCriteriaDto { StartDate = LimitedDataTransferObjectsConverter.ConvertCalendarDateToDto(startDate), EndDate = LimitedDataTransferObjectsConverter.ConvertCalendarDateToDto(endDate), BusinessId = BUSINESS_ID, RoomTypeId = 1, NumberOfAdults = 1, NumberOfChildren = 0 }; var resultToReturn = new AvailabilitySearchResult { StartDate = startDate, EndDate = endDate, NoOfAdults = 2, NoOfChildren = null, BusinessCandidates = new List<AvailabilityResultBusiness> { new AvailabilityResultBusiness { BusinessId = BUSINESS_ID } }, }; resultToReturn.BusinessCandidates[0].RoomTypes = new List<AvailabilityResultRoomType> { new AvailabilityResultRoomType { BusinessId = BUSINESS_ID, RoomIds = new List<int> {1, 2}, RoomTypeCode = "R1", RoomTypeName = "Double Room", RoomTypeId = 1 } }; resultToReturn.BusinessCandidates[0].RoomTypes[0].RatePlans = new List<AvailabilityResultRatePlan> { new AvailabilityResultRatePlan { RatePlanId = 1, RoomTypeId = 1, IsBaseRatePlan = false } }; resultToReturn.BusinessCandidates[0].RoomTypes[0].RatePlans[0].PriceCandidates = new List<AvailabilityResultPrice> { new AvailabilityResultPrice { BusinessId = BUSINESS_ID, RoomTypeId = 1, TotalPrice = 100, RatePlanId = 1 } }; resultToReturn.BusinessCandidates[0].RoomTypes[0].RatePlans[0].PriceCandidates[0]. PriceCalculationBreakdowns = new List<PriceCalculationBreakdown> { new PriceCalculationBreakdown { NightNumber = 1, Price = 100, RateType = new EnumEntity { Code = RateType.BAR } } }; // Stub the BusinessCache to be used by our service method CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID); // invalidate the cache so we make sure our business is loaded into the cache Cache.Business.Invalidate(); availabilityManager.Stub(m => m.CheckAvailability(Arg<AvailabilitySearchCriteria>.Is.Anything)).Return(resultToReturn); limitedMobileService.AvailabilityManager = availabilityManager; // Act AvailabilitySearchResultDto availabilitySearchResult = limitedMobileService.CheckAvailability(BUSINESS_ID, searchDto); // Assert Assert.AreEqual(BUSINESS_ID, availabilitySearchResult.BusinessCandidates[0].BusinessId, "Check the businessId has been correctly set"); Assert.AreEqual(1, availabilitySearchResult.BusinessCandidates[0].RoomTypes.Count, "Number Of RoomTypes returned is incorrect."); Assert.AreEqual(1, availabilitySearchResult.BusinessCandidates[0].RoomTypes[0].RoomTypeId, "RoomType Id retrieved is incorrect."); Assert.IsNotNull(availabilitySearchResult.BusinessCandidates[0].RoomTypes[0].RatePlans, "RatePlans are not retrieved for roomType."); AvailabilityResultRatePlanDto additionalRateplan = availabilitySearchResult.BusinessCandidates[0].RoomTypes[0].RatePlans[0]; Assert.IsFalse(additionalRateplan.IsBaseRatePlan, "Additional Rateplan is not retrieved."); Assert.AreEqual(1, additionalRateplan.RatePlanId, "Rateplan id retrieved is incorrect."); Assert.IsNotNull(additionalRateplan.PriceCandidates, "Price available is null."); Assert.AreEqual(1, additionalRateplan.PriceCandidates.Count, "Total number of price candidates are wrong."); Assert.AreEqual(100, additionalRateplan.PriceCandidates[0].TotalPrice, "TotalPrice calculated is not correct."); }
public void CheckAvailabilityWithInvalidBusinessThrowsException() { // Arrange CalendarDate startDate = CalendarDate.ConvertToCalendarDate(DateTime.UtcNow); CalendarDate endDate = CalendarDate.ConvertToCalendarDate(DateTime.UtcNow).AddDays(1); // business that we know will never exist in the cache const long INVALID_BUSINESS = -100; var searchDto = new AvailabilitySearchCriteriaDto { StartDate = LimitedDataTransferObjectsConverter.ConvertCalendarDateToDto(startDate), EndDate = LimitedDataTransferObjectsConverter.ConvertCalendarDateToDto(endDate), BusinessId = INVALID_BUSINESS, RoomTypeId = 1, NumberOfAdults = 1, NumberOfChildren = 0 }; try { // Act limitedMobileService.CheckAvailability(INVALID_BUSINESS, searchDto); // Assert Assert.Fail("An exception SRVEX30001 of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30001", ex.Code, "The Validation exception is not returning the right error code"); } }
/// <summary> /// Convert the AvailabilitySearchCriteriaDto to AvailabilitySearchCriteria Model /// </summary> /// <param name="searchCriteria">The object to convert</param> /// <returns>AvailabilitySearchCriteria</returns> public static AvailabilitySearchCriteria ConvertDtoToAvailabilitySearchCriteria(AvailabilitySearchCriteriaDto searchCriteria) { return new AvailabilitySearchCriteria { BusinessIds = new List<long> { searchCriteria.BusinessId }, StartDate = ConvertDtoToCalendarDate(searchCriteria.StartDate), EndDate = ConvertDtoToCalendarDate(searchCriteria.EndDate), NumberOfAdults = searchCriteria.NumberOfAdults, NumberOfChildren = searchCriteria.NumberOfChildren, RoomId = searchCriteria.RoomId, RoomTypeId = searchCriteria.RoomTypeId, RatePlanId = searchCriteria.RatePlanId, ModifyBookingId = searchCriteria.ModifyBookingId }; }