Beispiel #1
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);
            }
Beispiel #2
0
        /// <summary>
        ///  Create business provider
        /// </summary>
        /// <param name="provider">Provider</param>
        /// <returns>true if create succeeds</returns>
        public bool CreateProvider(Provider provider)
        {
            const string SQL_CREATE_BUSINESSPROVIDER_STATEMENT = @"
            INSERT INTO [Business].[Provider]
           (Id,
            [ProviderTypeCode],
            [RoomCount],
            [ContentId],
            [UpdatedByUserId])           
            VALUES(
            @Id,
            @ProviderTypeCode,
            @RoomCount,
            @ContentId,
            @UpdatedByUserId)";

            var providerParameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BusinessMapper.Parameters.Id, provider.Id),
                DbHelper.CreateParameter(BusinessMapper.Parameters.RoomCount, provider.RoomCount),
                DbHelper.CreateParameter(BusinessMapper.Parameters.ContentId, provider.ContentId),
                DbHelper.CreateParameter(BusinessMapper.Parameters.ProviderTypeCode, provider.ProviderTypeCode)
            };

            AuditFieldsHelper.PopulateAuditFields(providerParameters);

            try
            {
                DbHelper.ExecuteNonQueryCommand(SQL_CREATE_BUSINESSPROVIDER_STATEMENT, parameters: providerParameters);
            }
            catch (SqlException exception)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30099, "BusinessDao.CreateProvider", additionalDescriptionParameters: (new object[] { exception.Message }), arguments: new object[] { provider.GetType().Name, provider.Id }));
            }
            return true;

        }
Beispiel #3
0
            public void CreateBusinessCallsExpectedMethods()
            {
                // Arrange

                var businessDao = MockRepository.GenerateMock<IBusinessDao>();
                var businessEventDao = MockRepository.GenerateMock<IBusinessEventDao>();
                var businessChannelOptInDao = MockRepository.GenerateMock<IBusinessChannelOptInDao>();
                var distributionManagerMock = MockRepository.GenerateMock<IDistributionManager>();
                var businessChannelOverrideDaoMock = MockRepository.GenerateMock<IBusinessChannelOverrideDao>();

                var paymentMethod = new BusinessPaymentMethod
                {
                    BusinessId = BUSINESS_ID,
                    CurrencyCode = CURRENCY,
                    PaymentMethodCode = PaymentMethodEnum.Cash.GetCode()
                };
                var newProvider = new Provider
                                  {
                                      RoomCount = ROOM_COUNT,
                                      ContentId = BUSINESS_ID.ToString(),
                                      ProviderTypeCode = PROVIDER_TYPE
                                  };

                var channels = new List<BusinessChannelOptIn>
                    {
                        new BusinessChannelOptIn
                            {
                                Id = CHANNEL_OPT_IN_ID,
                                ChannelId = CHANNEL_ID,
                                ChannelTermsId = CHANNEL_TERMS_ID,
                                BusinessId = BUSINESS_ID
                            }
                    };

                var newBusiness = new Model.Business.Business
                    {
                        Provider = newProvider,
                        WorkingCurrencyCode = CURRENCY,
                        BusinessPaymentMethods = new List<BusinessPaymentMethod>
                        {
                            paymentMethod
                        }
                    };

                businessManager.BusinessDao = businessDao;
                businessManager.BusinessEventDao = businessEventDao;
                businessManager.BusinessChannelOptInDao = businessChannelOptInDao;
                businessManager.DistributionManager = distributionManagerMock;
                businessManager.BusinessChannelOverrideDao = businessChannelOverrideDaoMock;

                businessDao.Expect(x => x.Create(Arg<Model.Business.Business>.Is.Anything))
                           .Return(BUSINESS_ID)
                           .Repeat.Once();
                businessDao.Expect(x => x.AddBusinessOfflinePaymentMethod(Arg<BusinessPaymentMethod>.Matches(bp => bp.BusinessId == paymentMethod.BusinessId &&
                                                                                                                bp.CurrencyCode == paymentMethod.CurrencyCode &&
                                                                                                                bp.PaymentMethodCode == paymentMethod.PaymentMethodCode))).Return(true).Repeat.Once();
                businessDao.Expect(x => x.CreateProvider(Arg<Provider>.Matches(p => p.Id == newProvider.Id &&
                                                                                  p.RoomCount == newProvider.RoomCount &&
                                                                                  p.ContentId == newProvider.ContentId &&
                                                                                  p.ProviderTypeCode == newProvider.ProviderTypeCode))).Return(true).Repeat.Once();

                businessChannelOptInDao.Expect(x => x.GetDefaultChannelsPerBusinessLocation(Arg<long>.Is.Equal(BUSINESS_ID))).Return(channels).Repeat.Once();

                distributionManagerMock.Expect(
                    dmm => dmm.OptInToChannel(Arg<BusinessChannelOptIn>.Matches(bc => bc.Id == CHANNEL_OPT_IN_ID &&
                                                                                      bc.ChannelId == CHANNEL_ID &&
                                                                                      bc.ChannelTermsId ==
                                                                                      CHANNEL_TERMS_ID &&
                                                                                      bc.BusinessId == BUSINESS_ID),
                                              Arg<string>.Is.Anything)).Repeat.Once();

                businessEventDao.Expect(
                    be => be.Create(Arg<BusinessEvent>.Matches(bev => bev.BusinessId == BUSINESS_ID &&
                                                                      bev.EventType.Code == BusinessEventTypesEnum.Created.GetCode())))
                                .Repeat.Once();

                businessChannelOverrideDaoMock.Expect(
                    bco => bco.CreateInitialBusinessChannelOverride(Arg<long?>.Is.Anything, Arg<int?>.Is.Anything)).Repeat.Once();

                // Act
                businessManager.CreateBusiness(newBusiness);

                // Assert
                businessDao.VerifyAllExpectations();
                businessEventDao.VerifyAllExpectations();
                distributionManagerMock.VerifyAllExpectations();
                businessChannelOptInDao.VerifyAllExpectations();
                businessChannelOverrideDaoMock.VerifyAllExpectations();
            }
