Exemplo n.º 1
0
            public void CreateVariantRatePlanPopulatesRatePlanId()
            {
                // Arrange
                // Create rate plan
                var variantRatePlan = new VariantRatePlan
                {
                    Name = "Test",
                    BusinessId = 1,
                    RoomTypeId = 1,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Variant },
                    MaxOccupancy = 2,
                    MaxAdults = 2,
                    MaxChildren = 1,
                    BoardBasis = new EnumEntity { Code = BoardBasisTypeEnum.BreakfastIncluded.GetCode() },
                    CancellationClass = new EnumEntity { Code = CancellationClassTypeEnum.NoRefund.GetCode() },
                    CurrencyCode = "GBP",
                    VariantAmount = 10,
                    VariantType = new VariantType { Type = VariantTypeEnum.Amount },
                    ApplicableDays = "1111111"
                };

                // Act
                variantRatePlanDao.Create(variantRatePlan);

                // Assert
                // Check if the rate plan id is attributed
                Assert.IsNotNull(variantRatePlan.Id, "The rate plan id was not attributed.");
            }
Exemplo n.º 2
0
        /// <summary>
        /// Map the basic fields for the VariantRatePlan table to the VariantRatePlan model object
        /// </summary>
        /// <param name="record">The SqlDataReader with the executed query result</param>
        /// <param name="prefix">a prefix used to identify fields for the VariantRatePlan model  in the resultset if required</param>        
        /// <returns>An instance of Model.Pricing.VariantRatePlan</returns>
        internal static VariantRatePlan MapRecord(IDataRecord record, string prefix = "")
        {
            var ratePlan = new VariantRatePlan();

            RatePlanMapper.MapRecord(record, ratePlan, prefix);

            ratePlan.Name = DbHelper.ConvertValue<string>(record[prefix + Parameters.Name]);
            ratePlan.PeriodId = DbHelper.ConvertValue<int?>(record[prefix + Parameters.PeriodId]);
            ratePlan.MinStay = DbHelper.ConvertValue<int?>(record[prefix + Parameters.MinStay]);
            ratePlan.ApplicableDays = DbHelper.ConvertValue<string>(record[prefix + Parameters.ApplicableDays]);
            ratePlan.VariantType = VariantTypeMapper.MapRecord(record, Parameters.VariantType.ToString());
            ratePlan.VariantAmount = DbHelper.ConvertValue<decimal>(record[prefix + Parameters.VariantAmount]);
            ratePlan.ApplyToAllPeriods = DbHelper.ConvertValue<bool>(record[prefix + Parameters.ApplyToAllPeriods]);
            ratePlan.VariantRatePlanRateId = DbHelper.ConvertValue<int>(record[prefix + Parameters.VariantRatePlanRateId]);
            ratePlan.Period = PeriodMapper.MapRecord(record, "Period");
            return ratePlan;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set rates on variant rate plan
        /// </summary>
        /// <param name="varRate">RatePlanRate</param>
        /// <param name="variantRatePlan">VariantRatePlan</param>
        private void SetOccupantVariantRates(RatePlanRate varRate, VariantRatePlan variantRatePlan)
        {
            var variantType = variantRatePlan.VariantType.Type;
            var variantAmount = variantRatePlan.VariantAmount;

            varRate.MonRate = CalculateVariantRate(variantType, varRate.MonRate.HasValue ? varRate.MonRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[0], true);
            varRate.TueRate = CalculateVariantRate(variantType, varRate.TueRate.HasValue ? varRate.TueRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[1], true);
            varRate.WedRate = CalculateVariantRate(variantType, varRate.WedRate.HasValue ? varRate.WedRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[2], true);
            varRate.ThuRate = CalculateVariantRate(variantType, varRate.ThuRate.HasValue ? varRate.ThuRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[3], true);
            varRate.FriRate = CalculateVariantRate(variantType, varRate.FriRate.HasValue ? varRate.FriRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[4], true);
            varRate.SatRate = CalculateVariantRate(variantType, varRate.SatRate.HasValue ? varRate.SatRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[5], true);
            varRate.SunRate = CalculateVariantRate(variantType, varRate.SunRate.HasValue ? varRate.SunRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[6], true);
            variantRatePlan.Rates = varRate;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set rates on variant rate plan
        /// </summary>
        /// <param name="varRate">RatePlanRate</param>
        /// <param name="variantRatePlan">VariantRatePlan</param>
        private void SetVariantRates(RatePlanRate varRate, VariantRatePlan variantRatePlan)
        {
            var variantType = variantRatePlan.VariantType.Type;
            var variantAmount = variantRatePlan.VariantAmount;

            varRate.MonRate = CalculateVariantRate(variantType, varRate.MonRate.HasValue ? varRate.MonRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[0]);
            varRate.MonMinStay = variantRatePlan.MinStay.HasValue && varRate.MonRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.TueRate = CalculateVariantRate(variantType, varRate.TueRate.HasValue ? varRate.TueRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[1]);
            varRate.TueMinStay = variantRatePlan.MinStay.HasValue && varRate.TueRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.WedRate = CalculateVariantRate(variantType, varRate.WedRate.HasValue ? varRate.WedRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[2]);
            varRate.WedMinStay = variantRatePlan.MinStay.HasValue && varRate.WedRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.ThuRate = CalculateVariantRate(variantType, varRate.ThuRate.HasValue ? varRate.ThuRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[3]);
            varRate.ThuMinStay = variantRatePlan.MinStay.HasValue && varRate.ThuRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.FriRate = CalculateVariantRate(variantType, varRate.FriRate.HasValue ? varRate.FriRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[4]);
            varRate.FriMinStay = variantRatePlan.MinStay.HasValue && varRate.FriRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.SatRate = CalculateVariantRate(variantType, varRate.SatRate.HasValue ? varRate.SatRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[5]);
            varRate.SatMinStay = variantRatePlan.MinStay.HasValue && varRate.SatRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.SunRate = CalculateVariantRate(variantType, varRate.SunRate.HasValue ? varRate.SunRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[6]);
            varRate.SunMinStay = variantRatePlan.MinStay.HasValue && varRate.SunRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            variantRatePlan.Rates = varRate;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set the default period on a variant rate plan when the period is not set 
        /// <param name="variantRatePlan">Culture Code</param>
        private void SetVariantDefaultPeriod(VariantRatePlan variantRatePlan, string cultureCode)
        {

            if (variantRatePlan.PeriodId == null)
            {
                variantRatePlan.Periods = new List<VariantRatePlanPeriod>() { new VariantRatePlanPeriod { Id = 0, Name = dictionaryDao.GetItemByKey(EVERGREEN_PERIOD_NAME, cultureCode) } };
            }
        }
Exemplo n.º 6
0
            public void CreateRatePlanAsVariantPopulatesRatePlanId()
            {
                // Arrange
                // Create rate plan
                var ratePlan = new VariantRatePlan
                {
                    BusinessId = 1,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Variant }
                };

                // Act
                ratePlanDao.Create(ratePlan);

                // Assert
                // Check if the rate plan id is attributed
                Assert.IsNotNull(ratePlan.Id, "The rate plan id was not attributed.");
            }
Exemplo n.º 7
0
            public void ModifyVariantRatePlanNoIdThrowsException()
            {
                // Arrange
                var businessEventDao = MockRepository.GenerateMock<IBusinessEventDao>();
                var variantRatePlanDao = MockRepository.GenerateStrictMock<IVariantRatePlanDao>();
                var mockOfRatePlanManager = MockRepository.GeneratePartialMock<RatePlanManager>();
                mockOfRatePlanManager.BusinessEventDao = businessEventDao;
                mockOfRatePlanManager.VariantRatePlanDao = variantRatePlanDao;

                const int RATE_PLAN_ID = 1;
                const long BUSINESS_ID = 1;
                const int RATE_PLAN_RATE_ID = 5;

                mockOfRatePlanManager.Expect(
                    rtm => rtm.ModifyRatePlanRates(Arg<RatePlanRate>.Matches(rpr => rpr.Id == RATE_PLAN_RATE_ID), Arg<bool>.Is.Anything))
                                     .Return(new RatePlanRate { Id = RATE_PLAN_RATE_ID })
                                     .Repeat.Never();

                var ratePlan = new VariantRatePlan { BusinessId = BUSINESS_ID, RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Variant }, Rates = new RatePlanRate { Id = RATE_PLAN_RATE_ID } };

                variantRatePlanDao.Expect(rp => rp.Modify(Arg<VariantRatePlan>.Matches(vpr => vpr.Id == RATE_PLAN_ID && vpr.BusinessId == BUSINESS_ID))).Repeat.Never();

                businessEventDao.Expect(be => be.Create(Arg<BusinessEvent>.Matches(ev => ev.BusinessId == BUSINESS_ID && ev.EventType.Code == BusinessEventTypesEnum.RatePlanModified.GetCode() && ev.Reference == ratePlan.Id.ToString(CultureInfo.InvariantCulture)))).Repeat.Never();

                try
                {
                    // Act
                    mockOfRatePlanManager.ModifyVariantRatePlan(ratePlan);

                    // Assert
                    Assert.Fail("Validation exception was not thrown");
                }
                catch (ValidationException vex)
                {
                    Assert.AreEqual(Errors.SRVEX30098.ToString(), vex.Code, "Incorrect validation exception was thrown");
                    variantRatePlanDao.VerifyAllExpectations();
                    businessEventDao.VerifyAllExpectations();
                    mockOfRatePlanManager.VerifyAllExpectations();
                }
            }
Exemplo n.º 8
0
        /// <summary>
        /// Modify a particular variant rate plan
        /// </summary>
        /// <param name="ratePlan">Variant Rate plan</param>
        /// <returns>Modified rate plan</returns>
        public virtual VariantRatePlan ModifyVariantRatePlan(VariantRatePlan ratePlan)
        {
            if (ratePlan == null)
            {
                return null;
            }

            if (ratePlan.Id == default(int))
            {
                // can't modify with bad id
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30098, "RoomTypeManager.ModifyVariantRatePlan", arguments: new object[] { ratePlan }));
            }

            using (var tx = new BusinessTransaction())
            {
                variantRatePlanDao.Modify(ratePlan);

                //modify rate plan rates for rate plan here. 
                ratePlan.Rates = ModifyRatePlanRates(ratePlan.Rates, false);

                tx.Commit();
            }

            // events will need data in future
            eventTrackingManager.CreateBusinessEventAsync(ratePlan.BusinessId, BusinessEventTypesEnum.VariantRatePlanModified, ratePlan.Id.ToString(CultureInfo.InvariantCulture));

            // Invalidate the cache so it refreshes
            Cache.Cache.RatePlanViewCache.Invalidate(ratePlan.BusinessId);

            return ratePlan;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates just the rates for a particular variant rate plan
        /// </summary>
        /// <param name="ratePlan">Rate plan</param>
        /// <returns>created rate plan with rates</returns>
        public VariantRatePlan CreateVariantRatePlanRate(VariantRatePlan ratePlan)
        {
            if (ratePlan == null)
            {
                return null;
            }

            using (var tx = new BusinessTransaction())
            {
                variantRatePlanDao.CreateVariantRatePlanRate(ratePlan);

                tx.Commit();
            }
            
            eventTrackingManager.CreateBusinessEventAsync(ratePlan.BusinessId, BusinessEventTypesEnum.VariantRatePlanRateAdded, ratePlan.VariantRatePlanRateId.ToString(CultureInfo.InvariantCulture));

            return ratePlan;
        }
