Beispiel #1
0
        /// <summary>
        /// Assign and return rates for a Daily Rate
        /// </summary>
        /// <param name="startDate">Start Date</param>
        /// <param name="dailyRate">End Date</param>
        /// <param name="daysTillEndDate">Days till end</param>
        /// <returns>RatesRestrictionsDateRangeEntry object</returns>
        private static RatesRestrictionsDateRangeEntry AssignRates(DateTime startDate, RateCache dailyRate, ref int daysTillEndDate)
        {
            var daysOffSetFromStartDate = (dailyRate.Date - startDate).Days;
            var roomPrice = new Money(dailyRate.Rate);

            if (daysTillEndDate < daysOffSetFromStartDate)
            {
                daysTillEndDate = daysOffSetFromStartDate;
            }

            if (dailyRate.MinStay == 0)
            {
                Logger.Error(string.Format("Minimum booking duration is invalid. It is set as 0 for room type id {0}, date {1} ", dailyRate.ProductId, dailyRate.Date));

                return IsValidPrice(dailyRate.Rate, dailyRate.ProductId, dailyRate.Date) ? new RatesRestrictionsDateRangeEntry(daysOffSetFromStartDate, roomPrice.ToPence(), null) : new RatesRestrictionsDateRangeEntry(daysOffSetFromStartDate, null, null);
            }

            return !IsValidPrice(dailyRate.Rate, dailyRate.ProductId, dailyRate.Date) ? new RatesRestrictionsDateRangeEntry(daysOffSetFromStartDate, null, dailyRate.MinStay) : new RatesRestrictionsDateRangeEntry(daysOffSetFromStartDate, roomPrice.ToPence(), dailyRate.MinStay);
        }
Beispiel #2
0
            public void GetDateRateIdIsSuccessful()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateRatePlanDateRateData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var roomTypeId = roomTypeDao.GetRoomTypeIdByName("Single-Deluxe-Private Bathroom");
                    var ratePlanId = ratePlanDao.GetBaseRatePlanIdByRoomTypeId(roomTypeId);

                    var rate = new RateCache
                    {
                        RoomTypeId = roomTypeId,
                        RatePlanId = ratePlanId,
                        Date = new DateTime(2013, 1, 1).Date,
                        Rate = new decimal(20),
                        MinStay = 2
                    };
                    
                    //Act
                    var dateRateId = rateCacheDao.GetDateRateId(rate);

                    Assert.IsNotNull(dateRateId, "Date rate id was not returned.");
                }
            }
Beispiel #3
0
            public void GetDateRateIdWithInvalidDataReturnsNothing()
            {
                const int INVALID_ID = 0;

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateRatePlanDateRateData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var rate = new RateCache
                    {
                        RoomTypeId = INVALID_ID,
                        RatePlanId = INVALID_ID,
                        Date = DateTime.UtcNow.Date,
                        Rate = new decimal(10),
                        MinStay = 1
                    };

                    //Act
                    var dateRateId = rateCacheDao.GetDateRateId(rate);
                    
                    Assert.IsNull(dateRateId, "Date rate id was returned.");
                }
            }
Beispiel #4
0
            public void ModifyDateRateIsSuccessful()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateRatePlanDateRateData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var roomTypeId = roomTypeDao.GetRoomTypeIdByName("Single-Deluxe-Private Bathroom");
                    var ratePlanId = ratePlanDao.GetBaseRatePlanIdByRoomTypeId(roomTypeId);

                    var rate = new RateCache
                        {
                            RoomTypeId = roomTypeId,
                            RatePlanId = ratePlanId,
                            Date = new DateTime(2013, 1, 1).Date,
                            Rate = new decimal(20),
                            MinStay = 2
                        };

                    var dateRateId = rateCacheDao.GetDateRateId(rate);

                    //Act
                    rateCacheDao.ModifyDateRate(dateRateId.Value, rate);
                }
            }
Beispiel #5
0
            public void ModifyDateRateWithInvalidDataThrowsException()
            {
                const int INVALID_ID = 0;

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateRatePlanDateRateData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var rate = new RateCache
                               {
                                   RoomTypeId = INVALID_ID,
                                   RatePlanId = INVALID_ID,
                                   Date = DateTime.UtcNow.Date,
                                   Rate = new decimal(10),
                                   MinStay = 1
                               };

                    //Act
                    rateCacheDao.ModifyDateRate(INVALID_ID, rate);
                }
            }
