예제 #1
0
            public void CreateBaseRatePlanPopulatesRatePlanId()
            {
                // Arrange
                // Create rate plan
                var ratePlan = new BaseRatePlan
                {
                    BusinessId = 1,
                    RoomTypeId = 1,
                    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() },
                    RackRate = new decimal(12.4),
                    SellAtRackRate = true,
                    CurrencyCode = "GBP"
                };

                // Act
                baseRatePlanDao.Create(ratePlan);

                // Assert
                // Check if the rate plan id is attributed
                Assert.IsNotNull(ratePlan.Id, "The rate plan id was not attributed.");
            }
예제 #2
0
        /// <summary>
        /// Map the basic fields for the BaseRatePlan table to the BaseRatePlan 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 BaseRatePlan model  in the resultset if required</param>        
        /// <returns>An instance of Model.Pricing.BaseRatePlan</returns>
        internal static BaseRatePlan MapRecord(IDataRecord record, string prefix = "")
        {
            var ratePlan = new BaseRatePlan();

            RatePlanMapper.MapRecord(record, ratePlan, prefix);

            ratePlan.RackRate = DbHelper.ConvertValue<decimal>(record[prefix + Parameters.RackRate]);
            ratePlan.SellAtRackRate = DbHelper.ConvertValue<bool>(record[prefix + Parameters.SellAtRackRate]);
            ratePlan.UseOccupancyRates = DbHelper.ConvertValue<bool>(record[prefix + Parameters.UseOccupancyRates]);

            return ratePlan;
        }
예제 #3
0
            public void CreateRatePlanAsBasePopulatesRatePlanId()
            {
                // Arrange
                // Create rate plan
                var ratePlan = new BaseRatePlan
                {
                    BusinessId = 1,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base }
                };

                // Act
                ratePlanDao.Create(ratePlan);

                // Assert
                // Check if the rate plan id is attributed
                Assert.IsNotNull(ratePlan.Id, "The rate plan id was not attributed.");
            }
예제 #4
0
            public void SendRateAmountUpdateWithRatesListCallPPCGateway()
            {
                //Arrange
                const long businessId = 5002;
                const string businessShortname = "TestBus2";

                const int baseRatePlanId = 1;

                RoomType roomType = new RoomType();
                BaseRatePlan baseRatePlan = new BaseRatePlan();
                baseRatePlan.Id = baseRatePlanId;
                baseRatePlan.MaxOccupancy = 1;
                roomType.BaseRatePlan = baseRatePlan;
                
                var ppcGatewayMock = new Mock<IPPCGateway>();
                var roomTypeManagerStub = new Mock<IRoomTypeManager>();
                var rateCacheManagerStub = new Mock<IRateCacheManager>();

                rateCacheManagerStub.Setup(r => r.GetAllByRoomTypeAndRatePlanId(businessId, 1, baseRatePlanId, RatePlanTypeEnum.Unknown))
                    .Returns(new List<RateCache>()
                                 {
                                     new RateCache()
                                         {
                                             Rate = new decimal(1.0),
                                             Date = DateTime.Now,
                                             MinStay = 1
                                         }
                                 });


                roomTypeManagerStub.Setup(m => m.GetRoomType(1, businessId, ""))
                    .Returns(roomType); 

                var rateAmountUpdate = new RateAmountUpdate();
                rateAmountUpdate.PPCGateway = ppcGatewayMock.Object;
                rateAmountUpdate.RateCacheManager = rateCacheManagerStub.Object;
                rateAmountUpdate.RoomTypeManager = roomTypeManagerStub.Object;

                //Act
                rateAmountUpdate.SendRateAmountUpdate(businessShortname, businessId, 1, baseRatePlanId);

                //Assert
                ppcGatewayMock.Verify(g => g.Publish(It.IsAny<IPartitionable>()), Times.AtLeastOnce);
            }
예제 #5
0
        /// <summary>
        /// Get base adult/child rate plan from BaseRatePlanOccupantRate table
        /// </summary>
        /// <param name="baseRatePlanOccupantRate">BaseRatePlanOccupantRate</param>
        /// <param name="baseRatePlan">BaseRatePlan</param>
        /// <param name="baseRatePlanRate">RatePlanRate</param>
        /// <param name="roomTypeName">Name for RoomType</param>
        /// <param name="IsAdult">True if is Adult rate plan</param>
        /// <returns>Adult RatePlan</returns>
        private VariantRatePlan GetOccupantRatePlan(BaseRatePlanOccupantRate baseRatePlanOccupantRate, BaseRatePlan baseRatePlan, RatePlanRate baseRatePlanRate, string roomTypeName, bool IsAdult, OccupancyRateType occupancyRateType, bool fetchDateRanges = false)
        {
            var occupantRatePlan = CreateVariantFromBase(baseRatePlan, string.Concat(roomTypeName, " - ", baseRatePlanRate.PeriodId));

            //override the rates from the base with occupant rates
            occupantRatePlan.Rates = IsAdult ? GetAdultRate(baseRatePlanOccupantRate, baseRatePlanRate) : GetChildRate(baseRatePlanOccupantRate, baseRatePlanRate);
            occupantRatePlan.Period = baseRatePlanOccupantRate.Period;
            occupantRatePlan.PeriodId = baseRatePlanOccupantRate.PeriodId;//baseRatePlanOccupantRate.Period == null ? 0 : baseRatePlanOccupantRate.Period.Id;
            occupantRatePlan.RatePlanType = new RatePlanType() { Type = RatePlanTypeEnum.Base };
            occupantRatePlan.Rates.OccupancyRateType = occupancyRateType;

            if (fetchDateRanges &&
                occupantRatePlan.Period != null && occupantRatePlan.Period.Id != default(int) &&
                (occupantRatePlan.Period.PeriodDateRanges == null || !occupantRatePlan.Period.PeriodDateRanges.Any()))
            {
                occupantRatePlan.Period.PeriodDateRanges = periodDateRangeDao.GetAllByPeriodId(occupantRatePlan.Period.Id);
            }

            return occupantRatePlan;
        }