Exemplo n.º 10
0
            public void DeleteRatePlanExpectdVariantRatePlanRemoved()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                var ratePlanToDelete = new VariantRatePlan
                {
                    Name = "Test",
                    BusinessId = BUSINESS_ID,
                    RoomTypeId = 1,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Variant },
                    MaxOccupancy = 2,
                    MaxAdults = 2,
                    MaxChildren = 1,
                    BoardBasis = new EnumEntity { Code = BoardBasisTypeEnum.BreakfastIncluded.GetCode() },
                    CancellationClass = new EnumEntity { Code = CancellationClassTypeEnum.NoRefund.GetCode() },
                    CurrencyCode = "GBP",
                    VariantAmount = 10,
                    VariantType = new VariantType { Type = VariantTypeEnum.Amount },
                    ApplicableDays = Constants.FULL_AVAILABILITY
                };

                variantRatePlanDao.Create(ratePlanToDelete);
                variantRatePlanDao.CreateVariantRatePlanRate(ratePlanToDelete);

                Assert.IsNotNull(ratePlanToDelete, "RatePlan should have been created");
                Assert.IsTrue(ratePlanToDelete.VariantRatePlanRateId != default(int), "RatePlanRate should have been created");
           
                // Act
                var deleteResult = variantRatePlanDao.DeleteVariantRatePlan(ratePlanToDelete.Id);

                // Assert
                Assert.IsTrue(deleteResult,"Expect deletion outcome to be true for successful deletion");
                VariantRatePlan ratePlan = variantRatePlanDao.GetByBusinessId(BUSINESS_ID).First();
                Assert.IsNotNull(ratePlan,"Expect VariantRatePlan to be present ");
                Assert.IsTrue(ratePlan.VariantRatePlanRateId != default(int), "Expect VariantRatePlan rates to be present");
            }
