示例#1
0
        /// <summary>
        /// Create RoomType
        /// </summary>
        /// <param name="roomType">The room type object to create</param>
        public void Create(RoomType roomType)
        {
            const string SQL_STATEMENT = @"
                INSERT INTO Room.RoomType
                (
                        BusinessId,
                        Code,
                        RoomClassCode,
                        QualityTypeCode,
                        BathroomTypeCode,
                        AspectCode,
                        Label,
                        ServiceFrequencyCode,
                        BaseOccupancy,
                        UpdatedByUserId
                )
                VALUES
                (
                        @BusinessId,
                        Room.GetNextRoomTypeCode(@BusinessId),
                        @RoomClass,
                        @QualityType,
                        @BathroomType,
                        @Aspect,
                        @Label,
                        @ServiceFrequencyCode,
                        @BaseOccupancy,
                        @UpdatedByUserId
                )
                SELECT @Id = SCOPE_IDENTITY()";

            var parameters = new List<SqlParameter>
                {
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.BusinessId, roomType.BusinessId),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.RoomClass, roomType.RoomClass.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.QualityType, roomType.QualityType.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.BathroomType, roomType.BathroomType.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.Aspect, roomType.Aspect.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.Label, roomType.Label),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.BaseOccupancy, roomType.BaseOccupancy),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.ServiceFrequencyCode, roomType.ServiceFrequency.Code)
                };


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

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
            roomType.Id = DbHelper.ParameterValue<int>(outputKey);
        }
示例#2
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);
            }
示例#3
0
            public void CreateRoomTypePopulatesRoomTypeId()
            {
                // Arrange
                // Create room type
                var roomType = new RoomType
                {
                    BusinessId = 1,
                    RoomClass = new RoomClass { Code = "TWN" },
                    QualityType = new QualityType { Code = "CTG" },
                    BathroomType = new BathroomType { Code = "PB" },
                    Aspect = new Aspect { Code = "CVW" },
                    ServiceFrequency = new EnumEntity { Code = ServiceFrequencyEnum.Daily.GetCode() }
                };

                // Act
                roomTypeDao.Create(roomType);

                // Assert
                // Check if the room type id is attributed
                Assert.IsNotNull(roomType.Id, "The room type id was not attributed.");
            }
示例#4
0
        /// <summary>
        /// Modify RoomType
        /// </summary>
        /// <param name="roomType">The room type object to modify</param>
        public void Modify(RoomType roomType)
        {
            const string SQL_STATEMENT = @"
                UPDATE Room.RoomType
                SET    RoomClassCode = @RoomClass,
                       QualityTypeCode = @QualityType,
                       BathroomTypeCode = @BathroomType,
                       AspectCode = @Aspect,
                       Label = @Label,
                       BaseOccupancy = @BaseOccupancy,
                       UpdatedByUserId = @UpdatedByUserId
                WHERE  Id = @Id";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.Id, roomType.Id),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.RoomClass, roomType.RoomClass.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.QualityType, roomType.QualityType.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.BathroomType, roomType.BathroomType.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.Aspect, roomType.Aspect.Code),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.BaseOccupancy, roomType.BaseOccupancy),
                DbHelper.CreateParameter(RoomTypeMapper.Parameters.Label, roomType.Label)
            };

            // 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, "RoomTypeDao.Modify", 
                    additionalDescriptionParameters: (new object[] { roomType.GetType().Name, roomType.Id }), 
                    arguments: new object[] { roomType.GetType().Name, roomType.Id }));
            }
        }
示例#5
0
            public void DoesRoomTypeExistWithoutExistingRoomTypeReturnsFalseIsSuccessful()
            {
                // Arrange
                var roomType = new RoomType
                {
                    RoomClass = new RoomClass { Code = "SGL" },
                    QualityType = new QualityType { Code = "APT" },
                    BathroomType = new BathroomType { Code = "ES" },
                    Aspect = new Aspect { Code = "BAL" }
                };

                // Act
                bool doesRoomTypeExist = roomTypeDao.DoesRoomTypeExist(roomType);

                // Assert
                Assert.IsFalse(doesRoomTypeExist, "Room type should not exist");
            }