Beispiel #6
0
        /// <summary>
        /// Get the id of an existing date rate record
        /// </summary>
        /// <param name="rate">The rate to retrieve the date rate id for</param>
        /// <returns>The id of the date rate if it exists</returns>
        public int? GetDateRateId(RateCache rate)
        {
            const string QUERY = @"
                SELECT    Id
                FROM    Pricing.RatePlanDateRate
                WHERE   RoomTypeId = @RoomTypeId
                AND     RatePlanId = @RatePlanId
                AND     Date = @Date ";

            var parameters = new List<SqlParameter>
                {
                DbHelper.CreateParameter(RateCacheMapper.Parameters.RoomTypeId, rate.RoomTypeId),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.RatePlanId, rate.RatePlanId),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.Date, rate.Date)
                };

            return DbHelper.ExecuteScalar<int?>(QUERY, parameters: parameters);
        }
Beispiel #7
0
            public void CreateDateRateIsSuccessful()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateRatePlanDateRateData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var roomTypeId = roomTypeDao.GetRoomTypeIdByName("Single-Deluxe-Private Bathroom");
                    var ratePlanId = ratePlanDao.GetBaseRatePlanIdByRoomTypeId(roomTypeId);

                    var rate = new RateCache
                        {
                            RoomTypeId = roomTypeId,
                            RatePlanId = ratePlanId,
                            Date = DateTime.UtcNow.Date,
                            Rate = new decimal(10),
                            MinStay = 1
                        };

                    //Act
                    rateCacheDao.CreateDateRate(rate);

                    // Assert
                    Assert.IsNotNull(rate.DateRateId, "Date rate was not created successfully.");
                }
            }
Beispiel #8
0
        /// <summary>
        /// Create RatePlanDateRate 
        /// </summary>
        /// <param name="rate">The rate to create</param>
        public void CreateDateRate(RateCache rate)
        {
            const string SQL_STATEMENT = @"
                INSERT INTO Pricing.RatePlanDateRate
                (
                        RoomTypeId,
                        RatePlanId,
                        Date,
                        Amount,
                        MinStay,
                        UpdatedByUserId
                )
                VALUES
                (
                        @RoomTypeId,
                        @RatePlanId,
                        @Date,
                        @Rate,
                        @MinStay,
                        @UpdatedByUserId
                )
                SELECT @Id = SCOPE_IDENTITY()";

            var parameters = new List<SqlParameter>
                {
                DbHelper.CreateParameter(RateCacheMapper.Parameters.RoomTypeId, rate.RoomTypeId),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.RatePlanId, rate.RatePlanId),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.Date, rate.Date),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.Rate, rate.Rate),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.MinStay, rate.MinStay)
                };

            
            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);
            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(RateCacheMapper.Parameters.Id, SqlDbType.Int));

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
            rate.DateRateId = DbHelper.ParameterValue<int>(outputKey);
        }
Beispiel #9
0
        /// <summary>
        /// Modify RatePlanDateRate
        /// </summary>
        /// <param name="rateId">The id of the date rate record to modify</param>
        /// <param name="rate">The rate to modify</param>
        public void ModifyDateRate(int rateId, RateCache rate)
        {
            const string SQL_STATEMENT = @"
                UPDATE Pricing.RatePlanDateRate
                SET    Amount = @Rate,
                       MinStay = @MinStay,
                       UpdatedByUserId = @UpdatedByUserId
                WHERE  Id = @Id";

            var parameters = new List<SqlParameter>
                {
                DbHelper.CreateParameter(RateCacheMapper.Parameters.Id, rateId),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.Rate, rate.Rate),
                DbHelper.CreateParameter(RateCacheMapper.Parameters.MinStay, rate.MinStay)
                };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            int rowsAffected = DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);

            // Check if the update was successful
            if (rowsAffected == 0)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30027, "RateCacheDao.ModifyDateRate",
                        additionalDescriptionParameters: (new object[] { rate.GetType().Name, rateId }),
                        arguments: new object[] { rate.GetType().Name, rateId }));
            }
        }