Exemplo n.º 11
0
            public void CreateVariantRatePlanRateWithNonExistingVariantRatePlanExpectExceptionThrown()
            {
                // Arrange
                var variantRatePlan = new VariantRatePlan() {Id = 0};
                
                // Act
                variantRatePlanDao.CreateVariantRatePlanRate(variantRatePlan);

            }
Exemplo n.º 12
0
            public void CreateVariantRatePlanRatePopulatesVariantRatePlanRateId()
            {
                // Arrange
                var variantRatePlan = new VariantRatePlan
                {
                    Name = "Test",
                    BusinessId = 1,
                    RoomTypeId = 1,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Variant },
                    MaxOccupancy = 2,
                    MaxAdults = 2,
                    MaxChildren = 1,
                    BoardBasis = new EnumEntity { Code = BoardBasisTypeEnum.BreakfastIncluded.GetCode() },
                    CancellationClass = new EnumEntity { Code = CancellationClassTypeEnum.NoRefund.GetCode() },
                    CurrencyCode = "GBP",
                    VariantAmount = 10,
                    VariantType = new VariantType { Type = VariantTypeEnum.Amount },
                    ApplicableDays = Constants.FULL_AVAILABILITY
                };

                variantRatePlanDao.Create(variantRatePlan);

                // Act
                variantRatePlanDao.CreateVariantRatePlanRate(variantRatePlan);

                // Assert
                Assert.IsTrue(variantRatePlan.VariantRatePlanRateId !=  default(int));
            }