示例#6
0
            public void ModifyRoomTypeIsSuccessful()
            {
                // Arrange
                var roomType = new RoomType
                {
                    Id = 1,
                    BusinessId = 1,
                    RoomClass = new RoomClass { Code = "TWN" },
                    QualityType = new QualityType { Code = "APT" },
                    BathroomType = new BathroomType { Code = "JC" },
                    Aspect = new Aspect { Code = "BAL" }
                };

                // Act
                roomTypeDao.Modify(roomType);

                RoomType roomTypeToVerify = roomTypeDao.GetByKey(roomType.Id);

                // Assert
                // Check if the room type has been updated correctly
                Assert.AreEqual(roomType.BusinessId, roomTypeToVerify.BusinessId, "The business id was not updated.");
                Assert.AreEqual(roomType.RoomClass.Code, roomTypeToVerify.RoomClass.Code, "The room class was not updated.");
                Assert.AreEqual(roomType.QualityType.Code, roomTypeToVerify.QualityType.Code, "The quality type was not updated.");
                Assert.AreEqual(roomType.BathroomType.Code, roomTypeToVerify.BathroomType.Code, "The bathroom type was not updated.");
                Assert.AreEqual(roomType.Aspect.Code, roomTypeToVerify.Aspect.Code, "The aspect was not updated.");
            }
示例#7
0
        /// <summary>
        /// Create Inventory from Eagle room
        /// </summary>
        /// <param name="room">Room</param>
        /// <param name="roomType"></param>
        /// <returns>AIGInventory object</returns>
        private Inventory CreateInventoryFromRoom(Room room, RoomType roomType)
        {
            var visibility = Visibility.All;

            if (!room.IsAvailableOnline || room.RoomStatusCode != ACTIVE_ROOM_STATUS_CODE)
            {
                visibility = Visibility.Offline;
            }

            var interfaceRoom = new AIGInventory(room.Id.ToGuid(ROOM_PREFIX).ToString(), room.Name, visibility, null)
                                {
                                    InventoryAvailabilityDiaryDateRange = ExtractAndCreateInventoryAvailability(room.Id, roomType)
                                };

            return interfaceRoom;
        }
示例#8
0
        /// <summary>
        /// Set Configuration on AIG product
        /// </summary>
        /// <param name="roomType">Room Type</param>        
        /// <param name="interfaceProduct">AIG Product</param>
        private void SetAigProductConfiguration(RoomType roomType, ref AIGProduct interfaceProduct)
        {
            var rooms = ExtractProductsAndThierAvailabiltyByProductType(roomType);

            if (interfaceProduct == null)
            {
                interfaceProduct = AIGProduct.CreateProductInventoryConfigurationOnly(roomType.ProductId, rooms);
            }
            else
            {
                interfaceProduct.Inventory = rooms;
            }

            CheckAssociatedInventoryExists(interfaceProduct);
        }
示例#9
0
        /// <summary>
        /// Convert Room Type to AIG product
        /// </summary>
        /// <param name="roomType">Room Type</param>        
        /// <param name="checkinTime">Checkin Time</param>
        /// <param name="checkoutTime">Checkout Time</param>
        /// <returns>AIGProduct</returns>
        private AIGProduct ConvertRoomTypeToAigProduct(RoomType roomType, string checkinTime, string checkoutTime)
        {
            var interfaceProduct = SetAigProductAttributes(roomType, checkinTime, checkoutTime);

            CheckValidMaximumOccupancyIsSet(interfaceProduct);

            SetAigProductConfiguration(roomType, ref interfaceProduct);

            return interfaceProduct;
        }
        /// <summary>
        /// Set up booking for scenario given a row from feature table
        /// </summary>
        /// <param name="bookingType">booking type column cell</param>
        /// <param name="currentRoomType">room type</param>
        /// <param name="row">row from feature table</param>
        /// <param name="userId">user to use for created by</param>
        /// <returns>Booking to use</returns>
        private Booking SetUpBooking(string bookingType, RoomType currentRoomType, TableRow row, Guid userId)
        {
            int randomGuestId = TestSchemaHelper.LoadRandomGuest(businesses[row[HOTEL]], userId);

            EnumEntity bookingStatus = new EnumEntity
            {
                Code =
                    bookingType.ToLower().IndexOf("confirmed") >= 0 ? BookingStatusType.CONFIRMED : BookingStatusType.PROVISIONAL
            };

            return new Booking
            {
                BusinessId = businesses[row[HOTEL]],
                RoomId = currentRoomType.Rooms.Find(rm => rm.Name == row[ROOM_NAME]).Id,
                RoomTypeId = currentRoomType.Id,
                RatePlanId = currentRoomType.BaseRatePlans[0].Id, // Assume first rate plan for room type since not specified in given
                StartDate = GetDateFromFeatureString(row[START_DATE]),
                EndDate = GetDateFromFeatureString(row[END_DATE]),
                BookingStatus = bookingStatus,
                Guest = new Model.Customer.Guest { Id = randomGuestId },
                BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking,
                CurrencyCode = "GBP",
                SourceType = new EnumEntity { Code = SourceType.ONLINE },
                RateType = new EnumEntity { Code = RateType.BEST_AVAILABLE_RATE },
                CheckinStatus = new EnumEntity { Code = CheckinStatusOptions.NOTCHECKEDIN },
                Cost = 1
            };
        }