예제 #6
0
        /// <summary>
        /// Creates rates for a particular rate plan
        /// </summary>
        /// <param name="ratePlan">Rate plan</param>
        /// <returns>List of created rate plans</returns>
        public BaseRatePlan CreateBaseRatePlan(BaseRatePlan ratePlan)
        {
            if (ratePlan == null)
            {
                return null;
            }

            ratePlan.Rates.IsValid();

            //check if all elements have price 0 on every day
            CheckIfAllRatesHavePriceZero(ratePlan.Rates);
            //check if all elements have mlos 0 on every day
            CheckIfAllRatesHaveMLOSZero(ratePlan.Rates);

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

                if (ratePlan.Rates != null)
                {
                    ratePlan.Rates.RatePlanId = ratePlan.Id;
                    ratePlanRateDao.Create(ratePlan.Rates);

                }

                tx.Commit();
            }

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

            if (ratePlan.Rates != null)
            {
                eventTrackingManager.CreateBusinessEventAsync(ratePlan.BusinessId, BusinessEventTypesEnum.RatePlanRateAdded, ratePlan.Rates.Id.ToString(CultureInfo.InvariantCulture));

            }

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

            return ratePlan;
        }
예제 #7
0
 /// <summary>
 /// Create evergreen occupant rate plan from base rate plan
 /// </summary>
 /// <param name="baseRatePlan">BaseRatePlan</param>
 /// <param name="roomTypeName">RoomType name</param>
 /// <param name="cultureCode">Culture Code</param>
 /// <param name="isAdult">True if is Adult rate plan</param>
 /// <param name="occupancyRateType">OccupancyRateType</param>
 /// <returns>RatePlan</returns>
 private VariantRatePlan CreateEvergreenOccupantRatePlan(BaseRatePlan baseRatePlan, string roomTypeName, string cultureCode, bool isAdult, OccupancyRateType occupancyRateType)
 {
     var occupantRatePlan = CreateVariantFromBase(baseRatePlan, roomTypeName);
     SetDefaultPeriod(occupantRatePlan, cultureCode);
     occupantRatePlan.Id = 0;
     var occupantRatePlanRates = GetNulRates(occupantRatePlan);
     occupantRatePlan.Rates = occupantRatePlanRates;
     occupantRatePlan.Rates.Id = 0;
     occupantRatePlan.Rates.RatePlanId = baseRatePlan.Id;
     occupantRatePlan.RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base };
     occupantRatePlan.Rates.OccupancyRateType = occupancyRateType;
     occupantRatePlan.UseOccupancyRates = true;
     return occupantRatePlan;
 }
예제 #8
0
 /// <summary>
 ///  Create non evergreen occupant rate plan from base rate plan
 /// </summary>
 /// <param name="baseRatePlan">BaseRatePlan</param>
 /// <param name="roomTypeName">>RoomType name</param>
 /// <param name="ratePlanRate">RatePlanRate</param>
 /// <param name="period">Period</param>
 /// <param name="occupancyRateType">OccupancyRateType</param>
 /// <returns>RatePlan</returns>
 private VariantRatePlan CreateNonEvergreenOccupantRatePlan(BaseRatePlan baseRatePlan, string roomTypeName, RatePlanRate ratePlanRate, Period period, OccupancyRateType occupancyRateType)
 {
     var occupantRatePlan = CreateVariantFromBase(baseRatePlan, roomTypeName);
     occupantRatePlan.Id = 0;
     occupantRatePlan.RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base };
     occupantRatePlan.Period = period;
     occupantRatePlan.PeriodId = period.Id;
     occupantRatePlan.Rates = GetNulRates(occupantRatePlan);
     GetDefaultVariantEvergreenBaseRates(occupantRatePlan);
     occupantRatePlan.Rates.Id = 0;
     occupantRatePlan.Rates.RatePlanId = baseRatePlan.Id;
     occupantRatePlan.Rates.OccupancyRateType = occupancyRateType;
     occupantRatePlan.UseOccupancyRates = true;
     return occupantRatePlan;
 }
예제 #9
0
            public void AssignAndGetPromotionsForBaseGetsCorrectPromotions()
            {
                // Arrange
                BaseRatePlan rateplan = new BaseRatePlan
                    {
                        Id = RATEPLAN_TWO,
                        BusinessId = BUSINESS_ONE
                    };
                // ACT
                promotionManager.AssignAndGetPromotionsForBaseRatePlan(rateplan, BUSINESS_ONE);

                // Assert
                Assert.NotNull(rateplan.AssociatedPromotions, "associated promos not set");
                Assert.IsTrue(rateplan.AssociatedPromotions.Any(p => p.Id == PROMO_ONE), "promo one should be assigned to this rateplan");
                Assert.IsTrue(rateplan.AssociatedPromotions.Any(p => p.Id == PROMO_TWO), "promo two should be assigned to this rateplan");
                
                CacheHelper.ReAssignPromotionDaoToPromoCache();
            }