Exemplo n.º 13
0
            public void UpsertPromotionRatePlanLinksCallsMethodsCorrectly()
            {
                var existingPromotions = new List<Model.Pricing.Promotions.Promotion>
                    {
                        new Promotion
                        {
                            Id = 1,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID,
                                RATEPLAN_ID + 1
                            }
                        },
                        new Promotion
                        {
                            Id = 2,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID + 1
                            }
                        },
                        new Promotion
                        {
                            Id = 3,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID,
                                RATEPLAN_ID + 2
                            }
                        },
                    };

                var ratePlan = new VariantRatePlan
                {
                    BusinessId = BUSINESS_ID,
                    Id = RATEPLAN_ID,
                    AssociatedPromotions = new List<Model.Pricing.Promotions.Promotion>
                    {
                        new Promotion
                        {
                            Id = 2,
                            BusinessId = BUSINESS_ID,
                            AssociatedRatePlanIds = new List<int>
                            {
                                RATEPLAN_ID,
                                RATEPLAN_ID + 1
                            }
                        }
                    }
                };

                var promotionDaoMock = new Mock<IPromotionDao>();
                promotionDaoMock.Setup(p => p.DeletePromoLinks(ratePlan.Id, It.Is<IEnumerable<int>>(i => i.Any(x => x == 1 || x == 3))));
                promotionDaoMock.Setup(p => p.CreateRatePlanLinks(It.Is<List<PromotionRatePlanLink>>(prpl => prpl.Any(x => x.PromotionId == 2 && x.RatePlanId == RATEPLAN_ID))));

                var promotionManager = new PromotionManager();
                promotionManager.PromotionDao = promotionDaoMock.Object;
                Helpers.CacheHelper.StubPromoCacheWithPromotions(BUSINESS_ID, existingPromotions);
                Cache.PromoCache.Invalidate();

                promotionManager.UpsertPromotionRatePlanLinks(ratePlan);

                promotionDaoMock.VerifyAll();
                Helpers.CacheHelper.ReAssignPromotionDaoToPromoCache();
            }