示例#11
0
        /// <summary>
        /// Modify a room type and its base rate plan
        /// </summary>
        /// <param name="roomType">The room type object to modify</param>
        public void ModifyRoomTypeAndBaseRatePlan(RoomType roomType)
        {
            // Validate data
            if (roomTypeDao.DoesRoomTypeExist(roomType))
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30093, "RoomManager.ModifyRoomTypeAndBaseRatePlan", arguments: new object[] { roomType }));
            }

            using (var btx = new BusinessTransaction())
            {
                var baseRatePlan = roomType.BaseRatePlan;

                if (roomType.IsValid() && baseRatePlan.IsValid())
                {
                    // Modify room type and subsequent business event
                    roomTypeDao.Modify(roomType);

                    baseRatePlan.RoomTypeId = roomType.Id;

                    // Modify rate plan
                    ratePlanManager.ModifyBaseRatePlan(baseRatePlan);

                    btx.Commit();

                    eventTrackingManager.CreateBusinessEventAsync(roomType.BusinessId,
                                                             BusinessEventTypesEnum.RoomTypeModified,
                                                             roomType.Id.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Invalid this item in the cache so it is retrieved again
            // Needs to be after transaction so updated info is in db and readable.
            Cache.Cache.RoomType.Invalidate(roomType.Id);
            Cache.Cache.RatePlanViewCache.Invalidate(roomType.BusinessId);
            Cache.Cache.PromoCache.Invalidate(roomType.BusinessId);
        }
示例#12
0
        /// <summary>
        /// Create a record for room type and its base rate plan
        /// </summary>
        /// <param name="roomType">The room type object to create</param>
        public void CreateRoomTypeAndBaseRatePlan(RoomType roomType)
        {
            using (var btx = new BusinessTransaction())
            {
                // determine if room type exists and is active
                bool activeRoomTypeExists = roomTypeDao.DoesRoomTypeExist(roomType);

                // if room type exists and is active, throw validation exception
                if (activeRoomTypeExists)
                {
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30093, "RoomManager.CreateRoomTypeAndBaseRatePlan", arguments: new object[] { roomType }));
                }

                RoomType roomTypeReference = roomTypeDao.GetByRoomTypeInformation(roomType);

                //  if room type exists and is not active, activate it
                if (roomTypeReference != null)
                {
                    //set room type isActive flag to true
                    roomTypeDao.ActivateRoomType(roomTypeReference.Id);

                    // set rooms belonging to room type to active
                    List<Model.Room.Room> rooms = roomManager.GetRoomsByBusinessRoomType(roomTypeReference.Id, roomTypeReference.BusinessId);

                    // createRoom method detects existing rooms and set it to active
                    rooms.ForEach(r => roomManager.CreateRoom(r.Name, r.RoomTypeId, r.BusinessId));

                    roomType.Id = roomTypeReference.Id;

                    BaseRatePlan inputBaseRatePlan = roomType.BaseRatePlan;
                    BaseRatePlan roomTypeBaseRatePlan = baseRatePlanDao.GetByRoomTypeId(roomTypeReference.Id, roomTypeReference.BusinessId);

                    if (roomTypeBaseRatePlan == null)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30062,
                                                                                     "RoomManager.CreateRoomTypeAndBaseRatePlan",
                                                                                     arguments: new object[] { roomType }));
                    }

                    if (inputBaseRatePlan == null)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30062,
                                                                                     "RoomManager.CreateRoomTypeAndBaseRatePlan",
                                                                                     arguments: new object[] { roomType }));
                    }

                    roomTypeBaseRatePlan.RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base };
                    roomTypeBaseRatePlan.RoomTypeId = roomTypeReference.Id;
                    roomTypeBaseRatePlan.BusinessId = roomTypeReference.BusinessId;
                    roomTypeBaseRatePlan.RackRate = inputBaseRatePlan.RackRate;
                    roomTypeBaseRatePlan.MaxAdults = inputBaseRatePlan.MaxAdults;
                    roomTypeBaseRatePlan.MaxChildren = inputBaseRatePlan.MaxChildren;
                    roomTypeBaseRatePlan.MaxOccupancy = inputBaseRatePlan.MaxOccupancy;
                    roomTypeBaseRatePlan.BoardBasis = inputBaseRatePlan.BoardBasis;
                    roomTypeBaseRatePlan.CancellationClass = inputBaseRatePlan.CancellationClass;
                    roomTypeBaseRatePlan.SellAtRackRate = inputBaseRatePlan.SellAtRackRate;
                    roomTypeBaseRatePlan.UseOccupancyRates = inputBaseRatePlan.UseOccupancyRates;
                    roomTypeBaseRatePlan.DisplayName = inputBaseRatePlan.DisplayName;

                    ratePlanManager.ModifyBaseRatePlan(roomTypeBaseRatePlan);
                    
                    btx.Commit();

                    // set event for activation of room type
                    eventTrackingManager.CreateBusinessEventAsync(roomTypeReference.BusinessId,
                                                             BusinessEventTypesEnum.RoomTypeActivated,
                                                             roomTypeReference.Id.ToString(), null);
                }
                else
                {
                    BaseRatePlan baseRatePlan = roomType.BaseRatePlan;

                    if (baseRatePlan == null)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30062,
                                                                                     "RoomManager.CreateRoomTypeAndBaseRatePlan",
                                                                                     arguments: new object[] { roomType }));
                    }

                    // NOTE: ServiceFrequency isn't currently implemented so are hard coded here for the time being
                    roomType.ServiceFrequency = new EnumEntity { Code = ServiceFrequencyEnum.Daily.GetCode() };

                    baseRatePlan.RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base };

                    if (roomType.IsValid() && baseRatePlan.IsValid())
                    {
                        // Create room type and subsequent business event
                        roomTypeDao.Create(roomType);

                        // Create rate plan and subsequent business event
                        baseRatePlan.RoomTypeId = roomType.Id;
                        baseRatePlanDao.Create(baseRatePlan);

                        btx.Commit();

                        eventTrackingManager.CreateBusinessEventAsync(roomType.BusinessId,
                                                                 BusinessEventTypesEnum.RoomTypeAdded,
                                                                 roomType.Id.ToString(CultureInfo.InvariantCulture));

                        eventTrackingManager.CreateBusinessEventAsync(roomType.BusinessId,
                                                                 BusinessEventTypesEnum.RatePlanAdded,
                                                                 baseRatePlan.Id.ToString(CultureInfo.InvariantCulture));
                    }
                }
            }

            // Invalidate the cache so it refreshes
            Cache.Cache.RatePlanViewCache.Invalidate(roomType.BusinessId);
        }
        ///<summary>
        /// Converts RoomType to RoomTypeDto
        ///</summary>
        ///<param name="roomType">Room Type</param>
        ///<returns>Room Type DTO</returns>
        private static RoomTypeDto ConvertRoomTypeToDto(RoomType roomType)
        {
            RoomTypeDto dto = null;

            if (roomType != null)
            {
                dto = new RoomTypeDto
                {
                    Id = roomType.Id,
                    Code = roomType.Code,
                    Name = roomType.Name,
                    RoomIds = new List<int>(),
                    RatePlans = roomType.RatePlans.ConvertAll(ConvertRatePlanToDto)
                };

                foreach (Room room in roomType.Rooms)
                {
                    dto.RoomIds.Add(room.Id);
                }

                foreach (CombinedRoom combinedRoom in roomType.CombinedRooms)
                {
                    dto.RoomIds.Add(combinedRoom.Id);
                }
            }

            return dto;
        }
