Exemplo n.º 1
0
        public CalculateDimensionsTests()
        {
            _shippingSettings = new ShippingSettings
            {
                UseCubeRootMethod = true,
                ConsiderAssociatedProductsDimensions = true,
                ShipSeparatelyOneItemEach            = false
            };

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            var pluginService = new FakePluginService();

            _pickupPluginManager   = new PickupPluginManager(new Mock <ICustomerService>().Object, pluginService, _shippingSettings);
            _shippingPluginManager = new ShippingPluginManager(new Mock <ICustomerService>().Object, pluginService, _shippingSettings);

            _storeContext = new Mock <IStoreContext>();
            _storeContext.Setup(x => x.CurrentStore).Returns(new Store {
                Id = 1
            });

            _productService = new FakeProductService(
                productRepository: _fakeDataStore.RegRepository <Product>());

            _shippingService = new FakeShippingService(
                eventPublisher: _eventPublisher.Object,
                pickupPluginManager: _pickupPluginManager,
                shippingPluginManager: _shippingPluginManager,
                storeContext: _storeContext.Object,
                shippingSettings: _shippingSettings);
        }
Exemplo n.º 2
0
        public override void SetUp()
        {
            rm = new List <CustomerCustomerRoleMapping>
            {
                new CustomerCustomerRoleMapping
                {
                    CustomerRoleId = _customerRoleRegistered.Id,
                    CustomerId     = 1
                },
                new CustomerCustomerRoleMapping
                {
                    CustomerRoleId = _customerRoleAdmin.Id,
                    CustomerId     = 1
                }
            }.AsQueryable();
            _discountRepo.Setup(x => x.Table).Returns(Discounts().AsQueryable());
            _discountRepo.Setup(c => c.GetById(It.IsAny <int>())).Returns((int i) => Discounts().FirstOrDefault(c => c.Id == i));
            _discountRequirementRepo.Setup(x => x.Table).Returns(DiscountRequirements().AsQueryable());
            _discountRequirementRepo.Setup(dr => dr.Insert(It.IsAny <DiscountRequirement>())).Callback((DiscountRequirement i) =>
            {
                i.Id = DiscountRequirements().Count() > 0 ? DiscountRequirements().Max(x => x.Id) + 1 : 1;
                DiscountRequirements().Add(i);
            });
            _customerCustomerRoleMapping.Setup(x => x.Table).Returns(rm);
            _customerService.Setup(x => x.GetCustomerRoles(It.IsAny <Customer>(), false)).Returns((Customer i, bool f) =>
            {
                var roles = Roles().Where(y => rm.Where(x => x.CustomerId == i.Id).Select(x => x.CustomerRoleId).Contains(y.Id));
                return(roles.ToList());
            });

            var pluginService = new FakePluginService(customerService: _customerService.Object);

            _discountPluginManager = new DiscountPluginManager(_customerService.Object, pluginService);
        }