Exemplo n.º 14
0
            public void CreateEditVariantRatePlansWithInvalidVariantAmountThrowsException()
            {
                // Arrange
                const int variantRatePlanId = 1;
                const int variantRatePlanRateId = 0;
                const int roomTypeId = 1;
                const long businessId = 1;
                const int baseRatePlanId = 1;
                const decimal rackRate = 30;
                const decimal rate = 40;
                const decimal variantRate = -50;

                var baseRatePlanDao = new Mock<IBaseRatePlanDao>();
                var baseRatePlanRatesDao = new Mock<IBaseRatePlanRatesDao>();

                var variantRatePlan = new VariantRatePlan { Id = variantRatePlanId, VariantRatePlanRateId = variantRatePlanRateId, RoomTypeId = roomTypeId, BusinessId = businessId, VariantType = new VariantType { Type = VariantTypeEnum.Amount }, VariantAmount = variantRate };
                var baseRatePlan = new BaseRatePlan { Id = baseRatePlanId, SellAtRackRate = true, RackRate = rackRate };
                var ratePlanRate = new RatePlanRate { MonRate = rate, TueRate = rate, WedRate = rate, ThuRate = rate, FriRate = rate, SatRate = rate, SunRate = rate };

                var ratePlanManager = new RatePlanManager
                {
                    BaseRatePlanDao = baseRatePlanDao.Object,
                    BaseRatePlanRatesDao = baseRatePlanRatesDao.Object
                };

                baseRatePlanDao.Setup(brp => brp.GetByRoomTypeId(roomTypeId, businessId, string.Empty)).Returns(baseRatePlan);
                baseRatePlanRatesDao.Setup(brp => brp.GetByRatePlanId(baseRatePlanId)).Returns(new List<RatePlanRate> { ratePlanRate });
                
                try
                {
                    // Act
                    ratePlanManager.CreateEditVariantRatePlans(new List<VariantRatePlan> { variantRatePlan });

                    // Assert
                    Assert.Fail("Validation exception was not thrown");
                }
                catch (ValidationException vex)
                {
                    Assert.AreEqual(Errors.SRVEX30142.ToString(), vex.Code, "Incorrect validation exception was thrown");
                }
            }