示例#14
0
        /// <summary>
        /// Get room type based on room class, quality and bathroom types
        /// </summary>
        /// <param name="roomType">RoomType</param>
        /// <returns>RoomType</returns>
        public RoomType GetByRoomTypeInformation(RoomType roomType)
        {
            string sqlQuery = ROOMTYPES_QUERY + @"
                    WHERE  BusinessId = @BusinessId 
                    AND    RoomClassCode = @RoomClass 
                    AND    BathroomTypeCode = @BathroomType";

            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(RoomTypeMapper.Parameters.BusinessId, roomType.BusinessId),
                    DbHelper.CreateParameter(RoomTypeMapper.Parameters.RoomClass, roomType.RoomClass.Code),
                    DbHelper.CreateParameter(RoomTypeMapper.Parameters.BathroomType, roomType.BathroomType.Code),
                    DbHelper.CreateParameter(RoomMapper.Parameters.RoomStatus, RoomStatusCodes.ACTIVE)
                };
            if (roomType.QualityType != null && !string.IsNullOrWhiteSpace(roomType.QualityType.Code))
            {
                sqlQuery = sqlQuery + " AND  QualityTypeCode = @QualityType ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.QualityType, roomType.QualityType.Code));
            }
            else
            {
                sqlQuery = sqlQuery + " AND QualityTypeCode IS NULL ";
            }

            if (roomType.Aspect != null && !string.IsNullOrEmpty(roomType.Aspect.Code))
            {
                sqlQuery = sqlQuery + " AND  AspectCode = @Aspect ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.Aspect, roomType.Aspect.Code));
            }
            else
            {
                sqlQuery = sqlQuery + " AND  AspectCode IS NULL ";
            }

            if (!string.IsNullOrEmpty(roomType.Label))
            {
                sqlQuery = sqlQuery + "AND  Label = @Label ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.Label, roomType.Label));
            }
            else
            {
                sqlQuery = sqlQuery + "AND  Label IS NULL ";
            }

           
            if (roomType.Id != default(int))
            {
                sqlQuery = sqlQuery + " AND  Id = @Id ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.Id, roomType.Id));
            }

            return DbHelper.CreateInstance(sqlQuery, RoomTypeMapper.MapReader, parameters: parameters);
        }