예제 #10
0
        /// <summary>
        /// Create BaseRatePlan
        /// </summary>
        public void Create(BaseRatePlan baseRatePlan)
        {
            //create the RatePlan record
            ratePlanDao.Create(baseRatePlan);

            const string SQL_STATEMENT = @"
                INSERT INTO Pricing.BaseRatePlan
                (
                        Id,
                        RoomTypeId,
                        CurrencyCode,
                        BoardBasisCode,
                        CancellationClassCode,
                        MaxOccupancy,
                        MaxAdults,
                        MaxChildren,
                        RackRate,
                        UseOccupancyRates,
                        SellAtRackRate,
                        DisplayName,
                        UpdatedByUserId
                  )
                VALUES
                (
                        @Id,
                        @RoomTypeId,
                        @CurrencyCode,
                        @BoardBasisCode,
                        @CancellationClassCode,
                        @MaxOccupancy,
                        @MaxAdults,
                        @MaxChildren,
                        @RackRate,
                        @UseOccupancyRates,
                        @SellAtRackRate,
                        @DisplayName,
                        @UpdatedByUserId
                    )";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.Id, baseRatePlan.Id),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.RoomTypeId, baseRatePlan.RoomTypeId),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.CurrencyCode, baseRatePlan.CurrencyCode),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.BoardBasisCode, baseRatePlan.BoardBasis.Code),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.CancellationClassCode, baseRatePlan.CancellationClass.Code),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.MaxOccupancy, baseRatePlan.MaxOccupancy),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.MaxAdults, baseRatePlan.MaxAdults),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.UseOccupancyRates, baseRatePlan.UseOccupancyRates),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.MaxChildren, baseRatePlan.MaxChildren),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.RackRate, baseRatePlan.RackRate),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.DisplayName, string.IsNullOrWhiteSpace(baseRatePlan.DisplayName) ? null : baseRatePlan.DisplayName),
                DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.SellAtRackRate, baseRatePlan.SellAtRackRate)
            };

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

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
        }
예제 #11
0
            public void ModifyRoomTypeAndBaseRatePlanPopulatedRoomTypeIdAndRatePlanId()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                var roomTypeDao = new Mock<IRoomTypeDao>();
                var ratePlanManager = new Mock<IRatePlanManager>();
                var eventTrackingManager = new Mock<IEventTrackingManager>();

                var roomTypeManager = new RoomTypeManager
                {
                    RoomTypeDao = roomTypeDao.Object,
                    RatePlanManager = ratePlanManager.Object,
                    EventTrackingManager = eventTrackingManager.Object
                };

                var ratePlan = new BaseRatePlan
                {
                    MaxOccupancy = 4,
                    MaxAdults = 2,
                    MaxChildren = 2,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base },
                    BoardBasis = new BoardBasis { Code = "BK" },
                    CancellationClass = new CancellationClass { Code = "FR" }
                };

                var roomType = new RoomType
                {
                    Id = 1,
                    BusinessId = BUSINESS_ID,
                    RoomClass = new RoomClass { Code = "DBL" },
                    QualityType = new QualityType { Code = "CTG" },
                    BathroomType = new BathroomType { Code = "PB" },
                    Aspect = new Aspect { Code = "CVW" },
                    BaseRatePlan = ratePlan
                };

                CacheHelper.StubRoomTypeCacheWithRoomType(roomType);

                roomTypeDao.Setup(rt => rt.DoesRoomTypeExist(roomType)).Returns(false);
                roomTypeDao.Setup(rt => rt.Modify(roomType));
                ratePlanManager.Setup(rp => rp.ModifyBaseRatePlan(roomType.BaseRatePlan));

                eventTrackingManager.Setup(be => be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RoomTypeModified, roomType.Id.ToString(CultureInfo.InvariantCulture), null));
                
                // Act
                roomTypeManager.ModifyRoomTypeAndBaseRatePlan(roomType);

                // Assert
                roomTypeDao.VerifyAll();
                ratePlanManager.VerifyAll();
                eventTrackingManager.VerifyAll();

                // Make sure these are reset for future tests
                roomTypeManager.RoomTypeDao = new RoomTypeDao();
                roomTypeManager.RatePlanManager = new RatePlanManager();
                roomTypeManager.EventTrackingManager = new EventTrackingManager();
                CacheHelper.ReAssignRoomTypeDaoToRoomTypeCache();
            }
예제 #12
0
            public void ModifyBaseRatePlanNoIdThrowsException()
            {
                // Arrange
                var ratePlanManager = new RatePlanManager();
                
                const int RATE_PLAN_ID = 1;
                const long BUSINESS_ID = 1;
                const int RATE_PLAN_RATE_ID = 5;

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

                try
                {
                    // Act
                    ratePlanManager.ModifyBaseRatePlan(ratePlan);

                    // Assert
                    Assert.Fail("Validation exception was not thrown");
                }
                catch (ValidationException vex)
                {
                    Assert.AreEqual(Errors.SRVEX30098.ToString(), vex.Code, "Incorrect validation exception was thrown");
                }
            }
예제 #13
0
            public void ModifyRatePlanWithInvalidIdThrowsException()
            {
                // Arrange
                var ratePlan = new BaseRatePlan
                {
                    Id = 2,
                    MaxOccupancy = 4,
                    MaxAdults = 4,
                    MaxChildren = 2,
                    BoardBasis = new EnumEntity { Code = BoardBasisTypeEnum.FullBoard.GetCode() },
                    CancellationClass = new EnumEntity { Code = CancellationClassTypeEnum.FullyRefundable.GetCode() },
                    RackRate = new decimal(2.5),
                    SellAtRackRate = true
                };

                // Act
                baseRatePlanDao.Modify(ratePlan);
            }