Beispiel #10
0
        /// <summary>
        /// Assign and return rates for a Daily Rate
        /// </summary>
        /// <param name="dailyRate">End Date</param>
        /// <returns>RatesRestrictionsDateRangeEntry object</returns>
        private AvailStatusMessageType GetRestrictionRates(RateCache dailyRate, AvailabilityStatusType status = AvailabilityStatusType.Open)
        {
            if (dailyRate.MinStay == 0)
            {
                Logger.LogError("Minimum booking duration is invalid. It is set as 0 for room type id {0}, date {1} ", null, null, dailyRate.ProductId, dailyRate.Date);
            }

            var availStatusMessageType = new AvailStatusMessageType();


            availStatusMessageType.StatusApplicationControl = new StatusApplicationControlType
            {
                InvTypeCode = dailyRate.RoomTypeId.ToString(),
                RatePlanCode = dailyRate.RatePlanId.ToString(),
                Start = dailyRate.Date.ToString(Formats.UNIVERSAL_SHORT_DATE),
                End = dailyRate.Date.ToString(Formats.UNIVERSAL_SHORT_DATE),
            };
            availStatusMessageType.RestrictionStatus = new AvailStatusMessageTypeRestrictionStatus
            {
                Status = status,
                StatusSpecified = true
            };

            availStatusMessageType.LengthsOfStay = new LengthsOfStayType()
            {
                    ArrivalDateBased = true,
                    ArrivalDateBasedSpecified = true
            };
            availStatusMessageType.LengthsOfStay.LengthOfStay = new LengthsOfStayTypeLengthOfStay[1];
            availStatusMessageType.LengthsOfStay.LengthOfStay[0] = new LengthsOfStayTypeLengthOfStay
            {
                MinMaxMessageType =
                    LengthsOfStayTypeLengthOfStayMinMaxMessageType
                    .SetMinLOS,
                MinMaxMessageTypeSpecified = true,
                Time = dailyRate.MinStay.ToString(),
                
            };

            return availStatusMessageType;
        }
Beispiel #11
0
            public void OverrideRatesWithInvalidRateAndMinStayThrowsException()
            {
                // Arrange
                var rateCacheDaoMock = MockRepository.GenerateMock<IRateCacheDao>();

                rateCacheManager.RateCacheDao = rateCacheDaoMock;

                var rate = new RateCache
                {
                    Rate = new decimal(0),
                    MinStay = 1,
                    Override = true
                };

                var productType = new ProductType
                {
                    Rates = new List<RateCache> { rate }
                };
                
                // Act
                rateCacheManager.OverrideRates(productType);

                Assert.Fail("No exception was thrown.");
            }