示例#15
0
        /// <summary>
        /// Check if room type already exists
        /// </summary>
        /// <param name="roomType">Room type to check</param>
        /// <returns>True if room type exists</returns>
        public bool DoesRoomTypeExist(RoomType roomType)
        {
            string sqlSelect = @"
                    SELECT count(id) 
                    FROM   Room.RoomType
                    WHERE  BusinessId = @BusinessId 
                    AND    RoomClassCode = @RoomClass 
                    AND    BathroomTypeCode = @BathroomType 
                    AND    IsActive = 1 ";

            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(RoomTypeMapper.Parameters.BusinessId, roomType.BusinessId),
                    DbHelper.CreateParameter(RoomTypeMapper.Parameters.RoomClass, roomType.RoomClass.Code),
                    DbHelper.CreateParameter(RoomTypeMapper.Parameters.BathroomType, roomType.BathroomType.Code)
                };

            if (roomType.QualityType != null && !string.IsNullOrWhiteSpace(roomType.QualityType.Code))
            {
                sqlSelect = sqlSelect + "AND  QualityTypeCode = @QualityType ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.QualityType, roomType.QualityType.Code));
            }
            else
            {
                sqlSelect = sqlSelect + "AND QualityTypeCode IS NULL ";
            }

            if (roomType.Aspect != null && !string.IsNullOrEmpty(roomType.Aspect.Code))
            {
                sqlSelect = sqlSelect + "AND  AspectCode = @Aspect ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.Aspect, roomType.Aspect.Code));
            }
            else
            {
                sqlSelect = sqlSelect + "AND  AspectCode IS NULL ";
            }

            if (!string.IsNullOrEmpty(roomType.Label))
            {
                sqlSelect = sqlSelect + "AND  Label = @Label ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.Label, roomType.Label));
            }
            else
            {
                sqlSelect = sqlSelect + "AND  Label IS NULL ";
            }

            // Only return true if there's a match for the room type being modified
            if (roomType.Id != default(int))
            {
                sqlSelect = sqlSelect + "AND  Id != @Id ";
                parameters.Add(DbHelper.CreateParameter(RoomTypeMapper.Parameters.Id, roomType.Id));
            }

            return DbHelper.ExecuteScalar<bool>(sqlSelect, CommandType.Text, parameters);
        }