예제 #14
0
            public void CreateBaseRatePlanRatesMlosHasToBeZeroWhenPriceIsZeroFails()
            {
                // Arrange
                var ratePlanRateDao = MockRepository.GenerateMock<IBaseRatePlanRatesDao>();
                var ratePlanManager = new RatePlanManager { RatePlanRateDao = ratePlanRateDao };

                const int RATE_PLAN_ID = 1;
                var rates = new RatePlanRate
                                {
                                    RatePlanId = RATE_PLAN_ID,
                                    MonMinStay = 1,
                                    MonRate = new decimal(10),
                                    TueMinStay= 1,
                                    TueRate = new decimal(10),
                                    WedMinStay = 1,
                                    WedRate = new decimal(10),
                                    ThuMinStay = 1,
                                    ThuRate = new decimal(10),
                                    FriMinStay = 1,
                                    FriRate = new decimal(10),
                                    SatMinStay = 1,
                                    SatRate = new decimal(10),
                                    SunMinStay = 2,
                                    SunRate = 0,
                               };

                var ratePlan = new BaseRatePlan { Rates = rates, RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base } };

                // Act
                ratePlanManager.CreateBaseRatePlan(ratePlan);
            }
예제 #15
0
            public void ModifyBaseRatePlanIsSuccessful()
            {
                // Arrange
                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var baseRatePlanDao = new Mock<IBaseRatePlanDao>();
                var mockOfRatePlanManager = new Mock<RatePlanManager>();
                var promoManagerMock = new Mock<IPromotionManager>();

                mockOfRatePlanManager.CallBase = true;
                mockOfRatePlanManager.Object.EventTrackingManager = eventTrackingManager.Object;
                mockOfRatePlanManager.Object.BaseRatePlanDao = baseRatePlanDao.Object;
                mockOfRatePlanManager.Object.PromotionManager = promoManagerMock.Object;

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

                mockOfRatePlanManager.Setup(
                    rtm => rtm.ModifyRatePlanRates(It.Is<RatePlanRate>(rpr => rpr.Id == RATE_PLAN_RATE_ID), It.IsAny<bool>()))
                                     .Returns(new RatePlanRate { Id = RATE_PLAN_RATE_ID });

                var ratePlan = new BaseRatePlan { UseOccupancyRates = true, RoomTypeId = ROOMTYPE_ID, BusinessId = BUSINESS_ID, Id = RATE_PLAN_ID, RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base }, Rates = new RatePlanRate { Id = RATE_PLAN_RATE_ID } };
                promoManagerMock.Setup(pr => pr.UpsertPromotionRatePlanLinks(It.IsAny<RatePlan>()));
                
                baseRatePlanDao.Setup(rp => rp.Modify(It.Is<BaseRatePlan>(vpr => vpr.Id == RATE_PLAN_ID && vpr.BusinessId == BUSINESS_ID)));
                baseRatePlanDao.Setup(rp => rp.GetByRoomTypeId(ROOMTYPE_ID, BUSINESS_ID, string.Empty))
                               .Returns(new BaseRatePlan
                                       {
                                           UseOccupancyRates = true
                                       }
                                   );

                eventTrackingManager.Setup(be => be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanModified, ratePlan.Id.ToString(CultureInfo.InvariantCulture), null));

                // Act
                mockOfRatePlanManager.Object.ModifyBaseRatePlan(ratePlan);

                // Assert
                baseRatePlanDao.VerifyAll();
                eventTrackingManager.VerifyAll();
                mockOfRatePlanManager.VerifyAll();
                promoManagerMock.VerifyAll();
            }
예제 #16
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");
                }
            }
예제 #17
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());
            }
예제 #18
0
        /// <summary>
        /// Modify a particular base rate plan
        /// </summary>
        /// <param name="ratePlan">Base Rate plan</param>
        /// <returns>Modified rate plan</returns>
        public BaseRatePlan ModifyBaseRatePlan(BaseRatePlan 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.ModifyBaseRatePlan", arguments: new object[] { ratePlan }));
            }

            using (var tx = new BusinessTransaction())
            {
                // needed so we can check if we need to update the variants to be null for 
                // all occupancy constraints
                var originalBase = GetBaseRatePlan(ratePlan.RoomTypeId.Value, ratePlan.BusinessId, string.Empty);

                if (originalBase.UseOccupancyRates != ratePlan.UseOccupancyRates)
                {
                    // reset variants to have nulls for all occupancy
                    variantRatePlanDao.ResetVariantsToNullOccupancy(ratePlan.BusinessId, ratePlan.RoomTypeId.Value);
                }

                baseRatePlanDao.Modify(ratePlan);

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

                // update associated promos here
                PromotionManager.UpsertPromotionRatePlanLinks(ratePlan);

                tx.Commit();
            }

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

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

            return ratePlan;
        }
예제 #19
0
            public void GetRoomTypeIsSuccessful()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";
                const long BUSINESS_ID = 1;

                var roomTypeDao = new Mock<IRoomTypeDao>();
                var baseRatePlanDao = new Mock<IBaseRatePlanDao>();
                var variantRatePlanDao = new Mock<IVariantRatePlanDao>();
                var promotionManager = new Mock<IPromotionManager>();

                var roomTypeManager = new RoomTypeManager
                {
                    RoomTypeDao = roomTypeDao.Object,
                    BaseRatePlanDao = baseRatePlanDao.Object,
                    VariantRatePlanDao = variantRatePlanDao.Object,
                    PromotionManager = promotionManager.Object
                };

                var roomType = new RoomType { Id = 1 };

                roomTypeDao.Setup(x => x.GetByKey(roomType.Id)).Returns(roomType);
                var mockBaseRate = new BaseRatePlan();
                var mockVariants = new List<VariantRatePlan>();
                baseRatePlanDao.Setup(x => x.GetByRoomTypeId(roomType.Id, BUSINESS_ID, CULTURE_CODE)).Returns(mockBaseRate);
                variantRatePlanDao.Setup(x => x.GetByRoomTypeId(roomType.Id, BUSINESS_ID, CULTURE_CODE))
                                  .Returns(mockVariants);
                promotionManager.Setup(x => x.AssignAndGetPromotionsForBaseRatePlan(mockBaseRate, BUSINESS_ID));
                promotionManager.Setup(x => x.AssignAndGetPromotionsForRatePlans(mockVariants, BUSINESS_ID));

                // Act
                roomTypeManager.GetRoomType(roomType.Id, BUSINESS_ID, CULTURE_CODE);

                // Assert
                roomTypeDao.VerifyAll();
                baseRatePlanDao.VerifyAll();
                variantRatePlanDao.VerifyAll();
                promotionManager.VerifyAll();
            }
