public AvailabilitySearchResultDto CheckAvailability(long businessId, AvailabilitySearchCriteriaDto searchCriteria)
        {
            // Make sure the current user has access to this business
            CheckAccessRights(businessId);

            // Validate if business exists
            if (Cache.Business.TryGetValue(businessId) == null)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30001, "PropertyManagementSystemService.CheckAvailability",
                    additionalDescriptionParameters: (new object[] { businessId })));
            }

            // Convert the criteria to a model object
            AvailabilitySearchCriteria criteria = DataTransferObjectsConverter.ConvertDtoToAvailabilitySearchCriteria(searchCriteria);

            // Get the results
            AvailabilitySearchResult result = availabilityManager.CheckAvailability(criteria);

            // Convert the result back to a DTO and return
            var dtoResults = DataTransferObjectsConverter.ConvertAvailabilitySearchResultToDto(result);

            return dtoResults;
        }
            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 = DataTransferObjectsConverter.ConvertCalendarDateToDto(startDate),
                    EndDate = DataTransferObjectsConverter.ConvertCalendarDateToDto(endDate),
                    BusinessId = INVALID_BUSINESS,
                    RoomTypeId = 1,
                    NumberOfAdults = 1,
                    NumberOfChildren = 0
                };

                try
                {
                    // Act
                    PropertyManagementSystemService.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");
                }
            }
            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 = DataTransferObjectsConverter.ConvertCalendarDateToDto(startDate),
                    EndDate = DataTransferObjectsConverter.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,
                        RoomTypeCode = "R1",
                        RoomTypeName = "Double Room",
                        RoomTypeId = 1
                    }
                };

                resultToReturn.BusinessCandidates[0].RoomTypes[0].RatesAndRoomsAvailable = new List<RoomsAvailability>
                {
                    new RoomsAvailability
                    {
                        RatePlanId = 1,
                        RoomTypeId = 1,
                        RoomList = new List<int> {1, 2}
                    }
                };

                // 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);
                PropertyManagementSystemService.AvailabilityManager = availabilityManager;

                // Act
                AvailabilitySearchResultDto availabilitySearchResult =
                    PropertyManagementSystemService.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 RoomTypesRatesAndRoomsAvailable returned is incorrect.");
                Assert.AreEqual(1, availabilitySearchResult.BusinessCandidates[0].RoomTypes[0].RoomTypeId,
                                "RoomType Id retrieved is incorrect.");
                Assert.IsNotNull(availabilitySearchResult.BusinessCandidates[0].RoomTypes[0].RatesAndRoomsAvailable,
                                 "RatesAndRoomsAvailable are not retrieved for roomType.");

                RoomsAvailabilityDto additionalRateplan =
                    availabilitySearchResult.BusinessCandidates[0].RoomTypes[0].RatesAndRoomsAvailable[0];

                Assert.AreEqual(1, additionalRateplan.RatePlanId, "Rateplan id retrieved is incorrect.");
            }
Пример #4
0
 /// <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,
                    RoomTypeId = searchCriteria.RoomTypeId,
                    RatePlanId = searchCriteria.RatePlanId,
                    ModifyBookingId = searchCriteria.ModifyBookingId,
                    ChannelId = searchCriteria.ChannelId,
                    BoardBasis = searchCriteria.BoardBasis != null ? new BoardBasis { Code = searchCriteria.BoardBasis.Code } : null,
                    CancellationClass = searchCriteria.CancellationClass != null ? new CancellationClass { Code = searchCriteria.CancellationClass.Code } : null,
                    RequestedCurrency = searchCriteria.RequestedCurrency
                };
 }