Exemplo n.º 15
0
            public void CreateEditVariantRatePlansForExistingRatePlanAndSelectedSeasonExpectRatePlanModified()
            {
                // Arrange
                const int variantRatePlanId = 1;
                const int variantRatePlanRateId = 0;
                const int roomTypeId = 1;
                const long businessId = 1;
                const int baseRatePlanId = 1;
                const decimal rackRate = 30;
                const decimal rate = 40;

                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var variantRatePlanDao = new Mock<IVariantRatePlanDao>();
                var baseRatePlanDao = new Mock<IBaseRatePlanDao>();
                var baseRatePlanRatesDao = new Mock<IBaseRatePlanRatesDao>();
                var promotionManagerMock = new Mock<IPromotionManager>();

                var variantRatePlan = new VariantRatePlan { Id = variantRatePlanId, VariantRatePlanRateId = variantRatePlanRateId, RoomTypeId = roomTypeId, BusinessId = businessId, VariantType = new VariantType { Type = VariantTypeEnum.Percentage } };
                var baseRatePlan = new BaseRatePlan { Id = baseRatePlanId, SellAtRackRate = true, RackRate = rackRate };
                var ratePlanRate = new RatePlanRate { MonRate = rate, TueRate = rate, WedRate = rate, ThuRate = rate, FriRate = rate, SatRate = rate, SunRate = rate };
                
                var ratePlanManager = new RatePlanManager
                    {
                        EventTrackingManager = eventTrackingManager.Object,
                        VariantRatePlanDao = variantRatePlanDao.Object,
                        BaseRatePlanDao = baseRatePlanDao.Object,
                        BaseRatePlanRatesDao = baseRatePlanRatesDao.Object,
                        PromotionManager = promotionManagerMock.Object
                    };

                baseRatePlanDao.Setup(brp => brp.GetByRoomTypeId(roomTypeId, businessId, string.Empty)).Returns(baseRatePlan);
                baseRatePlanRatesDao.Setup(brp => brp.GetByRatePlanId(baseRatePlanId)).Returns(new List<RatePlanRate> { ratePlanRate });
                promotionManagerMock.Setup(pr => pr.UpsertPromotionRatePlanLinks(It.IsAny<RatePlan>()));

                variantRatePlanDao.Setup(vrp => vrp.Modify(variantRatePlan));

                eventTrackingManager.Setup(e => e.CreateBusinessEventAsync(It.IsAny<long>(), It.IsAny<BusinessEventTypesEnum>(), It.IsAny<string>(), null));
               
                // Act 
                ratePlanManager.CreateEditVariantRatePlans(new List<VariantRatePlan> { variantRatePlan });

                // Assert
                variantRatePlanDao.VerifyAll();
                eventTrackingManager.Verify(e => e.CreateBusinessEventAsync(It.IsAny<long>(), BusinessEventTypesEnum.VariantRatePlanModified, It.IsAny<string>(), null), Times.Once);
                baseRatePlanDao.VerifyAll();
                promotionManagerMock.Verify(pr => pr.UpsertPromotionRatePlanLinks(It.IsAny<RatePlan>()), Times.AtLeastOnce());
            }
Exemplo n.º 16
0
        /// <summary>
        ///  Create default Adult or Child VariantRataPlans for PerPerson pricing
        /// </summary>
        /// <param name="variantRatePlan">VariantRatePlan</param>
        /// <param name="cultureCode">CultureCode</param>
        /// <param name="occupancyRateType">OccupancyRateType</param>
        /// <returns>VariantRatePlan</returns>
       private VariantRatePlan GetDefaultOccupantVariantPerPersonRatePlan(VariantRatePlan variantRatePlan, string cultureCode,OccupancyRateType occupancyRateType)
       {
           var createdRatePlan = CloneVariantRatePlan(variantRatePlan);
           createdRatePlan.UseOccupancyRates = true;
           createdRatePlan.VariantRatePlanRateId = 0;
           createdRatePlan.Rates.OccupancyRateType = occupancyRateType;
           SetVariantDefaultPeriod(createdRatePlan, cultureCode);
           return createdRatePlan;

       }
Exemplo n.º 17
0
        /// <summary>
        /// Creates just the variant rate plan
        /// </summary>
        /// <param name="ratePlan">Rate plan</param>
        /// <returns>created rate plan with id</returns>
        public VariantRatePlan CreateVariantRatePlan(VariantRatePlan ratePlan)
        {
            if (ratePlan == null)
            {
                return null;
            }

            using (var tx = new BusinessTransaction())
            {
                variantRatePlanDao.Create(ratePlan);

                tx.Commit();
            }

            eventTrackingManager.CreateBusinessEventAsync(ratePlan.BusinessId, BusinessEventTypesEnum.VariantRatePlanAdded, ratePlan.Id.ToString(CultureInfo.InvariantCulture));

            // Invalidate the cache so it refreshes
            Cache.Cache.RatePlanViewCache.Invalidate(ratePlan.BusinessId);

            return ratePlan;
        }