示例#16
0
        /// <summary>
        /// Stubs the Room Type Cache with a room type
        /// </summary>
        /// <param name="roomType">The room type</param>
        /// <returns>Stubbed BusinessDao</returns>
        public static IRoomTypeDao StubRoomTypeCacheWithRoomType(RoomType roomType)
        {
            var roomTypeDao = new Mock<IRoomTypeDao>();
            roomTypeDao.Setup(rt => rt.GetByKey(roomType.Id)).Returns(roomType);

            Cache.RoomType.RoomTypeDao = roomTypeDao.Object;

            return roomTypeDao.Object;
        }
示例#17
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);
            }
示例#18
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");
                }

            }
示例#19
0
        /// <summary>
        /// Set Attributes on AIG product
        /// </summary>
        /// <param name="roomType">Room Type</param>        
        /// <param name="checkinTime">Checkin Time</param>
        /// <param name="checkoutTime">Checkout Time</param>
        /// <returns>AIGProduct</returns>
        private static AIGProduct SetAigProductAttributes(RoomType roomType, string checkinTime, string checkoutTime)
        {
            var checkInTime = string.IsNullOrEmpty(checkinTime) ? DEFAULT_CHECKIN_TIME : Int32.Parse(checkinTime);
            var checkOutTime = string.IsNullOrEmpty(checkoutTime) ? DEFAULT_CHECKOUT_TIME : Int32.Parse(checkoutTime);

            return AIGProduct.CreateProductAttributesOnly(roomType.ProductId, ProductCategoryType.ServicedAccomodation, roomType.Name, roomType.MaxOccupancy, roomType.MaxAdults, 1, roomType.MaxChildren, checkInTime, checkOutTime, null);
        }
示例#20
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();
            }
示例#21
0
        /// <summary>
        /// Get all Rooms for a Room Type
        /// </summary>
        /// <param name="roomType">Room Type</param>        
        /// <returns>Array of AIGInventory</returns>
        private AIGInventory[] ExtractProductsAndThierAvailabiltyByProductType(RoomType roomType)
        {
            var roomList = roomManager.GetRoomsByBusinessRoomType(roomType.Id, roomType.BusinessId);

            IList<AIGInventory> roomsList = new List<AIGInventory>();
            if (roomList != null && roomList.Count != default (int))
            {
                foreach (var interfaceRoom in from room in roomList where room.IsAvailableOnline select CreateInventoryFromRoom(room, roomType))
                {
                    roomsList.Add(interfaceRoom);
                }
            }

            return roomsList.ToArray();
        }
示例#22
0
            public void ModifyRoomTypeWhereRoomTypeExistsThrowsValidationException()
            {
                // Arrange
                var roomTypeDao = MockRepository.GenerateMock<IRoomTypeDao>();
                var roomTypeManager = new RoomTypeManager { RoomTypeDao = roomTypeDao };

                var roomType = new RoomType();

                roomTypeDao.Expect(x => x.DoesRoomTypeExist(roomType)).Return(true);

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

                    // Assert
                    Assert.Fail("An exception SRVEX30093 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual(Errors.SRVEX30093.ToString(), ex.Code, "The Validation exception is not returning the right error code");
                }
            }
示例#23
0
        /// <summary>
        /// Extract and Create Inventory Availability for a room
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="roomType"></param>
        /// <returns>InventoryAvailabilityDiaryDateRange object</returns>
        private InventoryAvailabilityDiaryDateRange ExtractAndCreateInventoryAvailability(int roomId, RoomType roomType)
        {
            //always get 1 years worth of availability data
            var startDate = DateTime.Now.Date;
            var endDate = startDate.AddYears(1);
            var extractedRoomAvailability = roomManager.GetAllRoomInventoryByRoomIdBetweenDates(roomId, startDate, endDate);

            if (extractedRoomAvailability == null || extractedRoomAvailability.Count == default(int))
            {
                Logger.Info(String.Format("No availability found for room {0} for room type {1}", roomId, roomType.Id));
                return null;
            }

            var inventoryAvailabilityDiaryEntryList = new List<InventoryAvailabilityDiaryEntry>();

            foreach (var roomAvailability in extractedRoomAvailability)
            {
                var availabilityStatus = roomAvailability.Available ? AvailablilityDiaryEntryType.Available : AvailablilityDiaryEntryType.Unavailable;

                inventoryAvailabilityDiaryEntryList.Add(new InventoryAvailabilityDiaryEntry(roomAvailability.Date, roomAvailability.Date, availabilityStatus));
            }

            return new InventoryAvailabilityDiaryDateRange(startDate, endDate, inventoryAvailabilityDiaryEntryList.ToArray());
        }
