Esempio n. 1
0
        public static IDiscountService Init(IQueryable <Discount> discounts = default, IQueryable <DiscountProductMapping> productDiscountMapping = null)
        {
            var staticCacheManager = new TestCacheManager();
            var discountRepo       = new Mock <IRepository <Discount> >();

            discountRepo.Setup(r => r.Table).Returns(discounts);

            var discountRequirementRepo = new Mock <IRepository <DiscountRequirement> >();

            discountRequirementRepo.Setup(x => x.Table).Returns(new List <DiscountRequirement>().AsQueryable());
            var discountUsageHistoryRepo = new Mock <IRepository <DiscountUsageHistory> >();

            var discountMappingRepo = new Mock <IRepository <DiscountMapping> >();

            discountMappingRepo.Setup(x => x.Table).Returns(productDiscountMapping);

            var customerService     = new Mock <ICustomerService>();
            var localizationService = new Mock <ILocalizationService>();
            var productService      = new Mock <IProductService>();

            var eventPublisher = new Mock <IEventPublisher>();

            var pluginService = new FakePluginService();

            var discountPluginManager = new DiscountPluginManager(customerService.Object, pluginService);
            var store = new Store {
                Id = 1
            };
            var storeContext = new Mock <IStoreContext>();

            storeContext.Setup(x => x.CurrentStore).Returns(store);

            var orderRepo = new Mock <IRepository <Order> >();

            var discountService = new TestDiscountService(
                new FakeCacheKeyService(),
                customerService.Object,
                discountPluginManager,
                eventPublisher.Object,
                localizationService.Object,
                productService.Object,
                discountRepo.Object,
                discountRequirementRepo.Object,
                discountUsageHistoryRepo.Object,
                orderRepo.Object,
                staticCacheManager,
                storeContext.Object);

            return(discountService);
        }