Exemplo n.º 18
0
            public void CreateRatePlanWithInvalidRoomTypeIdThrowsException()
            {
                // Arrange
                // Create rate plan
                var ratePlan = new VariantRatePlan
                {
                    Name = "Test",
                    BusinessId = 1,
                    RoomTypeId = 11,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base },
                    MaxOccupancy = 2,
                    MaxAdults = 2,
                    MaxChildren = 1,
                    BoardBasis = new EnumEntity { Code = BoardBasisTypeEnum.BreakfastIncluded.GetCode() },
                    CancellationClass = new EnumEntity { Code = CancellationClassTypeEnum.NoRefund.GetCode() },
                    CurrencyCode = "GBP",
                    VariantAmount = 10,
                    VariantType = new VariantType { Type = VariantTypeEnum.Amount },
                    ApplicableDays = Constants.FULL_AVAILABILITY
                };

                // Act
                variantRatePlanDao.Create(ratePlan);
            }
Exemplo n.º 19
0
        /// <summary>
        /// Creates variant rate plan and rates for a particular variant rate plan
        /// </summary>
        /// <param name="ratePlan">Rate plan</param>
        /// <returns>created rate plan with rates created</returns>
        public VariantRatePlan CreateVariantRatePlanAndRates(VariantRatePlan ratePlan)
        {
            if (ratePlan == null)
            {
                return null;
            }

            using (var tx = new BusinessTransaction())
            {
                CreateVariantRatePlan(ratePlan);
                CreateVariantRatePlanRate(ratePlan);

                tx.Commit();
            }

            return ratePlan;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create a copy of a specified VariantRatePlan
        /// </summary>
        /// <param name="variantRatePlan">Variant rate plan</param>
        /// <returns>Return copy of variant rate plan</returns>
        private static VariantRatePlan CloneVariantRatePlan(VariantRatePlan variantRatePlan)
        {
            if (variantRatePlan == null)
            {
                throw new ArgumentNullException("variantRatePlan");
            }

            return new VariantRatePlan
            {
                Id = variantRatePlan.Id,
                RoomTypeId = variantRatePlan.RoomTypeId,
                RatePlanType = variantRatePlan.RatePlanType,
                MaxOccupancy = variantRatePlan.MaxOccupancy,
                MaxAdults = variantRatePlan.MaxAdults,
                MaxChildren = variantRatePlan.MaxChildren,
                BoardBasis = variantRatePlan.BoardBasis,
                CancellationClass = variantRatePlan.CancellationClass,
                RoomType = variantRatePlan.RoomType,
                CurrencyCode = variantRatePlan.CurrencyCode,
                BusinessId = variantRatePlan.BusinessId,
                ApplicableDays = variantRatePlan.ApplicableDays,
                ApplyToAllPeriods = variantRatePlan.ApplyToAllPeriods,
                Rates = variantRatePlan.Rates != null ? CloneRatePlanRates(variantRatePlan.Rates) : null,
                Name = variantRatePlan.Name,
                VariantType = variantRatePlan.VariantType,
                VariantAmount = variantRatePlan.VariantAmount,
                MinStay = variantRatePlan.MinStay,
                VariantRatePlanRateId = variantRatePlan.VariantRatePlanRateId,
                IsActive = variantRatePlan.IsActive,
                DisplayName = variantRatePlan.DisplayName
            };
        }
Exemplo n.º 21
0
            public void ModifyVariantRatePlanIsSuccessful()
            {
                // Arrange
                const int ratePlanId = 1;
                const long businessId = 1;
                const int ratePlanRateId = 5;

                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var variantRatePlanDao = new Mock<IVariantRatePlanDao>();
                
                var ratePlanManager = new RatePlanManager
                {
                    EventTrackingManager = eventTrackingManager.Object,
                    VariantRatePlanDao = variantRatePlanDao.Object
                };
                
                var ratePlan = new VariantRatePlan { BusinessId = businessId, Id = ratePlanId, RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Variant }, Rates = new RatePlanRate { Id = ratePlanRateId, RatePlanId = ratePlanId } };

                variantRatePlanDao.Setup(rp => rp.Modify(ratePlan));

                eventTrackingManager.Setup(e => e.CreateBusinessEventAsync(It.IsAny<long>(), It.IsAny<BusinessEventTypesEnum>(), It.IsAny<string>(), null));
                
                // Act
                ratePlanManager.ModifyVariantRatePlan(ratePlan);

                // Assert
                variantRatePlanDao.VerifyAll();
                eventTrackingManager.Verify(e => e.CreateBusinessEventAsync(It.IsAny<long>(), BusinessEventTypesEnum.VariantRatePlanModified, It.IsAny<string>(), null), Times.Once);
            }