Exemplo n.º 3
0
        public new void SetUp()
        {
            var discount1 = new Discount
            {
                Id                 = 1,
                DiscountType       = DiscountType.AssignedToCategories,
                Name               = "Discount 1",
                UsePercentage      = true,
                DiscountPercentage = 10,
                DiscountAmount     = 0,
                DiscountLimitation = DiscountLimitationType.Unlimited,
                LimitationTimes    = 0
            };
            var discount2 = new Discount
            {
                Id                 = 2,
                DiscountType       = DiscountType.AssignedToSkus,
                Name               = "Discount 2",
                UsePercentage      = false,
                DiscountPercentage = 0,
                DiscountAmount     = 5,
                RequiresCouponCode = true,
                CouponCode         = "SecretCode",
                DiscountLimitation = DiscountLimitationType.NTimesPerCustomer,
                LimitationTimes    = 3
            };

            _discountRepo.Setup(x => x.Table).Returns(new List <Discount> {
                discount1, discount2
            }.AsQueryable());

            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));
            _categoryRepo.Setup(x => x.Table).Returns(new List <Category>().AsQueryable());
            _manufacturerRepo.Setup(x => x.Table).Returns(new List <Manufacturer>().AsQueryable());
            _productRepo.Setup(x => x.Table).Returns(new List <Product>().AsQueryable());

            var staticCacheManager = new TestCacheManager();

            _discountRequirementRepo.Setup(x => x.Table).Returns(new List <DiscountRequirement>().AsQueryable());

            var pluginService = new FakePluginService();

            _discountPluginManager = new DiscountPluginManager(new FakeCacheKeyService(), new Mock <ICustomerService>().Object, pluginService);
            _discountService       = new DiscountService(
                new FakeCacheKeyService(),
                _customerService.Object,
                _discountPluginManager,
                _eventPublisher.Object,
                _localizationService.Object,
                _productService.Object,
                _discountRepo.Object,
                _discountRequirementRepo.Object,
                _discountUsageHistoryRepo.Object,
                _orderRepo.Object,
                staticCacheManager,
                _storeContext.Object);
        }
Exemplo n.º 4
0
        public ShippingServiceTests()
        {
            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            _productRepository = _fakeDataStore.RegRepository(new[] {
                new Product
                {
                    Id     = 1,
                    Weight = 1.5M,
                    Height = 2.5M,
                    Length = 3.5M,
                    Width  = 4.5M
                },
                new Product
                {
                    Id     = 2,
                    Weight = 11.5M,
                    Height = 12.5M,
                    Length = 13.5M,
                    Width  = 14.5M
                }
            });

            _productService = new FakeProductService(productRepository: _productRepository, eventPublisher: _eventPublisher.Object);

            _shippingSettings = new ShippingSettings
            {
                ActiveShippingRateComputationMethodSystemNames = new List <string> {
                    "FixedRateTestShippingRateComputationMethod"
                }
            };

            var pluginService = new FakePluginService();

            _pickupPluginManager   = new PickupPluginManager(pluginService, _shippingSettings);
            _shippingPluginManager = new ShippingPluginManager(pluginService, _shippingSettings);

            _storeContext = new Mock <IStoreContext>();
            _storeContext.Setup(x => x.CurrentStore).Returns(new Store {
                Id = 1
            });

            _shippingService = new FakeShippingService(eventPublisher: _eventPublisher.Object,
                                                       pickupPluginManager: _pickupPluginManager,
                                                       productService: _productService,
                                                       shippingPluginManager: _shippingPluginManager,
                                                       storeContext: _storeContext.Object,
                                                       shippingSettings: _shippingSettings);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public new void SetUp()
        {
            var discount1 = new Discount
            {
                Id                 = 1,
                DiscountType       = DiscountType.AssignedToCategories,
                Name               = "Discount 1",
                UsePercentage      = true,
                DiscountPercentage = 10,
                DiscountAmount     = 0,
                DiscountLimitation = DiscountLimitationType.Unlimited,
                LimitationTimes    = 0
            };
            var discount2 = new Discount
            {
                Id                 = 2,
                DiscountType       = DiscountType.AssignedToSkus,
                Name               = "Discount 2",
                UsePercentage      = false,
                DiscountPercentage = 0,
                DiscountAmount     = 5,
                RequiresCouponCode = true,
                CouponCode         = "SecretCode",
                DiscountLimitation = DiscountLimitationType.NTimesPerCustomer,
                LimitationTimes    = 3
            };

            _discountRepo = new FakeRepository <Discount>(new List <Discount> {
                discount1, discount2
            });

            var staticCacheManager = new TestCacheManager();

            var pluginService = new FakePluginService();

            _discountPluginManager = new DiscountPluginManager(new Mock <ICustomerService>().Object, pluginService);
            _discountService       = new DiscountService(
                _customerService.Object,
                _discountPluginManager,
                _localizationService.Object,
                _productService.Object,
                _discountRepo.GetRepository(),
                _discountRequirementRepo,
                _discountUsageHistoryRepo,
                _orderRepo,
                staticCacheManager,
                _storeContext.Object);
        }
Exemplo n.º 7
0
        public new void SetUp()
        {
            _paymentSettings = new PaymentSettings
            {
                ActivePaymentMethodSystemNames = new List <string>()
            };
            _paymentSettings.ActivePaymentMethodSystemNames.Add("Payments.TestMethod");

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            var pluginService = new FakePluginService();

            _shoppingCartSettings = new ShoppingCartSettings();
            _settingService       = new Mock <ISettingService>();
            _paymentPluginManager = new PaymentPluginManager(pluginService, _settingService.Object, _paymentSettings);
            _paymentService       = new PaymentService(_paymentPluginManager, _paymentSettings, _shoppingCartSettings);
        }
Exemplo n.º 8
0
        public new void SetUp()
        {
            _paymentSettings = new PaymentSettings
            {
                ActivePaymentMethodSystemNames = new List <string>()
            };
            _paymentSettings.ActivePaymentMethodSystemNames.Add("Payments.TestMethod");

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            _shoppingCartSettings = new ShoppingCartSettings();
            _httpContextAccessor  = new Mock <IHttpContextAccessor>();
            var settingService = new Mock <ISettingService>();
            var pluginService  = new FakePluginService();

            _paymentPluginManager = new PaymentPluginManager(new FakeCacheKeyService(), new Mock <ICustomerService>().Object, pluginService, settingService.Object, _paymentSettings);
            _paymentService       = new PaymentService(new Mock <ICustomerService>().Object, _httpContextAccessor.Object, _paymentPluginManager, _paymentSettings, _shoppingCartSettings);
        }
        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);
        }