示例#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
            public void ModifyRoomTypeWithInvalidIdThrowsException()
            {
                // Arrange
                var roomType = new RoomType
                {
                    Id = 2,
                    BusinessId = 2,
                    RoomClass = new RoomClass { Code = "DBL" },
                    QualityType = new QualityType { Code = "CTG" },
                    BathroomType = new BathroomType { Code = "PB" },
                    Aspect = new Aspect { Code = "CVW" }
                };

                // Act
                roomTypeDao.Modify(roomType);
            }
示例#26
0
            public void GetRoomTypesAndBaseRatePlansIsSuccessful()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";
                const long BUSINESS_ID = 1;

                var roomTypeDao = MockRepository.GenerateMock<IRoomTypeDao>();
                var baseRatePlanDao = MockRepository.GenerateMock<IBaseRatePlanDao>();
                var roomDao = MockRepository.GenerateMock<IRoomDao>();

                var roomTypeManager = new RoomTypeManager
                    {
                        RoomTypeDao = roomTypeDao,
                        BaseRatePlanDao = baseRatePlanDao,
                        RoomDao = roomDao
                    };

                var roomType = new RoomType { Id = 1 };

                roomTypeDao.Expect(x => x.GetAllActiveForBusiness(BUSINESS_ID)).Return(new List<RoomType> { roomType });

                baseRatePlanDao.Expect(x => x.GetByRoomTypeId(roomType.Id, BUSINESS_ID, CULTURE_CODE)).Return(new BaseRatePlan());

                roomDao.Expect(x => x.GetByRoomTypeId(roomType.Id, BUSINESS_ID)).Return(new List<Room>());

                // Act
                roomTypeManager.GetRoomTypesAndBaseRatePlans(BUSINESS_ID, CULTURE_CODE);

                // Assert
                roomTypeDao.VerifyAllExpectations();
                baseRatePlanDao.VerifyAllExpectations();
                roomDao.VerifyAllExpectations();
            }
示例#27
0
            public void DoesRoomTypeExistWithExistingRoomTypeReturnsTrueIsSuccessful()
            {
                // Arrange
                var roomType = new RoomType
                    {
                        BusinessId = 1,
                        RoomClass = new RoomClass { Code = "DBL" },
                        QualityType = new QualityType { Code = "CTG" },
                        BathroomType = new BathroomType { Code = "PB" },
                        Aspect = new Aspect { Code = "CVW" }
                    };

                // Act
                bool doesRoomTypeExist = roomTypeDao.DoesRoomTypeExist(roomType);

                // Assert
                Assert.IsTrue(doesRoomTypeExist, "Room type should exist");
            }
示例#28
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();
            }
示例#29
0
            public void CreateRoomTypeWithInvalidBusinessIdThrowsException()
            {
                // Arrange
                // Create room type
                var roomType = new RoomType
                {
                    BusinessId = 2,
                    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() }
                };

                // Act
                roomTypeDao.Create(roomType);
            }
示例#30
0
        /// <summary>
        /// Finds the max occupancy (OTA NumberOfGuests) for a given rate plan.
        /// 
        /// Note this takes into account that 'same as base' setting on variant
        /// rate plans need to be determined from the base rate plan.
        /// </summary>
        /// <param name="roomType">containing the base and variant rate plans.</param>
        /// <param name="ratePlanId">to find the number of guests for.</param>
        /// <returns></returns>
        private int FindNumberOfGuests(RoomType roomType, int ratePlanId)
        {
            try
            {
                RatePlan baseRatePlan = roomType.BaseRatePlan;
                if (baseRatePlan != null && baseRatePlan.Id == ratePlanId)
                {
                    return baseRatePlan.MaxOccupancy.Value;
                }
                foreach (RatePlan plan in roomType.VariantRatePlans)
                {
                    if (plan.Id != ratePlanId)
                        continue;

                    if (plan.MaxOccupancy == null)
                        return baseRatePlan.MaxOccupancy.Value;

                    return plan.MaxOccupancy.Value;
                }
                throw new Exception(String.Format("Failed to find the MaxOccupancy for rate plan: '{0}' and room type: '{1}'", ratePlanId, roomType.Id));
            }
            catch(Exception ex)
            {
                throw new Exception(String.Format("Failed to determine the MaxOccupancy for rate plan: '{0}' and room type: '{1}'", ratePlanId, roomType.Id), ex);
            }
        }