예제 #20
0
            public void CreateBaseRatePlanIsSuccessful()
            {
                // Arrange
                var ratePlanRateDao = new Mock<IBaseRatePlanRatesDao>();
                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var ratePlanDao = new Mock<IBaseRatePlanDao>();
                var ratePlanManager = new RatePlanManager { RatePlanRateDao = ratePlanRateDao.Object, 
                                                            EventTrackingManager = eventTrackingManager.Object, 
                                                            BaseRatePlanDao = ratePlanDao.Object };
                
                const int RATE_PLAN_ID = 1;
                const long BUSINESS_ID = 1;
                var rates = new RatePlanRate
                                {
                                    RatePlanId = RATE_PLAN_ID,
                                    MonMinStay = 1,
                                    MonRate = new decimal(10),
                                    TueMinStay= 1,
                                    TueRate = new decimal(10),
                                    WedMinStay = 1,
                                    WedRate = new decimal(10),
                                    ThuMinStay = 1,
                                    ThuRate = new decimal(10),
                                    FriMinStay = 1,
                                    FriRate = new decimal(10),
                                    SatMinStay = 1,
                                    SatRate = new decimal(10),
                                    SunMinStay = 1,
                                    SunRate = new decimal(10),
                               };

                var ratePlan = new BaseRatePlan { BusinessId = BUSINESS_ID, Rates = rates, RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base } };

                ratePlanDao.Setup(rp => rp.Create(ratePlan)).Callback(delegate { ratePlan.Id = RATE_PLAN_ID; });

                int id = 2;

                ratePlanRateDao.Setup(x => x.Create(rates)).Callback(delegate { rates.Id = id; });
                eventTrackingManager.Setup(
                    be =>
                    be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanAdded,
                                           RATE_PLAN_ID.ToString(CultureInfo.InvariantCulture), null));

                eventTrackingManager.Setup(
                    be =>
                    be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanRateAdded,
                                           id.ToString(CultureInfo.InvariantCulture), null));

                // Act
                ratePlanManager.CreateBaseRatePlan(ratePlan);

                // Assert
                ratePlanRateDao.VerifyAll();
                eventTrackingManager.VerifyAll();
                ratePlanDao.VerifyAll();
            }
예제 #21
0
        /// <summary>
        /// Gets the promotions for the business and associates the matching promos to the rate plan given
        /// </summary>
        /// <param name="ratePlan">base ratePlan for this business</param>
        /// <param name="businessId">business for the rateplan</param>
        public void AssignAndGetPromotionsForBaseRatePlan(BaseRatePlan ratePlan, long businessId)
        {
            var promotions = Cache.Cache.PromoCache.TryGetValue(businessId);

            if (promotions != null)
            {
                ratePlan.AssociatedPromotions =
                    promotions.Where(promo => promo.AssociatedRatePlanIds.Any(ids => ids == ratePlan.Id))
                              .ToList();

            }
        }
예제 #22
0
            public void CreateRoomTypeWithoutRoomClassThrowsValidationException()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                var roomTypeManager = new RoomTypeManager();

                var ratePlan = new BaseRatePlan
                {
                    RoomTypeId = 1,
                    MaxOccupancy = 4,
                    MaxAdults = 4,
                    MaxChildren = 2,
                };

                var roomType = new RoomType
                {
                    BusinessId = BUSINESS_ID,
                    RoomClass = new RoomClass(),
                    QualityType = new QualityType { Code = "CTG" },
                    BathroomType = new BathroomType { Code = "PB" },
                    Aspect = new Aspect { Code = "CVW" },
                    ServiceFrequency = new EnumEntity { Code = ServiceFrequencyEnum.Daily.GetCode() },
                    BaseRatePlan = ratePlan
                };

                try
                {
                    // Act
                    roomTypeManager.CreateRoomTypeAndBaseRatePlan(roomType);

                    // Assert
                    Assert.Fail("An exception SRVEX30063 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual(Errors.SRVEX30063.ToString(), ex.Code,
                                    "The Validation exception is not returning the right error code");
                }

            }
예제 #23
0
            public void CreateRatePlanWithInvalidRoomTypeIdThrowsException()
            {
                // Arrange
                // Create rate plan
                var ratePlan = new BaseRatePlan
                {
                    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"
                };

                // Act
                baseRatePlanDao.Create(ratePlan);
            }