Exemplo n.º 10
0
        public new void SetUp()
        {
            _workContext = new Mock <IWorkContext>();
            _workContext.Setup(w => w.WorkingCurrency).Returns(new Currency {
                RoundingType = RoundingType.Rounding001
            });

            _currencySettings = new CurrencySettings();
            var currency1 = new Currency
            {
                Id               = 1,
                Name             = "Euro",
                CurrencyCode     = "EUR",
                DisplayLocale    = "",
                CustomFormatting = "€0.00",
                DisplayOrder     = 1,
                Published        = true,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow
            };
            var currency2 = new Currency
            {
                Id               = 1,
                Name             = "US Dollar",
                CurrencyCode     = "USD",
                DisplayLocale    = "en-US",
                CustomFormatting = "",
                DisplayOrder     = 2,
                Published        = true,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow
            };

            _currencyRepo = new Mock <IRepository <Currency> >();
            _currencyRepo.Setup(x => x.Table).Returns(new List <Currency> {
                currency1, currency2
            }.AsQueryable());

            _storeMappingService = new Mock <IStoreMappingService>();
            _measureService      = new Mock <IMeasureService>();

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            var pluginService = new FakePluginService();

            _exchangeRatePluginManager = new ExchangeRatePluginManager(_currencySettings, new Mock <ICustomerService>().Object, pluginService);
            _currencyService           = new CurrencyService(_currencySettings,
                                                             new FakeCacheKeyService(),
                                                             null,
                                                             _exchangeRatePluginManager,
                                                             _currencyRepo.Object,
                                                             _storeMappingService.Object);

            _taxSettings = new TaxSettings();

            _localizationService = new Mock <ILocalizationService>();
            _localizationService.Setup(x => x.GetResource("Products.InclTaxSuffix", 1, false, string.Empty, false)).Returns("{0} incl tax");
            _localizationService.Setup(x => x.GetResource("Products.ExclTaxSuffix", 1, false, string.Empty, false)).Returns("{0} excl tax");

            _priceFormatter = new PriceFormatter(_currencySettings, _currencyService, _localizationService.Object,
                                                 _measureService.Object, _workContext.Object, _taxSettings);

            var nopEngine = new Mock <NopEngine>();

            nopEngine.Setup(x => x.ServiceProvider).Returns(new TestServiceProvider());
            EngineContext.Replace(nopEngine.Object);
        }