Esempio n. 2
0
        public static IDiscountService Init()
        {
            var cacheManager            = new TestCacheManager();
            var discountRepo            = new Mock <IRepository <Discount> >();
            var discountRequirementRepo = new Mock <IRepository <DiscountRequirement> >();

            discountRequirementRepo.Setup(x => x.Table).Returns(new List <DiscountRequirement>().AsQueryable());
            var discountUsageHistoryRepo = new Mock <IRepository <DiscountUsageHistory> >();
            var categoryRepo             = new Mock <IRepository <Category> >();

            categoryRepo.Setup(x => x.Table).Returns(new List <Category>().AsQueryable());
            var manufacturerRepo = new Mock <IRepository <Manufacturer> >();

            manufacturerRepo.Setup(x => x.Table).Returns(new List <Manufacturer>().AsQueryable());
            var productRepo = new Mock <IRepository <Product> >();

            productRepo.Setup(x => x.Table).Returns(new List <Product>().AsQueryable());
            var customerService     = new Mock <ICustomerService>();
            var localizationService = new Mock <ILocalizationService>();
            var eventPublisher      = new Mock <IEventPublisher>();
            var loger     = new Mock <ILogger>();
            var webHelper = new Mock <IWebHelper>();

            var pluginService         = new PluginService(new CatalogSettings(), customerService.Object, loger.Object, CommonHelper.DefaultFileProvider, webHelper.Object);
            var categoryService       = new Mock <ICategoryService>();
            var discountPluginManager = new DiscountPluginManager(pluginService);
            var store = new Store {
                Id = 1
            };
            var storeContext = new Mock <IStoreContext>();

            storeContext.Setup(x => x.CurrentStore).Returns(store);

            var discountService = new TestDiscountService(categoryService.Object,
                                                          customerService.Object,
                                                          discountPluginManager,
                                                          eventPublisher.Object,
                                                          localizationService.Object,
                                                          categoryRepo.Object,
                                                          discountRepo.Object,
                                                          discountRequirementRepo.Object,
                                                          discountUsageHistoryRepo.Object,
                                                          manufacturerRepo.Object,
                                                          productRepo.Object,
                                                          cacheManager,
                                                          storeContext.Object);

            return(discountService);
        }
        public static IDiscountService Init(IQueryable <Discount> discounts = default, IQueryable <DiscountProductMapping> productDiscountMapping = null)
        {
            var staticCacheManager = new TestCacheManager();
            var discountRepo       = new FakeRepository <Discount>(discounts.ToList());

            var discountRequirementRepo  = new FakeRepository <DiscountRequirement>();
            var discountUsageHistoryRepo = new FakeRepository <DiscountUsageHistory>();

            var customerService     = new Mock <ICustomerService>();
            var localizationService = new Mock <ILocalizationService>();
            var productService      = new Mock <IProductService>();

            var pluginService = new FakePluginService();

            var discountPluginManager = new DiscountPluginManager(customerService.Object, pluginService);
            var store = new Store {
                Id = 1
            };
            var storeContext = new Mock <IStoreContext>();

            storeContext.Setup(x => x.CurrentStore).Returns(store);

            var orderRepo = new FakeRepository <Order>();

            var discountService = new TestDiscountService(
                customerService.Object,
                discountPluginManager,
                localizationService.Object,
                productService.Object,
                discountRepo,
                discountRequirementRepo,
                discountUsageHistoryRepo,
                orderRepo,
                staticCacheManager,
                storeContext.Object);

            return(discountService);
        }
        public OrderTotalCalculationServiceTests()
        {
            _shippingSettings = new ShippingSettings
            {
                ActiveShippingRateComputationMethodSystemNames = new List <string> {
                    "FixedRateTestShippingRateComputationMethod"
                },
                AllowPickupInStore = true,
                IgnoreAdditionalShippingChargeForPickupInStore = false
            };

            _taxSettings = new TaxSettings
            {
                ShippingIsTaxable = true,
                PaymentMethodAdditionalFeeIsTaxable = true,
                DefaultTaxAddressId = 10
            };

            var products = new List <Product>
            {
                new Product
                {
                    Id     = 1,
                    Weight = 1.5M,
                    Height = 2.5M,
                    Length = 3.5M,
                    Width  = 4.5M,
                    AdditionalShippingCharge = 5.5M,
                    IsShipEnabled            = true
                },
                new Product
                {
                    Id     = 2,
                    Weight = 11.5M,
                    Height = 12.5M,
                    Length = 13.5M,
                    Width  = 14.5M,
                    AdditionalShippingCharge = 6.5M,
                    IsShipEnabled            = true
                },
                new Product
                {
                    Id     = 3,
                    Weight = 11.5M,
                    Height = 12.5M,
                    Length = 13.5M,
                    Width  = 14.5M,
                    AdditionalShippingCharge = 7.5M,
                    IsShipEnabled            = false
                }
            };

            var productRepository = _fakeDataStore.RegRepository(products);

            _productService = new FakeProductService(productRepository: productRepository);

            var store = new Store {
                Id = 1
            };

            _storeContext.Setup(x => x.CurrentStore).Returns(store);
            _currencyService.Setup(x => x.GetCurrencyById(1)).Returns(new Currency {
                Id = 1, RoundingTypeId = 0
            });
            _addressService.Setup(x => x.GetAddressById(_taxSettings.DefaultTaxAddressId)).Returns(new Address {
                Id = _taxSettings.DefaultTaxAddressId
            });
            _paymentService.Setup(ps => ps.GetAdditionalHandlingFee(It.IsAny <IList <ShoppingCartItem> >(), "test1")).Returns(20);

            _genericAttributeService.Setup(x =>
                                           x.GetAttribute <PickupPoint>(It.IsAny <Customer>(), NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.Object.CurrentStore.Id, null))
            .Returns(new PickupPoint());
            _genericAttributeService.Setup(x => x.GetAttribute <string>(It.IsAny <Customer>(), NopCustomerDefaults.SelectedPaymentMethodAttribute, _storeContext.Object.CurrentStore.Id, null))
            .Returns("test1");

            _customerRoleRepository = _fakeDataStore.RegRepository(new[]
            {
                new CustomerRole
                {
                    Id           = 1,
                    Active       = true,
                    FreeShipping = true
                },
                new CustomerRole
                {
                    Id           = 2,
                    Active       = true,
                    FreeShipping = false
                }
            });

            var customerRepository = _fakeDataStore.RegRepository(new[] { new Customer()
                                                                          {
                                                                              Id = 1
                                                                          } });

            var customerCustomerRoleMappingRepository = _fakeDataStore.RegRepository <CustomerCustomerRoleMapping>();

            _customerService = new FakeCustomerService(
                customerRepository: customerRepository,
                customerRoleRepository: _customerRoleRepository,
                customerCustomerRoleMappingRepository: customerCustomerRoleMappingRepository,
                storeContext: _storeContext.Object);

            var pluginService = new FakePluginService();

            var pickupPluginManager = new PickupPluginManager(_customerService, pluginService, _shippingSettings);

            _shippingPluginManager = new ShippingPluginManager(_customerService, pluginService, _shippingSettings);
            var taxPluginManager      = new TaxPluginManager(_customerService, pluginService, _taxSettings);
            var discountPluginManager = new DiscountPluginManager(_customerService, pluginService);

            var currencySettings = new CurrencySettings {
                PrimaryStoreCurrencyId = 1
            };

            var discountRepository = _fakeDataStore.RegRepository <Discount>();

            _discountService = new FakeDiscountService(
                customerService: _customerService,
                discountPluginManager: discountPluginManager,
                productService: _productService,
                discountRepository: discountRepository,
                storeContext: _storeContext.Object);

            IPriceCalculationService priceCalculationService = new FakePriceCalculationService(
                currencySettings: currencySettings,
                currencyService: _currencyService.Object,
                customerService: _customerService,
                discountService: _discountService,
                productService: _productService,
                storeContext: _storeContext.Object);

            _shoppingCartService = new FakeShoppingCartService(
                productService: _productService,
                customerService: _customerService,
                genericAttributeService: _genericAttributeService.Object,
                priceCalculationService: priceCalculationService,
                shoppingCartSettings: _shoppingCartSettings);

            IShippingService shippingService = new FakeShippingService(customerSerice: _customerService,
                                                                       genericAttributeService: _genericAttributeService.Object,
                                                                       pickupPluginManager: pickupPluginManager,
                                                                       productService: _productService,
                                                                       shippingPluginManager: _shippingPluginManager,
                                                                       storeContext: _storeContext.Object,
                                                                       shippingSettings: _shippingSettings);

            _taxService = new FakeTaxService(
                addressService: _addressService.Object,
                customerService: _customerService,
                genericAttributeService: _genericAttributeService.Object,
                storeContext: _storeContext.Object,
                taxPluginManager: taxPluginManager,
                shippingSettings: _shippingSettings,
                taxSettings: _taxSettings);

            _orderTotalCalcService = new FakeOrderTotalCalculationService(
                addressService: _addressService.Object,
                customerService: _customerService,
                discountService: _discountService,
                genericAttributeService: _genericAttributeService.Object,
                paymentService: _paymentService.Object,
                priceCalculationService: priceCalculationService,
                productService: _productService,
                shippingPluginManager: _shippingPluginManager,
                shippingService: shippingService,
                shoppingCartService: _shoppingCartService,
                storeContext: _storeContext.Object,
                taxService: _taxService,
                shippingSettings: _shippingSettings,
                taxSettings: _taxSettings,
                rewardPointsSettings: _rewardPointsSettings);

            var serviceProvider = new FakeServiceProvider(_shoppingCartService, _paymentService.Object,
                                                          _genericAttributeService.Object, _orderTotalCalcService, _taxService, _taxSettings);

            var nopEngine = new FakeNopEngine(serviceProvider);

            EngineContext.Replace(nopEngine);
        }