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(); }
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); }
/// <summary> /// Add business offline payment methods /// </summary> /// <param name="businessPaymentMethod">business offline payment method to add</param> /// <returns>true if add succeeds</returns> public bool AddBusinessOfflinePaymentMethod(BusinessPaymentMethod businessPaymentMethod) { const string SQL_ADD_BUSINESS_OFFLINE_PAYMENT = @"INSERT INTO Business.BusinessPaymentMethod (BusinessId, PaymentMethodCode, CurrencyCode, CardTypeCode, UpdatedByUserId) VALUES (@BusinessId, @PaymentMethodCode, @CurrencyCode, @CardTypeCode, @UpdatedByUserId)"; var parameters = new List<SqlParameter> { DbHelper.CreateParameter(PaymentMapper.Parameters.BusinessId, businessPaymentMethod.BusinessId), DbHelper.CreateParameter(PaymentMapper.Parameters.PaymentMethodCode, businessPaymentMethod.PaymentMethodCode), DbHelper.CreateParameter(PaymentMapper.Parameters.CurrencyCode, businessPaymentMethod.CurrencyCode), DbHelper.CreateParameter(PaymentMapper.Parameters.CardTypeCode, businessPaymentMethod.CardTypeCode) }; AuditFieldsHelper.PopulateAuditFields(parameters); return DbHelper.ExecuteNonQueryCommand(SQL_ADD_BUSINESS_OFFLINE_PAYMENT, parameters: parameters) > 0; }