Exemplo n.º 11
0
        public new void SetUp()
        {
            _productService = new Mock <IProductService>();

            _discountService          = new Mock <IDiscountService>();
            _categoryService          = new Mock <ICategoryService>();
            _manufacturerService      = new Mock <IManufacturerService>();
            _productAttributeParser   = new Mock <IProductAttributeParser>();
            _eventPublisher           = new Mock <IEventPublisher>();
            _localizationService      = new Mock <ILocalizationService>();
            _shippingMethodRepository = new Mock <IRepository <ShippingMethod> >();
            _warehouseRepository      = new Mock <IRepository <Warehouse> >();
            _shipmentService          = new Mock <IShipmentService>();
            _paymentService           = new Mock <IPaymentService>();
            _checkoutAttributeParser  = new Mock <ICheckoutAttributeParser>();
            _giftCardService          = new Mock <IGiftCardService>();
            _genericAttributeService  = new Mock <IGenericAttributeService>();
            _geoLookupService         = new Mock <IGeoLookupService>();
            _countryService           = new Mock <ICountryService>();
            _stateProvinceService     = new Mock <IStateProvinceService>();
            _eventPublisher           = new Mock <IEventPublisher>();
            _addressService           = new Mock <IAddressService>();
            _rewardPointService       = new Mock <IRewardPointService>();
            _webHelper                  = new Mock <IWebHelper>();
            _languageService            = new Mock <ILanguageService>();
            _priceFormatter             = new Mock <IPriceFormatter>();
            _productAttributeFormatter  = new Mock <IProductAttributeFormatter>();
            _shoppingCartService        = new Mock <IShoppingCartService>();
            _checkoutAttributeFormatter = new Mock <ICheckoutAttributeFormatter>();
            _customerService            = new Mock <ICustomerService>();
            _encryptionService          = new Mock <IEncryptionService>();
            _workflowMessageService     = new Mock <IWorkflowMessageService>();
            _customerActivityService    = new Mock <ICustomerActivityService>();
            _currencyService            = new Mock <ICurrencyService>();
            _affiliateService           = new Mock <IAffiliateService>();
            _vendorService              = new Mock <IVendorService>();
            _pdfService                 = new Mock <IPdfService>();
            _customNumberFormatter      = new Mock <ICustomNumberFormatter>();
            _rewardPointService         = new Mock <IRewardPointService>();


            _workContext = null;

            //setup

            _storeContext = new Mock <IStoreContext>();
            _store        = new Store {
                Id = 1
            };
            _storeContext.Setup(x => x.CurrentStore).Returns(_store);

            _catalogSettings = new CatalogSettings();
            var cacheManager = new TestCacheManager();

            _currencySettings = new CurrencySettings();

            //price calculation service
            _priceCalcService = new PriceCalculationService(_catalogSettings, _currencySettings, _categoryService.Object,
                                                            _currencyService.Object, _customerService.Object, _discountService.Object, _manufacturerService.Object, _productAttributeParser.Object,
                                                            _productService.Object, cacheManager, _storeContext.Object, _workContext);

            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            var pluginService = new FakePluginService(_catalogSettings);

            _paymentPluginManager  = new PaymentPluginManager(pluginService, null, _paymentSettings);
            _pickupPluginManager   = new PickupPluginManager(pluginService, _shippingSettings);
            _shippingPluginManager = new ShippingPluginManager(pluginService, _shippingSettings);
            _taxPluginManager      = new TaxPluginManager(pluginService, _taxSettings);

            _shoppingCartSettings = new ShoppingCartSettings();
            //shipping
            _shippingSettings = new ShippingSettings
            {
                ActiveShippingRateComputationMethodSystemNames = new List <string>()
            };
            _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add("FixedRateTestShippingRateComputationMethod");

            _logger           = new NullLogger();
            _customerSettings = new CustomerSettings();
            _addressSettings  = new AddressSettings();

            var shippingMethodCountryMappingRepository = new Mock <IRepository <ShippingMethodCountryMapping> >();

            _shippingService = new ShippingService(_addressService.Object,
                                                   _checkoutAttributeParser.Object,
                                                   _countryService.Object,
                                                   _customerService.Object,
                                                   _eventPublisher.Object,
                                                   _genericAttributeService.Object,
                                                   _localizationService.Object,
                                                   _logger,
                                                   _pickupPluginManager,
                                                   _priceCalcService,
                                                   _productAttributeParser.Object,
                                                   _productService.Object,
                                                   _shippingMethodRepository.Object,
                                                   shippingMethodCountryMappingRepository.Object,
                                                   _warehouseRepository.Object,
                                                   _shippingPluginManager,
                                                   _stateProvinceService.Object,
                                                   _storeContext.Object,
                                                   _shippingSettings,
                                                   _shoppingCartSettings);

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

            _addressService.Setup(x => x.GetAddressById(_taxSettings.DefaultTaxAddressId)).Returns(new Address {
                Id = _taxSettings.DefaultTaxAddressId
            });

            _taxService = new TaxService(_addressSettings,
                                         _customerSettings,
                                         _addressService.Object,
                                         _countryService.Object,
                                         _customerService.Object,
                                         _genericAttributeService.Object,
                                         _geoLookupService.Object,
                                         _logger,
                                         _stateProvinceService.Object,
                                         _storeContext.Object,
                                         _taxPluginManager,
                                         _webHelper.Object,
                                         _workContext,
                                         _shippingSettings,
                                         _taxSettings);

            _rewardPointsSettings = new RewardPointsSettings();

            _recurringPaymentRepository = new Mock <IRepository <RecurringPayment> >();
            var recurringPayments = new List <RecurringPayment>();

            _recurringPaymentRepository.Setup(r => r.Insert(It.IsAny <RecurringPayment>())).Callback((RecurringPayment rph) => recurringPayments.Add(rph));
            _recurringPaymentRepository.Setup(r => r.Table).Returns(recurringPayments.AsQueryable());

            _recurringPaymentHistoryRepository = new Mock <IRepository <RecurringPaymentHistory> >();
            var recurringPaymentHistory = new List <RecurringPaymentHistory>();

            _recurringPaymentHistoryRepository.Setup(r => r.Insert(It.IsAny <RecurringPaymentHistory>())).Callback((RecurringPaymentHistory rph) => recurringPaymentHistory.Add(rph));
            _recurringPaymentHistoryRepository.Setup(r => r.Table).Returns(recurringPaymentHistory.AsQueryable());

            _orderService = new OrderService(_eventPublisher.Object, null, null, null, null, null, null, null, null, _recurringPaymentRepository.Object, _recurringPaymentHistoryRepository.Object, _shipmentService.Object);


            _orderTotalCalcService = new OrderTotalCalculationService(_catalogSettings,
                                                                      _addressService.Object,
                                                                      _checkoutAttributeParser.Object,
                                                                      _customerService.Object,
                                                                      _discountService.Object,
                                                                      _genericAttributeService.Object,
                                                                      _giftCardService.Object,
                                                                      _orderService,
                                                                      _paymentService.Object,
                                                                      _priceCalcService,
                                                                      _productService.Object,
                                                                      _rewardPointService.Object,
                                                                      _shippingPluginManager,
                                                                      _shippingService,
                                                                      _shoppingCartService.Object,
                                                                      _storeContext.Object,
                                                                      _taxService,
                                                                      _workContext,
                                                                      _rewardPointsSettings,
                                                                      _shippingSettings,
                                                                      _shoppingCartSettings,
                                                                      _taxSettings);

            _paymentSettings = new PaymentSettings
            {
                ActivePaymentMethodSystemNames = new List <string>
                {
                    "Payments.TestMethod"
                }
            };
            _orderSettings = new OrderSettings();

            _localizationSettings = new LocalizationSettings();

            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            _orderProcessingService = new OrderProcessingService(_currencySettings,
                                                                 _addressService.Object,
                                                                 _affiliateService.Object,
                                                                 _checkoutAttributeFormatter.Object,
                                                                 _countryService.Object,
                                                                 _currencyService.Object,
                                                                 _customerActivityService.Object,
                                                                 _customerService.Object,
                                                                 _customNumberFormatter.Object,
                                                                 _discountService.Object,
                                                                 _encryptionService.Object,
                                                                 _eventPublisher.Object,
                                                                 _genericAttributeService.Object,
                                                                 _giftCardService.Object,
                                                                 _languageService.Object,
                                                                 _localizationService.Object,
                                                                 _logger,
                                                                 _orderService,
                                                                 _orderTotalCalcService,
                                                                 _paymentPluginManager,
                                                                 _paymentService.Object,
                                                                 _pdfService.Object,
                                                                 _priceCalcService,
                                                                 _priceFormatter.Object,
                                                                 _productAttributeFormatter.Object,
                                                                 _productAttributeParser.Object,
                                                                 _productService.Object,
                                                                 _rewardPointService.Object,
                                                                 _shipmentService.Object,
                                                                 _shippingPluginManager,
                                                                 _shippingService,
                                                                 _shoppingCartService.Object,
                                                                 _stateProvinceService.Object,
                                                                 _storeContext.Object,
                                                                 _taxService,
                                                                 _vendorService.Object,
                                                                 _webHelper.Object,
                                                                 _workContext,
                                                                 _workflowMessageService.Object,
                                                                 _localizationSettings,
                                                                 _orderSettings,
                                                                 _paymentSettings,
                                                                 _rewardPointsSettings,
                                                                 _shippingSettings,
                                                                 _taxSettings);
        }