Beispiel #4
0
        /// <summary>
        /// Modify a provider in db
        /// </summary>
        /// <param name="provider">provider info from business</param>
        public void ModifyProvider(Provider provider)
        {
            const string SQL_UPDATE_PROVIDER_STATEMENT = @"
                            DECLARE @OriginalContentId        varchar(25)
                            DECLARE @ItemId                    int

                            SELECT @OriginalContentId = ContentId
                            FROM Business.Provider
                            WHERE Id = @Id

                            UPDATE Business.Provider    
                                        SET
                                                RoomCount = @RoomCount,
                                                ContentId = @ContentId,
                                                ProviderTypeCode = @ProviderTypeCode
                                        WHERE
                                                Id = @Id
                    
                            IF @@ROWCOUNT > 0 AND @OriginalContentId != @ContentId
                            BEGIN
                                EXEC Business.AddBusinessChangeToPushQueue @BusinessId=@Id, @Action='AttributeChange', @IsOptinActive=1, @UserId=@CreatedByUserId, @ItemId=@ItemId output
                            END";

            var providerParameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BusinessMapper.Parameters.Id, provider.Id),
                DbHelper.CreateParameter(BusinessMapper.Parameters.RoomCount, provider.RoomCount),
                DbHelper.CreateParameter(BusinessMapper.Parameters.ContentId, provider.ContentId),
                DbHelper.CreateParameter(BusinessMapper.Parameters.ProviderTypeCode, provider.ProviderTypeCode),
                DbHelper.CreateParameter(BusinessMapper.Parameters.CreatedByUserId, AuditFieldsHelper.GetUserId())
            };

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

            try
            {
                DbHelper.ExecuteNonQueryCommand(SQL_UPDATE_PROVIDER_STATEMENT, parameters: providerParameters);
            }
            catch (SqlException exception)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30099, "BusinessDao.ModifyProvider", additionalDescriptionParameters: (new object[] { exception.Message }), arguments: new object[] { provider.GetType().Name, provider.Id }));
            }
        }