Beispiel #12
0
            public void OverrideRatesNotSetToOverrideDoesNotCallMethods()
            {
                // Arrange
                const long BUSINESS_ID = 1;
                const int ROOM_TYPE_ID = 1;
                const int RATE_PLAN_ID = 1;

                var rateCacheDaoMock = MockRepository.GenerateMock<IRateCacheDao>();
                var eventTrackingManagerMock = MockRepository.GenerateMock<IEventTrackingManager>();

                rateCacheManager.RateCacheDao = rateCacheDaoMock;
                rateCacheManager.EventTrackingManager = eventTrackingManagerMock;

                var rate = new RateCache
                {
                    RoomTypeId = ROOM_TYPE_ID,
                    RatePlanId = RATE_PLAN_ID,
                    Date = DateTime.UtcNow.Date,
                    Rate = new decimal(10),
                    MinStay = 1,
                    Override = false
                };

                var productType = new ProductType
                {
                    BusinessId = BUSINESS_ID,
                    Rates = new List<RateCache> { rate }
                };

                rateCacheDaoMock.Expect(dao => dao.GetDateRateId(rate)).Repeat.Never();
                rateCacheDaoMock.Expect(dao => dao.CreateDateRate(rate)).Repeat.Never();

                eventTrackingManagerMock.Expect(be => be.CreateBusinessEventAsync(Arg<long>.Is.Anything, Arg<BusinessEventTypesEnum>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();

                // Act
                rateCacheManager.OverrideRates(productType);

                // Assert
                rateCacheDaoMock.VerifyAllExpectations();
                eventTrackingManagerMock.VerifyAllExpectations();
            }
Beispiel #13
0
            public void OverrideExistingRatesCallsCorrectMethods()
            {
                // Arrange
                const long BUSINESS_ID = 1;
                const int ROOM_TYPE_ID = 1;
                const int RATE_PLAN_ID = 1;
                const int DATE_RATE_ID = 1;

                var rateCacheDaoMock = MockRepository.GenerateMock<IRateCacheDao>();
                var eventTrackingManagerMock = MockRepository.GenerateMock<IEventTrackingManager>();

                rateCacheManager.RateCacheDao = rateCacheDaoMock;
                rateCacheManager.EventTrackingManager = eventTrackingManagerMock;

                var rate = new RateCache
                {
                    RoomTypeId = ROOM_TYPE_ID,
                    RatePlanId = RATE_PLAN_ID,
                    Date = DateTime.UtcNow.Date,
                    Rate = new decimal(10),
                    MinStay = 1,
                    Override = true
                };

                var productType = new ProductType
                {
                    BusinessId = BUSINESS_ID,
                    Rates = new List<RateCache> { rate }
                };

                rateCacheDaoMock.Expect(dao => dao.GetDateRateId(rate)).Return(DATE_RATE_ID);
                rateCacheDaoMock.Expect(dao => dao.ModifyDateRate(DATE_RATE_ID, rate));

                eventTrackingManagerMock.Expect(be => be.CreateBusinessEvent(Arg<long>.Is.Anything, Arg<BusinessEventTypesEnum>.Matches(ev => ev == BusinessEventTypesEnum.RatePlanOverrideModified), Arg<string>.Is.Anything, Arg<string>.Is.Anything));

                // Act
                rateCacheManager.OverrideRates(productType);

                // Assert
                rateCacheDaoMock.VerifyAllExpectations();
                eventTrackingManagerMock.VerifyAllExpectations();
            }
Beispiel #14
0
        /// <summary>
        /// Get rates amount
        /// </summary>
        /// <param name="dailyRate">daily RateCache</param>
        /// <param name="numberOfGuests">the number of guests for the rate plan.</param>
        /// <returns>RateAmountMessageType</returns>
        private RateAmountMessageType GetRatesAmount(RateCache dailyRate, int numberOfGuests)
        {
            if (dailyRate.MinStay == 0)
            {
                Logger.LogError(string.Format("Minimum booking duration is invalid. It is set as 0 for room type id {0}, date {1} ", dailyRate.ProductId, dailyRate.Date));
            }

            var rateAmountMessage = new RateAmountMessageType();

            rateAmountMessage.StatusApplicationControl = new StatusApplicationControlType();
            rateAmountMessage.StatusApplicationControl.InvTypeCode = dailyRate.RoomTypeId.ToString();
            rateAmountMessage.StatusApplicationControl.RatePlanCode = dailyRate.RatePlanId.ToString();
            rateAmountMessage.StatusApplicationControl.Start = dailyRate.Date.ToString(Formats.UNIVERSAL_SHORT_DATE);
            rateAmountMessage.StatusApplicationControl.End = dailyRate.Date.ToString(Formats.UNIVERSAL_SHORT_DATE);

            rateAmountMessage.Rates = new RateAmountMessageTypeRate[1];
            rateAmountMessage.Rates[0] = new RateAmountMessageTypeRate();
            rateAmountMessage.Rates[0].MinLOS = dailyRate.MinStay.ToString();
            rateAmountMessage.Rates[0].BaseByGuestAmts = new RateUploadTypeBaseByGuestAmt[1];
            rateAmountMessage.Rates[0].BaseByGuestAmts[0] = new RateUploadTypeBaseByGuestAmt();
            rateAmountMessage.Rates[0].BaseByGuestAmts[0].AmountAfterTax = dailyRate.Rate;
            rateAmountMessage.Rates[0].BaseByGuestAmts[0].AmountAfterTaxSpecified = true;
            rateAmountMessage.Rates[0].BaseByGuestAmts[0].DecimalPlaces = "0";
            rateAmountMessage.Rates[0].BaseByGuestAmts[0].CurrencyCode = dailyRate.CurrencyCode;
            rateAmountMessage.Rates[0].BaseByGuestAmts[0].NumberOfGuests = numberOfGuests.ToString();

            return rateAmountMessage;
        }