Exemplo n.º 12
0
        public new void SetUp()
        {
            _currencyUSD = new Currency
            {
                Id               = 1,
                Name             = "US Dollar",
                CurrencyCode     = "USD",
                Rate             = 1.2M,
                DisplayLocale    = "en-US",
                CustomFormatting = "",
                Published        = true,
                DisplayOrder     = 1,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow,
                RoundingType     = RoundingType.Rounding001
            };
            _currencyEUR = new Currency
            {
                Id               = 2,
                Name             = "Euro",
                CurrencyCode     = "EUR",
                Rate             = 1,
                DisplayLocale    = "",
                CustomFormatting = "€0.00",
                Published        = true,
                DisplayOrder     = 2,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow,
                RoundingType     = RoundingType.Rounding001
            };
            _currencyRUR = new Currency
            {
                Id               = 3,
                Name             = "Russian Rouble",
                CurrencyCode     = "RUB",
                Rate             = 34.5M,
                DisplayLocale    = "ru-RU",
                CustomFormatting = "",
                Published        = true,
                DisplayOrder     = 3,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow,
                RoundingType     = RoundingType.Rounding001
            };
            _currencyRepository = new Mock <IRepository <Currency> >();
            _currencyRepository.Setup(x => x.Table).Returns(new List <Currency> {
                _currencyUSD, _currencyEUR, _currencyRUR
            }.AsQueryable());
            _currencyRepository.Setup(x => x.GetById(_currencyUSD.Id)).Returns(_currencyUSD);
            _currencyRepository.Setup(x => x.GetById(_currencyEUR.Id)).Returns(_currencyEUR);
            _currencyRepository.Setup(x => x.GetById(_currencyRUR.Id)).Returns(_currencyRUR);

            _storeMappingService = new Mock <IStoreMappingService>();

            _currencySettings = new CurrencySettings
            {
                PrimaryStoreCurrencyId        = _currencyUSD.Id,
                PrimaryExchangeRateCurrencyId = _currencyEUR.Id
            };

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            var pluginService = new FakePluginService();

            _exchangeRatePluginManager = new ExchangeRatePluginManager(_currencySettings, new FakeCacheKeyService(), new Mock <ICustomerService>().Object, pluginService);
            _currencyService           = new CurrencyService(_currencySettings,
                                                             new FakeCacheKeyService(),
                                                             _eventPublisher.Object,
                                                             _exchangeRatePluginManager,
                                                             _currencyRepository.Object,
                                                             _storeMappingService.Object);
        }