Exemplo n.º 22
0
 /// <summary>
 /// Get the default rates for evergreen period for variant rate plan
 /// </summary>
 /// <param name="variantRatePlan">VariantRatePlan</param>
 private static RatePlanRate GetDefaultVariantEvergreenBaseRates(VariantRatePlan variantRatePlan)
 {
     return new RatePlanRate
     {
         MonRate = 0,
         MonMinStay = MIN_STAY,
         TueRate = 0,
         TueMinStay = MIN_STAY,
         WedRate = 0,
         WedMinStay = MIN_STAY,
         ThuRate = 0,
         ThuMinStay = MIN_STAY,
         FriRate = 0,
         FriMinStay = MIN_STAY,
         SatRate = 0,
         SatMinStay = MIN_STAY,
         SunRate = 0,
         SunMinStay = MIN_STAY,
         RatePlanId = variantRatePlan.Id
     };
 }
Exemplo n.º 23
0
            public void AssignAndGetPromotionsForVariantPlansGetsCorrectPromotions()
            {
                // Arrange
                VariantRatePlan variantOne = new VariantRatePlan
                    {
                        Id = RATEPLAN_ONE,
                        BusinessId = BUSINESS_ONE
                    };
                VariantRatePlan variantTwo = new VariantRatePlan
                    {
                        Id = RATEPLAN_THREE,
                        BusinessId = BUSINESS_ONE
                    };
                List<VariantRatePlan> ratePlans = new List<VariantRatePlan>
                    {
                        variantOne,
                        variantTwo
                    };

                // Act
                promotionManager.AssignAndGetPromotionsForRatePlans(ratePlans, BUSINESS_ONE);

                // Assert
                Assert.NotNull(variantOne.AssociatedPromotions, "associated promos not set for first variant");
                Assert.NotNull(variantTwo.AssociatedPromotions, "associated promos not set for second variant");
                Assert.IsTrue(variantOne.AssociatedPromotions.Any(p => p.Id == PROMO_ONE), "promo one should be assigned to the first rateplan");
                Assert.IsTrue(variantOne.AssociatedPromotions.Any(p => p.Id == PROMO_TWO) == false, "promo two should not be assigned to the first rateplan");
                Assert.IsTrue(variantTwo.AssociatedPromotions.Any(p => p.Id == PROMO_TWO), "promo two should be assigned to the second rateplan");
                Assert.IsTrue(variantTwo.AssociatedPromotions.Any(p => p.Id == PROMO_ONE) == false, "promo one should not be assigned to the second rateplan");

                CacheHelper.ReAssignPromotionDaoToPromoCache();
            }
Exemplo n.º 24
0
 /// <summary>
 /// Get null rates for a rate plan
 /// </summary>
 /// <param name="variantRatePlan">VariantRatePlan</param>
 private static RatePlanRate GetNulRates(VariantRatePlan variantRatePlan)
 {
     return new RatePlanRate
     {
         MonRate = null,
         MonMinStay = MIN_STAY,
         TueRate = null,
         TueMinStay = MIN_STAY,
         WedRate = null,
         WedMinStay = MIN_STAY,
         ThuRate = null,
         ThuMinStay = MIN_STAY,
         FriRate = null,
         FriMinStay = MIN_STAY,
         SatRate = null,
         SatMinStay = MIN_STAY,
         SunRate = null,
         SunMinStay = MIN_STAY,
         RatePlanId = variantRatePlan.Id
     };
 }