예제 #24
0
            public void CreateRoomTypeAndBaseRatePlanPopulatedRoomTypeIdAndRatePlanId()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                var roomTypeDao = new Mock<IRoomTypeDao>();
                var ratePlanDao = new Mock<IBaseRatePlanDao>();
                var eventTrackingManager = new Mock<IEventTrackingManager>();

                var roomTypeManager = new RoomTypeManager
                {
                    RoomTypeDao = roomTypeDao.Object,
                    BaseRatePlanDao = ratePlanDao.Object,
                    EventTrackingManager = eventTrackingManager.Object
                };

                var ratePlan = new BaseRatePlan
                {
                    RoomTypeId = 1,
                    MaxOccupancy = 4,
                    MaxAdults = 2,
                    MaxChildren = 2,
                    RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base },
                    BoardBasis = new BoardBasis { Code = "BK" },
                    CancellationClass = new CancellationClass { Code = "FR" }
                };

                var roomType = new RoomType
                {
                    BusinessId = BUSINESS_ID,
                    RoomClass = new RoomClass { Code = "DBL" },
                    QualityType = new QualityType { Code = "CTG" },
                    BathroomType = new BathroomType { Code = "PB" },
                    Aspect = new Aspect { Code = "CVW" },
                    ServiceFrequency = new EnumEntity { Code = ServiceFrequencyEnum.Daily.GetCode() },
                    BaseRatePlan = ratePlan
                };

                roomTypeDao.Setup(rt => rt.Create(roomType)).Callback(delegate { roomType.Id = 1; });
                ratePlanDao.Setup(rp => rp.Create(roomType.BaseRatePlan)).Callback(delegate { ratePlan.Id = 1; });

                eventTrackingManager.Setup(be => be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RoomTypeAdded, roomType.Id.ToString(CultureInfo.InvariantCulture), null));
                eventTrackingManager.Setup(be => be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanAdded, ratePlan.Id.ToString(CultureInfo.InvariantCulture), null));

                CacheHelper.StubRatePlanViewCacheWithRatePlanViews(BUSINESS_ID, new List<RatePlanView>());

                // Act
                roomTypeManager.CreateRoomTypeAndBaseRatePlan(roomType);

                // Assert
                Assert.AreNotEqual(default(int), roomType.Id, "The room type id was not attributed.");
                Assert.AreNotEqual(default(int), ratePlan.Id, "The rate plan id was not attributed.");

                roomTypeDao.VerifyAll();
                ratePlanDao.VerifyAll();
                eventTrackingManager.VerifyAll();

                // Make sure these are reset for future tests
                roomTypeManager.RoomTypeDao = new RoomTypeDao();

                CacheHelper.ReAssignRatePlanDaoToRatePlanViewCache();
            }
예제 #25
0
 /// <summary>
 /// Set the default rates for evergreen period
 /// </summary>
 /// <param name="baseRatePlan">RatePlan</param>
 private static void SetDefaultEvergreenBaseRates(BaseRatePlan baseRatePlan)
 {
     baseRatePlan.Rates = new RatePlanRate
     {
         MonRate = baseRatePlan.RackRate,
         MonMinStay = MIN_STAY,
         TueRate = baseRatePlan.RackRate,
         TueMinStay = MIN_STAY,
         WedRate = baseRatePlan.RackRate,
         WedMinStay = MIN_STAY,
         ThuRate = baseRatePlan.RackRate,
         ThuMinStay = MIN_STAY,
         FriRate = baseRatePlan.RackRate,
         FriMinStay = MIN_STAY,
         SatRate = baseRatePlan.RackRate,
         SatMinStay = MIN_STAY,
         SunRate = baseRatePlan.RackRate,
         SunMinStay = MIN_STAY,
         RatePlanId = baseRatePlan.Id
     };
 }
예제 #26
0
 /// <summary>
 /// Get the rack rates for base rate plan
 /// </summary>
 /// <param name="baseRatePlan">BaseRatePlan</param>
 private static RatePlanRate GetBaseRackRates(BaseRatePlan baseRatePlan)
 {
     return new RatePlanRate
     {
         MonRate = baseRatePlan.RackRate,
         MonMinStay = MIN_STAY,
         TueRate = baseRatePlan.RackRate,
         TueMinStay = MIN_STAY,
         WedRate = baseRatePlan.RackRate,
         WedMinStay = MIN_STAY,
         ThuRate = baseRatePlan.RackRate,
         ThuMinStay = MIN_STAY,
         FriRate = baseRatePlan.RackRate,
         FriMinStay = MIN_STAY,
         SatRate = baseRatePlan.RackRate,
         SatMinStay = MIN_STAY,
         SunRate = baseRatePlan.RackRate,
         SunMinStay = MIN_STAY,
         RatePlanId = baseRatePlan.Id
     };
 }