Exemplo n.º 13
0
        public override void SetUp()
        {
            var discount1 = new Discount
            {
                Id                 = 1,
                DiscountType       = DiscountType.AssignedToCategories,
                Name               = "Discount 1",
                CouponCode         = "DiscoutCoupon",
                RequiresCouponCode = true,
                UsePercentage      = true,
                DiscountPercentage = 10,
                DiscountAmount     = 0,
                DiscountLimitation = DiscountLimitationType.Unlimited,
                LimitationTimes    = 0
            };
            var discount2 = new Discount
            {
                Id                 = 2,
                DiscountType       = DiscountType.AssignedToSkus,
                Name               = "Discount 2",
                UsePercentage      = false,
                DiscountPercentage = 0,
                DiscountAmount     = 5,
                RequiresCouponCode = true,
                CouponCode         = "SecretCode",
                DiscountLimitation = DiscountLimitationType.NTimesPerCustomer,
                LimitationTimes    = 3
            };
            var discountList = new List <Discount> {
                discount1, discount2
            }.AsQueryable();
            var discountRequirement = new List <DiscountRequirement>().AsQueryable();

            _permissionService.Setup(x => x.Authorize(StandardPermissionProvider.ManageDiscounts)).Returns(true);
            _discountRepo.Setup(x => x.Table).Returns(discountList);
            _discountRepo.Setup(c => c.GetById(It.IsAny <int>())).Returns((int i) => discountList.FirstOrDefault(c => c.Id == i));
            _discountRequirementRepo.Setup(x => x.Table).Returns(discountRequirement);
            _discountRequirementRepo.Setup(dr => dr.Insert(It.IsAny <DiscountRequirement>())).Callback((DiscountRequirement i) =>
            {
                i.Id = discountRequirement.Count() > 0 ? discountRequirement.Max(x => x.Id) + 1 : 1;
                discountRequirement.ToList().Add(i);
            });

            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));
            var staticCacheManager = new TestCacheManager();
            var pluginService      = new FakePluginService();

            _discountPluginManager = new DiscountPluginManager(new Mock <ICustomerService>().Object, pluginService);
            _discountService       = new DiscountService(
                new FakeCacheKeyService(),
                _customerService.Object,
                _discountPluginManager,
                _eventPublisher.Object,
                _localizationService.Object,
                _productService.Object,
                _discountRepo.Object,
                _discountRequirementRepo.Object,
                _discountUsageHistoryRepo.Object,
                _orderRepo.Object,
                staticCacheManager,
                _storeContext.Object);
        }
Exemplo n.º 14
0
        public new void SetUp()
        {
            _taxSettings = new TaxSettings
            {
                DefaultTaxAddressId = 10
            };

            _workContext  = null;
            _storeContext = new Mock <IStoreContext>();
            _storeContext.Setup(x => x.CurrentStore).Returns(new Store {
                Id = 1
            });

            _addressService = new Mock <IAddressService>();
            //default tax address
            _addressService.Setup(x => x.GetAddressById(_taxSettings.DefaultTaxAddressId)).Returns(new Address {
                Id = _taxSettings.DefaultTaxAddressId
            });

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            _geoLookupService = new Mock <IGeoLookupService>();
            _countryService   = new Mock <ICountryService>();

            _customerRoleRepo = new FakeRepository <CustomerRole>(new List <CustomerRole>
            {
                new CustomerRole
                {
                    Id        = 1,
                    TaxExempt = true,
                    Active    = true
                }
            });

            _customerCustomerRoleMappingRepo = new FakeRepository <CustomerCustomerRoleMapping>();

            _stateProvinceService = new Mock <IStateProvinceService>();
            _logger    = new Mock <ILogger>();
            _webHelper = new Mock <IWebHelper>();
            _genericAttributeService = new Mock <IGenericAttributeService>();

            _customerSettings = new CustomerSettings();
            _shippingSettings = new ShippingSettings();
            _addressSettings  = new AddressSettings();

            _customerService = new CustomerService(new CustomerSettings(),
                                                   _genericAttributeService.Object,
                                                   null,
                                                   null,
                                                   null,
                                                   _customerCustomerRoleMappingRepo,
                                                   null,
                                                   _customerRoleRepo,
                                                   null,
                                                   null,
                                                   new TestCacheManager(),
                                                   _storeContext.Object,
                                                   null);

            var pluginService = new FakePluginService();

            _taxPluginManager = new TaxPluginManager(_customerService, pluginService, _taxSettings);

            _taxService = new TaxService(_addressSettings,
                                         _customerSettings,
                                         _addressService.Object,
                                         _countryService.Object,
                                         _customerService,
                                         _eventPublisher.Object,
                                         _genericAttributeService.Object,
                                         _geoLookupService.Object,
                                         _logger.Object,
                                         _stateProvinceService.Object,
                                         _storeContext.Object,
                                         _taxPluginManager,
                                         _webHelper.Object,
                                         _workContext,
                                         _shippingSettings,
                                         _taxSettings);
        }
        public new void SetUp()
        {
            _currencyUSD = new Currency
            {
                Id               = 1,
                Name             = "US Dollar",
                CurrencyCode     = "USD",
                Rate             = 1.2M,
                DisplayLocale    = "en-US",
                CustomFormatting = "",
                Published        = true,
                DisplayOrder     = 1,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow,
                RoundingType     = RoundingType.Rounding001
            };
            _currencyEUR = new Currency
            {
                Id               = 2,
                Name             = "Euro",
                CurrencyCode     = "EUR",
                Rate             = 1,
                DisplayLocale    = "",
                CustomFormatting = "€0.00",
                Published        = true,
                DisplayOrder     = 2,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow,
                RoundingType     = RoundingType.Rounding001
            };
            _currencyRUR = new Currency
            {
                Id               = 3,
                Name             = "Russian Rouble",
                CurrencyCode     = "RUB",
                Rate             = 34.5M,
                DisplayLocale    = "ru-RU",
                CustomFormatting = "",
                Published        = true,
                DisplayOrder     = 3,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow,
                RoundingType     = RoundingType.Rounding001
            };
            _currencyRepository = new FakeRepository <Currency>(new List <Currency> {
                _currencyUSD, _currencyEUR, _currencyRUR
            });

            _storeMappingService = new Mock <IStoreMappingService>();

            _currencySettings = new CurrencySettings
            {
                PrimaryStoreCurrencyId        = _currencyUSD.Id,
                PrimaryExchangeRateCurrencyId = _currencyEUR.Id
            };

            var pluginService = new FakePluginService();

            _exchangeRatePluginManager = new ExchangeRatePluginManager(_currencySettings, new Mock <ICustomerService>().Object, pluginService);
            _currencyService           = new CurrencyService(_currencySettings,
                                                             _exchangeRatePluginManager,
                                                             _currencyRepository,
                                                             _storeMappingService.Object);
        }
        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);
        }