예제 #27
0
        /// <summary>
        /// Create a collection of default VariantRataPlans for PerPerson pricing
        /// </summary>
        /// <param name="baseRatePlan">BaseRatePlan</param>
        /// <param name="evergreenRatePlanRate">Evergreen RatePlanRate</param>
        /// <param name="baseRatePlanRates">Base RatePlanRates</param>
        /// <param name="businessPeriods">Business Periods</param>
        /// <param name="cultureCode">CultureCode</param>
        /// <returns>Collection of VariantRatePlans</returns>
        private List<VariantRatePlan> GetDefaultVariantPerPersonRatePlans(BaseRatePlan baseRatePlan, RatePlanRate evergreenRatePlanRate, List<BaseRatePlanOccupantRate> baseRatePlanRates, List<Period> businessPeriods, string cultureCode)
        {
            var defaultVariantRatePlans = new List<VariantRatePlan>();
            var instantiatedRatePlan = CreateVariantFromBase(baseRatePlan, string.Empty);
            instantiatedRatePlan.Id = 0;
            instantiatedRatePlan.VariantRatePlanRateId = 0;
            instantiatedRatePlan.VariantAmount = 0;
            instantiatedRatePlan.ApplicableDays = Constants.FULL_AVAILABILITY;
            instantiatedRatePlan.UseOccupancyRates = baseRatePlan.UseOccupancyRates;
            // set this variant rate plan period to evergreen period
            SetVariantDefaultPeriod(instantiatedRatePlan, cultureCode);
            // set to evergreen rates if exist
            RatePlanRate variantRatePlanRates = evergreenRatePlanRate == null
                                                   ? GetBaseRackRates(baseRatePlan)
                                                   : CloneRatePlanRates(evergreenRatePlanRate);
            instantiatedRatePlan.Rates = variantRatePlanRates;
            instantiatedRatePlan.IsSelectedSeason = false;
            instantiatedRatePlan.VariantType = new VariantType() { Type = VariantTypeEnum.Amount };
            instantiatedRatePlan.RatePlanType = new RatePlanType() { Type = RatePlanTypeEnum.Variant };
            instantiatedRatePlan.UseOccupancyRates = true;
            instantiatedRatePlan.Rates.OccupancyRateType = OccupancyRateType.Unknown;
            defaultVariantRatePlans.Add(instantiatedRatePlan);

            var adultInstantiatedRatePlan = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedRatePlan, cultureCode, OccupancyRateType.Adult);
            defaultVariantRatePlans.Add(adultInstantiatedRatePlan);
            var childInstantiatedRatePlan = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedRatePlan, cultureCode, OccupancyRateType.Child);
            defaultVariantRatePlans.Add(childInstantiatedRatePlan);
           
            // clone evergreen variant for later use
            var evergreenRatePlan = CloneVariantRatePlan(instantiatedRatePlan);

            // create variants for business periods that have not been associated with a variant rate plan
            foreach (var period in businessPeriods)
            {
                VariantRatePlan instantiatedPlan = CloneVariantRatePlan(evergreenRatePlan);
                instantiatedPlan.VariantType = new VariantType() { Type = VariantTypeEnum.Amount };
                // as this is a created on the fly variant based on an existing one, there would not be a VariantRatePlanRate record
                instantiatedPlan.VariantRatePlanRateId = 0;
                instantiatedRatePlan.ApplicableDays = Constants.FULL_AVAILABILITY;
                instantiatedRatePlan.IsActive = true;
                instantiatedPlan.Periods = CreateVariantRatePlanPeriods(period);
                var variantRatePlanRate = baseRatePlanRates.Find(brpr => brpr.PeriodId == period.Id);
                RatePlanRate variantRatePlanRateForAllPeriods = variantRatePlanRate != null ? CloneRatePlanRates(variantRatePlanRate) : GetDefaultVariantEvergreenBaseRates(instantiatedPlan);
                SetVariantRates(variantRatePlanRateForAllPeriods, instantiatedPlan);
                // as this variant is artificially created, set to false
                instantiatedPlan.IsSelectedSeason = false;
                instantiatedPlan.RatePlanType = new RatePlanType() { Type = RatePlanTypeEnum.Variant };
                instantiatedRatePlan.UseOccupancyRates = true;
                instantiatedRatePlan.Rates.OccupancyRateType = OccupancyRateType.Unknown; ;
                defaultVariantRatePlans.Add(instantiatedPlan);

                var adultInstantiatedVariantRatePlan  = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedPlan, cultureCode, OccupancyRateType.Adult);
                adultInstantiatedVariantRatePlan.Periods = CreateVariantRatePlanPeriods(period);
                defaultVariantRatePlans.Add(adultInstantiatedVariantRatePlan);

                var childInstantiatedVariantRatePlan = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedPlan, cultureCode, OccupancyRateType.Child);
                childInstantiatedVariantRatePlan.Periods = CreateVariantRatePlanPeriods(period);
                defaultVariantRatePlans.Add(childInstantiatedVariantRatePlan);

                defaultVariantRatePlans.ForEach(x=> x.IsDefault = true);

            }
            return defaultVariantRatePlans;
        }
예제 #28
0
            protected override void RunBeforeAllTests()
            {
                base.RunBeforeAllTests();

                var businessManager = new BusinessManager();
                var roomTypeManager = new RoomTypeManager();
                var roomManager = new RoomManager();
                var orderManager = new OrderManager();


                //Create a business
                var paymentMethod = new BusinessPaymentMethod
                    {
                        BusinessId = BUSINESS_ID,
                        CurrencyCode = CURRENCY,
                        PaymentMethodCode = PaymentMethodEnum.Cash.GetCode()
                    };

                var provider = new Provider
                    {
                        RoomCount = ROOM_COUNT,
                        ContentId = BUSINESS_ID.ToString(),
                        ProviderTypeCode = PROVIDER_TYPE,
                    };

                var business = new Model.Business.Business
                    {
                        BusinessStatusCode = "A",
                        BusinessTypeCode = "P",
                        Name = "Test Business",
                        ShortName = "Test",
                        ReferenceCode = "B001",
                        IsTaxRegistered = true,
                        TaxRegistrationNumber = "12345",
                        BusinessRegistrationNumber = "12345",
                        AddressLine1 = "5 Main Road",
                        AddressLine2 = "Twickenham",
                        City = "London",
                        StateProvinceId = 386,
                        PostCode = "TW2 5SE",
                        CountryId = 16,
                        BusinessTelephoneNumber = "07448752114",
                        TimeZoneId = 36,
                        DefaultCultureCode = CULTURE,
                        WorkingCurrencyCode = CURRENCY,
                        UpdatedByUserId = new Guid("11111111-1111-1111-1111-111111111111"),
                        Provider = provider,
                        BusinessPaymentMethods = new List<BusinessPaymentMethod> {paymentMethod}
                    };

                var businessId = businessManager.CreateBusiness(business);


                // Create a room type
                
                var ratePlan = new BaseRatePlan
                    {
                        BusinessId = businessId,
                        CurrencyCode = CURRENCY,
                        MaxAdults = 2,
                        MaxChildren = 2,
                        MaxOccupancy = 3,
                        BoardBasis = new EnumEntity {Code = "BK"},
                        CancellationClass = new EnumEntity {Code = "FR"},
                        RackRate = new decimal(120.0),
                        SellAtRackRate = true,
                        RatePlanType = new RatePlanType {Type = RatePlanTypeEnum.Base},
                        Rates = new RatePlanRate{BusinessId = businessId, MonRate = 120, MonMinStay = 120},
                        UpdatedByUserId = new Guid("11111111-1111-1111-1111-111111111111"),
                    };

                var roomType = new RoomType
                    {
                        BusinessId = businessId,
                        RoomClass = roomTypeManager.GetRoomClasses(CULTURE).FirstOrDefault(),      //new RoomClass { Code = "DBL" },
                        QualityType = roomTypeManager.GetQualityTypes(CULTURE).FirstOrDefault(),   //new QualityType { Code = "APT" },
                        BathroomType = roomTypeManager.GetBathroomTypes(CULTURE).FirstOrDefault(), //new BathroomType { Code = "SP" },
                        Code = "DBL99",
                        ServiceFrequency = new EnumEntity { Code = "B" },
                        UpdatedByUserId = new Guid("11111111-1111-1111-1111-111111111111"),
                        BaseRatePlan = ratePlan,
                        BaseRatePlanId = ratePlan.Id,
                        Aspect = new Aspect { Code = "BAL"},                    
                    };
                
                roomTypeManager.CreateRoomTypeAndBaseRatePlan(roomType);
                roomType = roomTypeManager.GetRoomTypesAndBaseRatePlans(businessId, CULTURE).First();
                ratePlan = roomType.BaseRatePlan;


                //Create a room
                var roomId = roomManager.CreateRoom("TestRoom", roomType.Id, businessId);


                //Create an order
                var booking = new Booking
                {
                    BusinessId = businessId,
                    Guest = new Guest { DefaultCultureCode = CULTURE, Surname = "TestSurname", BusinessId = businessId },
                    StartDate = new DateTime(2014, 2, 10, 0, 0, 0, DateTimeKind.Utc),
                    EndDate = new DateTime(2014, 2, 12, 0, 0, 0, DateTimeKind.Utc),
                    NumberOfAdults = 2,
                    NumberOfChildren = 1,
                    Cost = new decimal(120.5),
                    BookingStatus = new EnumEntity { Code = BookingStatusType.CONFIRMED },
                    RoomTypeId = roomType.Id,
                    RoomId = roomId,
                    RatePlanId = ratePlan.Id,
                    Notes = "Testing note",
                    BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking,
                    RateType = new EnumEntity { Code = RateType.BEST_AVAILABLE_RATE },
                    CheckinStatus = new EnumEntity { Code = CheckinStatusOptions.NOTCHECKEDIN },
                    IsAvailabilityIgnored = true,
                    BoardBasis = BoardBasisTypeEnum.BreakfastIncluded,
                    CancellationDetails = new CancellationDetail()
                };

                var order = new Order
                {
                    OfflineSourceEnum = OfflineSourceEnum.Web,
                    OrderSourceCode = SourceType.Pms.GetCode(),
                    CustomerCurrencyCode = CURRENCY,
                    Bookings = new List<Booking> { booking },
                    CustomerCultureCode = "en-GB"
                };
                
                // Mock email manager so it doesn't send emails
                var emailManager = new Mock<IEmailManager>();
                orderManager.EmailManager = emailManager.Object;

                emailManager.Setup(x => x.SendConfirmationEmails(order)).Returns(true);

                orderManager.CreateOrder(businessId, order);
            }
예제 #29
0
        /// <summary>
        /// Modify RatePlan
        /// </summary>
        /// <param name="ratePlan">The rate plan object to modify</param>
        public void Modify(BaseRatePlan ratePlan)
        {
            const string SQL_STATEMENT = @"
                UPDATE Pricing.BaseRatePlan
                SET    MaxOccupancy = @MaxOccupancy,
                       MaxAdults = @MaxAdults,
                       MaxChildren = @MaxChildren,
                       BoardBasisCode = @BoardBasisCode,
                       CancellationClassCode = @CancellationClassCode,
                       RackRate = @RackRate,
                       SellAtRackRate = @SellAtRackRate,
                       UseOccupancyRates = @UseOccupancyRates,
                       DisplayName = @DisplayName,
                       UpdatedByUserId = @UpdatedByUserId
                WHERE  Id = @Id";

            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.Id, ratePlan.Id),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.MaxOccupancy, ratePlan.MaxOccupancy),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.MaxAdults, ratePlan.MaxAdults),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.MaxChildren, ratePlan.MaxChildren),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.BoardBasisCode, ratePlan.BoardBasis.Code),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.CancellationClassCode, ratePlan.CancellationClass.Code),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.RackRate, ratePlan.RackRate),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.SellAtRackRate, ratePlan.SellAtRackRate),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.DisplayName, string.IsNullOrWhiteSpace(ratePlan.DisplayName) ? null : ratePlan.DisplayName),
                    DbHelper.CreateParameter(BaseRatePlanMapper.Parameters.UseOccupancyRates, ratePlan.UseOccupancyRates)
                };

            // 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, "BaseRatePlanDao.Modify",
                    additionalDescriptionParameters: (new object[] { ratePlan.GetType().Name, ratePlan.Id }),
                    arguments: new object[] { ratePlan.GetType().Name, ratePlan.Id }));
            }
        }