public void TestInitialize()
        {
            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            config = new ConfigFileSettingService(new List <ICacheManager> {
                cacheManager
            }, null, null);
        }
        public void TestInitialize()
        {
            //plugin initialization
            new Grand.Services.Tests.ServiceTest().PluginInitializator();

            _shippingSettings = new ShippingSettings();
            _shippingSettings.ActiveShippingRateComputationMethodSystemNames = new List <string>();
            _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add("FixedRateTestShippingRateComputationMethod");

            _shippingMethodRepository = new Mock <IRepository <ShippingMethod> >().Object;
            _deliveryDateRepository   = new Mock <IRepository <DeliveryDate> >().Object;
            _warehouseRepository      = new Mock <IRepository <Warehouse> >().Object;
            _logger = new NullLogger();
            _productAttributeParser  = new Mock <IProductAttributeParser>().Object;
            _checkoutAttributeParser = new Mock <ICheckoutAttributeParser>().Object;
            _serviceProvider         = new Mock <IServiceProvider>().Object;

            var tempEventPublisher = new Mock <IMediator>();
            {
                //tempEventPublisher.Setup(x => x.Publish(It.IsAny<object>()));
                _eventPublisher = tempEventPublisher.Object;
            }

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object, _eventPublisher);

            var pluginFinder = new PluginFinder(_serviceProvider);

            _countryService       = new Mock <ICountryService>().Object;
            _stateProvinceService = new Mock <IStateProvinceService>().Object;
            _currencyService      = new Mock <ICurrencyService>().Object;
            _productService       = new Mock <IProductService>().Object;



            _localizationService = new Mock <ILocalizationService>().Object;
            _addressService      = new Mock <IAddressService>().Object;

            _store = new Store {
                Id = "1"
            };
            var tempStoreContext = new Mock <IStoreContext>();

            {
                tempStoreContext.Setup(x => x.CurrentStore).Returns(_store);
                _storeContext = tempStoreContext.Object;
            }

            _shoppingCartSettings = new ShoppingCartSettings();
        }
Ejemplo n.º 3
0
        public void TestInitialize()
        {
            _articleRepository        = new MongoDBRepositoryTest <KnowledgebaseArticle>();
            _categoryRepository       = new MongoDBRepositoryTest <KnowledgebaseCategory>();
            _articleCommentRepository = new MongoDBRepositoryTest <KnowledgebaseArticleComment>();

            var eventPublisher = new Mock <IMediator>();

            //eventPublisher.Setup(x => x.PublishAsync(new object()));
            _eventPublisher = eventPublisher.Object;

            var customer = new Customer()
            {
                Username = "******"
            };
            var tempWorkContext = new Mock <IWorkContext>();
            {
                _workContext = tempWorkContext.Object;
                tempWorkContext.Setup(x => x.CurrentCustomer).Returns(customer);
            }

            var store            = new Store();
            var tempStoreContext = new Mock <IStoreContext>();
            {
                _storeContext = tempStoreContext.Object;
                tempStoreContext.Setup(x => x.CurrentStore).Returns(store);
            }

            var catalogSettings = new Mock <CatalogSettings>();

            _catalogSettings = catalogSettings.Object;

            var commonSettings = new Mock <CommonSettings>();

            _commonSettings = commonSettings.Object;

            var permissionService = new Mock <IPermissionService>();

            _permissionService = permissionService.Object;

            var _cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object, _eventPublisher);


            _knowledgebaseService = new KnowledgebaseService(_categoryRepository, _articleRepository, _articleCommentRepository, _eventPublisher,
                                                             _workContext, _cacheManager, _storeContext, _commonSettings, _catalogSettings);
        }
Ejemplo n.º 4
0
        public new void SetUp()
        {
            _languageRepo = new Mock <IRepository <Language> >();
            var lang1 = new Language
            {
                Name              = "English",
                LanguageCulture   = "en-Us",
                FlagImageFileName = "us.png",
                Published         = true,
                DisplayOrder      = 1
            };
            var lang2 = new Language
            {
                Name              = "Russian",
                LanguageCulture   = "ru-Ru",
                FlagImageFileName = "ru.png",
                Published         = true,
                DisplayOrder      = 2
            };

            _languageRepo.Setup(x => x.Table).Returns(new List <Language> {
                lang1, lang2
            }.AsQueryable());

            _storeMappingService = new Mock <IStoreMappingService>();

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _settingService = new Mock <ISettingService>();

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

            _localizationSettings = new LocalizationSettings();
            _languageService      = new LanguageService(_eventPublisher.Object, _languageRepo.Object, _settingService.Object, cacheManager, _storeMappingService.Object, _localizationSettings);
        }
        public void TestInitialize()
        {
            _productRepo = new MongoDBRepositoryTest <Product>();
            //dropdown list: adding 2 options "atributes" that can be selected via DropDownList
            pa1 = new ProductAttribute {
                Id   = "1",
                Name = "Color"
            };
            pam1_1 = new ProductAttributeMapping {
                Id                   = "11",
                ProductId            = "1",
                TextPrompt           = "Select color:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.DropdownList,
                DisplayOrder         = 1,
                ProductAttributeId   = pa1.Id
            };
            pav1_1 = new ProductAttributeValue {
                Id           = "11",
                Name         = "Green",
                DisplayOrder = 1,
                ProductAttributeMappingId = pam1_1.Id
            };
            pav1_2 = new ProductAttributeValue {
                Id           = "12",
                Name         = "Red",
                DisplayOrder = 2,
                ProductAttributeMappingId = pam1_1.Id
            };
            //adding colors (as product atributes)
            pam1_1.ProductAttributeValues.Add(pav1_1);
            pam1_1.ProductAttributeValues.Add(pav1_2);

            //checkboxes - adding 2 options that can be ticked via CheckBox'es
            pa2 = new ProductAttribute {
                Id   = "2",
                Name = "Some custom option",
            };
            pam2_1 = new ProductAttributeMapping {
                Id                   = "21",
                ProductId            = "1",
                TextPrompt           = "Select at least one option:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.Checkboxes,
                DisplayOrder         = 2,
                ProductAttributeId   = pa2.Id
            };
            pav2_1 = new ProductAttributeValue {
                Id           = "21",
                Name         = "Option 1",
                DisplayOrder = 1,
                ProductAttributeMappingId = pam2_1.Id
            };
            pav2_2 = new ProductAttributeValue {
                Id           = "22",
                Name         = "Option 2",
                DisplayOrder = 2,
                ProductAttributeMappingId = pam2_1.Id
            };
            pam2_1.ProductAttributeValues.Add(pav2_1);
            pam2_1.ProductAttributeValues.Add(pav2_2);

            //adds custom text (user can add its own text)
            pa3 = new ProductAttribute {
                Id   = "3",
                Name = "Custom text",
            };
            pam3_1 = new ProductAttributeMapping {
                Id                   = "31",
                ProductId            = "1",
                TextPrompt           = "Enter custom text:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.TextBox,
                DisplayOrder         = 1,
                ProductAttributeId   = pa3.Id
            };

            _product = new Product();
            _product.ProductAttributeMappings.Add(pam1_1);
            _product.ProductAttributeMappings.Add(pam2_1);
            _product.ProductAttributeMappings.Add(pam3_1);
            _productRepo.Insert(_product); //26 april

            var tempEventPublisher = new Mock <IMediator>();
            {
                //tempEventPublisher.Setup(x => x.Publish(It.IsAny<object>()));
                _eventPublisher = tempEventPublisher.Object;
            }

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object, _eventPublisher);

            _productAttributeRepo = new Mock <IRepository <ProductAttribute> >().Object;

            _productAttributeService = new ProductAttributeService(cacheManager,
                                                                   _productAttributeRepo,
                                                                   _productRepo,
                                                                   _eventPublisher);
            _productAttributeParser  = new ProductAttributeParser();
            _priceCalculationService = new Mock <IPriceCalculationService>().Object;

            var tempWorkContext = new Mock <IWorkContext>();

            {
                var workingLanguage = new Language();
                tempWorkContext.Setup(x => x.WorkingLanguage).Returns(workingLanguage);
                _workContext = tempWorkContext.Object;
            }
            _currencyService = new Mock <ICurrencyService>().Object;
            var tempLocalizationService = new Mock <ILocalizationService>();

            {
                tempLocalizationService.Setup(x => x.GetResource("GiftCardAttribute.For.Virtual")).Returns("For: {0} <{1}>");
                tempLocalizationService.Setup(x => x.GetResource("GiftCardAttribute.From.Virtual")).Returns("From: {0} <{1}>");
                tempLocalizationService.Setup(x => x.GetResource("GiftCardAttribute.For.Physical")).Returns("For: {0}");
                tempLocalizationService.Setup(x => x.GetResource("GiftCardAttribute.From.Physical")).Returns("From: {0}");
                _localizationService = tempLocalizationService.Object;
            }

            _taxService           = new Mock <ITaxService>().Object;
            _priceFormatter       = new Mock <IPriceFormatter>().Object;
            _downloadService      = new Mock <IDownloadService>().Object;
            _webHelper            = new Mock <IWebHelper>().Object;
            _shoppingCartSettings = new Mock <ShoppingCartSettings>().Object;

            _productAttributeFormatter = new ProductAttributeFormatter(_workContext,
                                                                       _productAttributeService,
                                                                       _productAttributeParser,
                                                                       _currencyService,
                                                                       _localizationService,
                                                                       _taxService,
                                                                       _priceFormatter,
                                                                       _downloadService,
                                                                       _webHelper,
                                                                       _priceCalculationService,
                                                                       _shoppingCartSettings);
        }
        public void TestInitialize()
        {
            //color choosing via DropDownList
            ca1 = new CheckoutAttribute {
                Id                   = "1",
                Name                 = "Color",
                TextPrompt           = "Select color:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.DropdownList,
                DisplayOrder         = 1,
            };
            cav1_1 = new CheckoutAttributeValue {
                Id           = "11",
                Name         = "Green",
                DisplayOrder = 1,
                //CheckoutAttribute = ca1,
                CheckoutAttributeId = ca1.Id,
            };
            cav1_2 = new CheckoutAttributeValue {
                Id           = "12",
                Name         = "Red",
                DisplayOrder = 2,
                //CheckoutAttribute = ca1,
                CheckoutAttributeId = ca1.Id,
            };
            ca1.CheckoutAttributeValues.Add(cav1_1);
            ca1.CheckoutAttributeValues.Add(cav1_2);

            //choosing via CheckBox'es
            ca2 = new CheckoutAttribute {
                Id                   = "2",
                Name                 = "Custom option",
                TextPrompt           = "Select custom option:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.Checkboxes,
                DisplayOrder         = 2,
                //CheckoutAttributeValues
            };

            cav2_1 = new CheckoutAttributeValue {
                Id           = "21",
                Name         = "Option 1",
                DisplayOrder = 1,
                //CheckoutAttribute = ca2,
                CheckoutAttributeId = ca2.Id,
            };
            cav2_2 = new CheckoutAttributeValue {
                Id           = "22",
                Name         = "Option 2",
                DisplayOrder = 2,
                //CheckoutAttribute = ca2,
                CheckoutAttributeId = ca2.Id,
            };
            ca2.CheckoutAttributeValues.Add(cav2_1);
            ca2.CheckoutAttributeValues.Add(cav2_2);

            //via MultiTextBoxes
            ca3 = new CheckoutAttribute {
                Id                   = "3",
                Name                 = "Custom text",
                TextPrompt           = "Enter custom text:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.MultilineTextbox,
                DisplayOrder         = 3,
            };



            var tempCheckoutAttributeRepo = new Mock <IRepository <CheckoutAttribute> >();
            {
                var IMongoCollection = new Mock <IMongoCollection <CheckoutAttribute> >().Object;
                IMongoCollection.InsertOne(ca1);
                IMongoCollection.InsertOne(ca2);
                IMongoCollection.InsertOne(ca3);
                tempCheckoutAttributeRepo.Setup(x => x.Table).Returns(IMongoCollection.AsQueryable());
                tempCheckoutAttributeRepo.Setup(x => x.GetByIdAsync(ca1.Id)).ReturnsAsync(ca1);
                tempCheckoutAttributeRepo.Setup(x => x.GetByIdAsync(ca2.Id)).ReturnsAsync(ca2);
                tempCheckoutAttributeRepo.Setup(x => x.GetByIdAsync(ca3.Id)).ReturnsAsync(ca3);
                _checkoutAttributeRepo = tempCheckoutAttributeRepo.Object;
            }

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _storeMappingService = new Mock <IStoreMappingService>().Object;



            var tempEventPublisher = new Mock <IMediator>();

            {
                //tempEventPublisher.Setup(x => x.PublishAsync(It.IsAny<object>()));
                _eventPublisher = tempEventPublisher.Object;
            }


            _checkoutAttributeService = new CheckoutAttributeService(cacheManager, _checkoutAttributeRepo,
                                                                     _storeMappingService, _eventPublisher, null, null);

            _checkoutAttributeParser = new CheckoutAttributeParser(_checkoutAttributeService);



            var workingLanguage = new Language();
            var tempWorkContext = new Mock <IWorkContext>();

            {
                tempWorkContext.Setup(x => x.WorkingLanguage).Returns(workingLanguage);
                _workContext = tempWorkContext.Object;
            }
            _currencyService = new Mock <ICurrencyService>().Object;
            _taxService      = new Mock <ITaxService>().Object;
            _priceFormatter  = new Mock <IPriceFormatter>().Object;
            _downloadService = new Mock <IDownloadService>().Object;
            _webHelper       = new Mock <IWebHelper>().Object;

            _checkoutAttributeFormatter = new CheckoutAttributeFormatter(_workContext,
                                                                         _checkoutAttributeService,
                                                                         _checkoutAttributeParser,
                                                                         _currencyService,
                                                                         _taxService,
                                                                         _priceFormatter,
                                                                         _downloadService,
                                                                         _webHelper);
        }
Ejemplo n.º 7
0
        public void TestInitialize()
        {
            new Grand.Services.Tests.ServiceTest().PluginInitializator();

            _workContext          = new Mock <IWorkContext>().Object;
            _stateProvinceService = new Mock <IStateProvinceService>().Object;

            _store = new Store {
                Id = "1"
            };
            var tempStoreContext = new Mock <IStoreContext>();

            {
                tempStoreContext.Setup(x => x.CurrentStore).Returns(_store);
                _storeContext = tempStoreContext.Object;
            }

            _productService = new Mock <IProductService>().Object;
            var tempEventPublisher = new Mock <IMediator>();
            {
                //tempEventPublisher.Setup(x => x.PublishAsync(It.IsAny<object>()));
                _eventPublisher = tempEventPublisher.Object;
            }

            var pluginFinder = new PluginFinder(_serviceProvider);
            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object, _eventPublisher);

            _discountService        = new Mock <IDiscountService>().Object;
            _categoryService        = new Mock <ICategoryService>().Object;
            _manufacturerService    = new Mock <IManufacturerService>().Object;
            _productAttributeParser = new Mock <IProductAttributeParser>().Object;
            _vendorService          = new Mock <IVendorService>().Object;
            _currencyService        = new Mock <ICurrencyService>().Object;
            _serviceProvider        = new Mock <IServiceProvider>().Object;

            _shoppingCartSettings   = new ShoppingCartSettings();
            _catalogSettings        = new CatalogSettings();
            _customerService        = new Mock <ICustomerService>().Object;
            _customerProductService = new Mock <ICustomerProductService>().Object;

            _priceCalcService = new PriceCalculationService(_workContext, _storeContext,
                                                            _discountService, _categoryService,
                                                            _manufacturerService, _productAttributeParser, _productService, _customerProductService,
                                                            _vendorService, _currencyService,
                                                            _shoppingCartSettings, _catalogSettings);


            _localizationService = new Mock <ILocalizationService>().Object;

            //shipping
            _shippingSettings = new ShippingSettings();
            _shippingSettings.ActiveShippingRateComputationMethodSystemNames = new List <string>();
            _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add("FixedRateTestShippingRateComputationMethod");
            _shippingMethodRepository = new Mock <IRepository <ShippingMethod> >().Object;
            _deliveryDateRepository   = new Mock <IRepository <DeliveryDate> >().Object;
            _warehouseRepository      = new Mock <IRepository <Warehouse> >().Object;
            _logger                  = new NullLogger();
            _paymentService          = new Mock <IPaymentService>().Object;
            _checkoutAttributeParser = new Mock <ICheckoutAttributeParser>().Object;
            _giftCardService         = new Mock <IGiftCardService>().Object;
            _genericAttributeService = new Mock <IGenericAttributeService>().Object;
            _geoLookupService        = new Mock <IGeoLookupService>().Object;
            _countryService          = new Mock <ICountryService>().Object;
            _customerSettings        = new CustomerSettings();
            _addressSettings         = new AddressSettings();

            //tax
            _taxSettings = new TaxSettings();
            _taxSettings.ShippingIsTaxable = true;
            _taxSettings.PaymentMethodAdditionalFeeIsTaxable = true;
            _taxSettings.DefaultTaxAddressId = "10";

            _shippingService = new ShippingService(_shippingMethodRepository,
                                                   _deliveryDateRepository,
                                                   _warehouseRepository,
                                                   null,
                                                   _logger,
                                                   _productService,
                                                   _productAttributeParser,
                                                   _checkoutAttributeParser,
                                                   _localizationService,
                                                   _addressService,
                                                   _countryService,
                                                   _stateProvinceService,
                                                   pluginFinder,
                                                   _eventPublisher,
                                                   _currencyService,
                                                   cacheManager,
                                                   _shoppingCartSettings,
                                                   _shippingSettings);



            var tempAddressService = new Mock <IAddressService>();

            {
                tempAddressService.Setup(x => x.GetAddressByIdSettings(_taxSettings.DefaultTaxAddressId))
                .ReturnsAsync(new Address {
                    Id = _taxSettings.DefaultTaxAddressId
                });
                _addressService = tempAddressService.Object;
            }

            _taxService = new TaxService(_addressService, _workContext, pluginFinder, _geoLookupService, _countryService, _logger, _taxSettings, _customerSettings, _addressSettings);

            _rewardPointsSettings = new RewardPointsSettings();

            _orderTotalCalcService = new OrderTotalCalculationService(_workContext, _storeContext,
                                                                      _priceCalcService, _taxService, _shippingService, _paymentService,
                                                                      _checkoutAttributeParser, _discountService, _giftCardService,
                                                                      null, _productService, _currencyService, _taxSettings, _rewardPointsSettings,
                                                                      _shippingSettings, _shoppingCartSettings, _catalogSettings);
        }
Ejemplo n.º 8
0
        public void TestInitialize()
        {
            //plugin initialization
            new Grand.Services.Tests.ServiceTest().PluginInitializator();

            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,
            };
            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,
            };
            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,
            };

            var tempCurrencyRepository = new Mock <IRepository <Currency> >();

            {
                var IMongoCollection = new Mock <IMongoCollection <Currency> >().Object;
                IMongoCollection.InsertOne(currencyUSD);
                IMongoCollection.InsertOne(currencyEUR);
                IMongoCollection.InsertOne(currencyRUR);

                tempCurrencyRepository.Setup(x => x.Table).Returns(IMongoCollection.AsQueryable());
                tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyUSD.Id)).ReturnsAsync(currencyUSD);
                tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyEUR.Id)).ReturnsAsync(currencyEUR);
                tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyRUR.Id)).ReturnsAsync(currencyRUR);
                tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyUSD.Id)).ReturnsAsync(currencyUSD);
                tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyEUR.Id)).ReturnsAsync(currencyEUR);
                tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyRUR.Id)).ReturnsAsync(currencyRUR);
                _currencyRepository = tempCurrencyRepository.Object;
            }

            _storeMappingService = new Mock <IStoreMappingService>().Object;
            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _serviceProvider = new Mock <IServiceProvider>().Object;

            _currencySettings = new CurrencySettings();
            _currencySettings.PrimaryStoreCurrencyId        = currencyUSD.Id;
            _currencySettings.PrimaryExchangeRateCurrencyId = currencyEUR.Id;

            var tempEventPublisher = new Mock <IMediator>();

            {
                //tempEventPublisher.Setup(x => x.PublishAsync(It.IsAny<object>()));
                _eventPublisher = tempEventPublisher.Object;
            }

            _currencyService = new CurrencyService(
                cacheManager, _currencyRepository, _storeMappingService,
                _currencySettings, new PluginFinder(_serviceProvider), _eventPublisher);

            //tempDiscountServiceMock.Setup(x => x.GetAllDiscounts(DiscountType.AssignedToCategories, "", "", false)).ReturnsAsync(new List<Discount>());
        }
Ejemplo n.º 9
0
        public new void SetUp()
        {
            measureDimension1 = new MeasureDimension
            {
                Id            = 1,
                Name          = "inch(es)",
                SystemKeyword = "inches",
                Ratio         = 1M,
                DisplayOrder  = 1
            };
            measureDimension2 = new MeasureDimension
            {
                Id            = 2,
                Name          = "feet",
                SystemKeyword = "feet",
                Ratio         = 0.08333333M,
                DisplayOrder  = 2
            };
            measureDimension3 = new MeasureDimension
            {
                Id            = 3,
                Name          = "meter(s)",
                SystemKeyword = "meters",
                Ratio         = 0.0254M,
                DisplayOrder  = 3
            };
            measureDimension4 = new MeasureDimension
            {
                Id            = 4,
                Name          = "millimetre(s)",
                SystemKeyword = "millimetres",
                Ratio         = 25.4M,
                DisplayOrder  = 4
            };

            measureWeight1 = new MeasureWeight
            {
                Id            = 1,
                Name          = "ounce(s)",
                SystemKeyword = "ounce",
                Ratio         = 16M,
                DisplayOrder  = 1
            };
            measureWeight2 = new MeasureWeight
            {
                Id            = 2,
                Name          = "lb(s)",
                SystemKeyword = "lb",
                Ratio         = 1M,
                DisplayOrder  = 2
            };
            measureWeight3 = new MeasureWeight
            {
                Id            = 3,
                Name          = "kg(s)",
                SystemKeyword = "kg",
                Ratio         = 0.45359237M,
                DisplayOrder  = 3
            };
            measureWeight4 = new MeasureWeight
            {
                Id            = 4,
                Name          = "gram(s)",
                SystemKeyword = "grams",
                Ratio         = 453.59237M,
                DisplayOrder  = 4
            };

            _measureDimensionRepository = new Mock <IRepository <MeasureDimension> >();
            _measureDimensionRepository.Setup(x => x.Table).Returns(new List <MeasureDimension> {
                measureDimension1, measureDimension2, measureDimension3, measureDimension4
            }.AsQueryable());
            _measureDimensionRepository.Setup(x => x.GetById(measureDimension1.Id)).Returns(measureDimension1);
            _measureDimensionRepository.Setup(x => x.GetById(measureDimension2.Id)).Returns(measureDimension2);
            _measureDimensionRepository.Setup(x => x.GetById(measureDimension3.Id)).Returns(measureDimension3);
            _measureDimensionRepository.Setup(x => x.GetById(measureDimension4.Id)).Returns(measureDimension4);

            _measureWeightRepository = new Mock <IRepository <MeasureWeight> >();
            _measureWeightRepository.Setup(x => x.Table).Returns(new List <MeasureWeight> {
                measureWeight1, measureWeight2, measureWeight3, measureWeight4
            }.AsQueryable());
            _measureWeightRepository.Setup(x => x.GetById(measureWeight1.Id)).Returns(measureWeight1);
            _measureWeightRepository.Setup(x => x.GetById(measureWeight2.Id)).Returns(measureWeight2);
            _measureWeightRepository.Setup(x => x.GetById(measureWeight3.Id)).Returns(measureWeight3);
            _measureWeightRepository.Setup(x => x.GetById(measureWeight4.Id)).Returns(measureWeight4);

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _measureSettings = new MeasureSettings
            {
                BaseDimensionId = measureDimension1.Id, //inch(es)
                BaseWeightId    = measureWeight2.Id     //lb(s)
            };

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

            _measureService = new MeasureService(cacheManager,
                                                 _eventPublisher.Object,
                                                 _measureDimensionRepository.Object,
                                                 _measureWeightRepository.Object,
                                                 _measureSettings);
        }
Ejemplo n.º 10
0
        public new void SetUp()
        {
            _discountRepo        = new Mock <IRepository <Discount> >();
            _complexDiscountRepo = new Mock <IRepository <ComplexDiscount> >();
            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 = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            _storeContext    = new Mock <IStoreContext>();
            _customerService = new Mock <ICustomerService>();

            _categoryRepo = new Mock <IRepository <Category> >();
            _categoryRepo.Setup(x => x.Table).Returns(new List <Category>().AsQueryable());
            _manufacturerRepo = new Mock <IRepository <Manufacturer> >();
            _manufacturerRepo.Setup(x => x.Table).Returns(new List <Manufacturer>().AsQueryable());
            _productRepo = new Mock <IRepository <Product> >();
            _productRepo.Setup(x => x.Table).Returns(new List <Product>().AsQueryable());

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

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

            _discountUsageHistoryRepo = new Mock <IRepository <DiscountUsageHistory> >();
            var pluginFinder = new PluginFinder(_eventPublisher.Object);

            _localizationService = new Mock <ILocalizationService>();
            _categoryService     = new Mock <ICategoryService>();

            _discountService = new DiscountService(_categoryService.Object,
                                                   _customerService.Object,
                                                   _eventPublisher.Object,
                                                   _localizationService.Object,
                                                   pluginFinder,
                                                   _categoryRepo.Object,
                                                   _discountRepo.Object,
                                                   _complexDiscountRepo.Object,
                                                   _discountRequirementRepo.Object,
                                                   _discountUsageHistoryRepo.Object,
                                                   _manufacturerRepo.Object,
                                                   _productRepo.Object,
                                                   cacheManager,
                                                   _storeContext.Object);
        }
        public void TestInitialize()
        {
            _workContext = null;

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

            var pluginFinder = new PluginFinder();

            _shoppingCartSettings = new ShoppingCartSettings();
            _catalogSettings      = new CatalogSettings();
            _currencySettings     = new CurrencySettings();

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _productService = new Mock <IProductService>().Object;

            //price calculation service
            _discountService           = new Mock <IDiscountService>().Object;
            _categoryService           = new Mock <ICategoryService>().Object;
            _manufacturerService       = new Mock <IManufacturerService>().Object;
            _storeService              = new Mock <IStoreService>().Object;
            _customerService           = new Mock <ICustomerService>().Object;
            _productReservationService = new Mock <IProductReservationService>().Object;
            _currencyService           = new Mock <ICurrencyService>().Object;
            _auctionService            = new Mock <IAuctionService>().Object;

            _productAttributeParser = new Mock <IProductAttributeParser>().Object;
            _priceCalcService       = new PriceCalculationService(_workContext, _storeContext,
                                                                  _discountService, _categoryService, _manufacturerService,
                                                                  _productAttributeParser, _productService, _customerService,
                                                                  cacheManager, _vendorService, _storeService, _currencyService, _shoppingCartSettings, _catalogSettings);

            var tempEventPublisher = new Mock <IEventPublisher>();

            {
                tempEventPublisher.Setup(x => x.Publish(It.IsAny <object>()));
                _eventPublisher = tempEventPublisher.Object;
            }

            _localizationService = new Mock <ILocalizationService>().Object;

            //shipping
            _shippingSettings = new ShippingSettings();
            _shippingSettings.ActiveShippingRateComputationMethodSystemNames = new List <string>();
            _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add("FixedRateTestShippingRateComputationMethod");
            _shippingMethodRepository = new Mock <IRepository <ShippingMethod> >().Object;
            _deliveryDateRepository   = new Mock <IRepository <DeliveryDate> >().Object;
            _warehouseRepository      = new Mock <IRepository <Warehouse> >().Object;
            _pickupPointRepository    = new Mock <IRepository <PickupPoint> >().Object;

            _logger          = new NullLogger();
            _shippingService = new ShippingService(_shippingMethodRepository,
                                                   _deliveryDateRepository,
                                                   _warehouseRepository,
                                                   _pickupPointRepository,
                                                   _logger,
                                                   _productService,
                                                   _productAttributeParser,
                                                   _checkoutAttributeParser,
                                                   _genericAttributeService,
                                                   _localizationService,
                                                   _addressService,
                                                   _shippingSettings,
                                                   pluginFinder,
                                                   _storeContext,
                                                   _eventPublisher,
                                                   _shoppingCartSettings,
                                                   cacheManager,
                                                   null);
            _shipmentService = new Mock <IShipmentService>().Object;


            tempPaymentService = new Mock <IPaymentService>();
            {
                _paymentService = tempPaymentService.Object;
            }
            _checkoutAttributeParser = new Mock <ICheckoutAttributeParser>().Object;
            _giftCardService         = new Mock <IGiftCardService>().Object;
            _genericAttributeService = new Mock <IGenericAttributeService>().Object;

            _geoLookupService = new Mock <IGeoLookupService>().Object;
            _countryService   = new Mock <ICountryService>().Object;
            _customerSettings = new CustomerSettings();
            _addressSettings  = new AddressSettings();

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

            var tempAddressService = new Mock <IAddressService>();

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

            _taxService = new TaxService(_addressService, _workContext, _taxSettings,
                                         pluginFinder, _geoLookupService, _countryService, _logger, _customerSettings, _addressSettings);

            _rewardPointsSettings = new RewardPointsSettings();

            _orderTotalCalcService = new OrderTotalCalculationService(_workContext, _storeContext,
                                                                      _priceCalcService, _taxService, _shippingService, _paymentService,
                                                                      _checkoutAttributeParser, _discountService, _giftCardService,
                                                                      _genericAttributeService, null, _productService, _currencyService,
                                                                      _taxSettings, _rewardPointsSettings, _shippingSettings, _shoppingCartSettings, _catalogSettings);

            _orderService               = new Mock <IOrderService>().Object;
            _webHelper                  = new Mock <IWebHelper>().Object;
            _languageService            = new Mock <ILanguageService>().Object;
            _priceFormatter             = new Mock <IPriceFormatter>().Object;
            _productAttributeFormatter  = new Mock <IProductAttributeFormatter>().Object;
            _shoppingCartService        = new Mock <IShoppingCartService>().Object;
            _checkoutAttributeFormatter = new Mock <ICheckoutAttributeFormatter>().Object;
            _encryptionService          = new Mock <IEncryptionService>().Object;
            _workflowMessageService     = new Mock <IWorkflowMessageService>().Object;
            _customerActivityService    = new Mock <ICustomerActivityService>().Object;
            _currencyService            = new Mock <ICurrencyService>().Object;
            _affiliateService           = new Mock <IAffiliateService>().Object;
            _vendorService              = new Mock <IVendorService>().Object;
            _pdfService                 = new Mock <IPdfService>().Object;

            _paymentSettings = new PaymentSettings
            {
                ActivePaymentMethodSystemNames = new List <string>
                {
                    "Payments.TestMethod"
                }
            };
            _orderSettings        = new OrderSettings();
            _localizationSettings = new LocalizationSettings();
            ICustomerActionEventService tempICustomerActionEventService = new Mock <ICustomerActionEventService>().Object;

            _currencySettings = new CurrencySettings();

            _orderProcessingService = new OrderProcessingService(_orderService, _webHelper,
                                                                 _localizationService, _languageService,
                                                                 _productService, _paymentService, _logger,
                                                                 _orderTotalCalcService, _priceCalcService, _priceFormatter,
                                                                 _productAttributeParser, _productAttributeFormatter,
                                                                 _giftCardService, _shoppingCartService, _checkoutAttributeFormatter,
                                                                 _shippingService, _shipmentService, _taxService,
                                                                 _customerService, _discountService,
                                                                 _encryptionService, _workContext,
                                                                 _workflowMessageService, _vendorService,
                                                                 _customerActivityService, tempICustomerActionEventService,
                                                                 _currencyService, _affiliateService,
                                                                 _eventPublisher, _pdfService, null, null, _storeContext, _productReservationService, _auctionService,
                                                                 _shippingSettings, _paymentSettings, _rewardPointsSettings,
                                                                 _orderSettings, _taxSettings, _localizationSettings);
        }
Ejemplo n.º 12
0
        public void TestInitialize()
        {
            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            tempWorkContext = new Mock <IWorkContext>();
            {
                _workContext = tempWorkContext.Object;
            }
            _currencySettings = new CurrencySettings();
            var currency01 = new Currency
            {
                Id               = "1",
                Name             = "Euro",
                CurrencyCode     = "EUR",
                DisplayLocale    = "",
                CustomFormatting = "€0.00",
                DisplayOrder     = 1,
                Published        = true,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow
            };

            var currency02 = new Currency
            {
                Id               = "1",
                Name             = "US Dollar",
                CurrencyCode     = "USD",
                DisplayLocale    = "en-US",
                CustomFormatting = "",
                DisplayOrder     = 2,
                Published        = true,
                CreatedOnUtc     = DateTime.UtcNow,
                UpdatedOnUtc     = DateTime.UtcNow
            };

            var tempCurrencyRepo = new Mock <IRepository <Currency> >();

            {
                var tempIMongoCollection = new Mock <IMongoCollection <Currency> >().Object;
                tempIMongoCollection.InsertOne(currency01);
                tempIMongoCollection.InsertOne(currency02);
                tempCurrencyRepo.Setup(x => x.Table).Returns(tempIMongoCollection.AsQueryable());
            }

            _storeMappingService = new Mock <IStoreMappingService>().Object;
            _serviceProvider     = new Mock <IServiceProvider>().Object;

            _currencyRepo = new Mock <IRepository <Currency> >().Object;

            var pluginFinder = new PluginFinder(_serviceProvider);

            _currencyService = new CurrencyService(
                cacheManager,
                _currencyRepo,
                _storeMappingService,
                _currencySettings,
                pluginFinder,
                null);

            _taxSettings = new TaxSettings();

            var tempLocalizationService = new Mock <ILocalizationService>();

            {
                tempLocalizationService.Setup(x => x.GetResource("Products.InclTaxSuffix", "1", false, "", false)).Returns("{0} incl tax");
                tempLocalizationService.Setup(x => x.GetResource("Products.ExclTaxSuffix", "1", false, "", false)).Returns("{0} excl tax");
                _localizationService = tempLocalizationService.Object;
            }

            _priceFormatter = new PriceFormatter(_workContext, _currencyService, _localizationService, _taxSettings, _currencySettings);
        }
Ejemplo n.º 13
0
        public void TestInitialize()
        {
            tempWorkContext = new Mock <IWorkContext>();
            {
                tempWorkContext.Setup(instance => instance.WorkingCurrency).Returns(_currency);
                _workContext = tempWorkContext.Object;
            }
            var tempStoreContext = new Mock <IStoreContext>();

            {
                _store = new Store {
                    Id = "1"
                };
                tempStoreContext.Setup(instance => instance.CurrentStore).Returns(_store);
                _storeContext = tempStoreContext.Object;
            }


            tempDiscountServiceMock = new Mock <IDiscountService>();
            {
                _discountService = tempDiscountServiceMock.Object;
            }

            _categoryService     = new Mock <ICategoryService>().Object;
            _manufacturerService = new Mock <IManufacturerService>().Object;
            _vendorService       = new Mock <IVendorService>().Object;
            _customerService     = new Mock <ICustomerService>().Object;



            tempProductService = new Mock <IProductService>();
            {
                _productService = tempProductService.Object;
            }
            _productAttributeParser = new Mock <IProductAttributeParser>().Object;
            _shoppingCartSettings   = new ShoppingCartSettings();
            _catalogSettings        = new CatalogSettings();
            _customerProductService = new Mock <ICustomerProductService>().Object;
            var eventPublisher = new Mock <IMediator>();

            _eventPublisher = eventPublisher.Object;

            _currencySettings = new CurrencySettings();
            _currencySettings.PrimaryExchangeRateCurrencyId = "1";
            _currencySettings.PrimaryStoreCurrencyId        = "1";
            //_currencyService = new Mock<ICurrencyService>().Object;
            _currency = new Currency {
                Id = "1", CurrencyCode = "USD", Rate = 1, Published = true, MidpointRound = System.MidpointRounding.ToEven, RoundingType = RoundingType.Rounding001
            };

            var tempCurrency = new Mock <ICurrencyService>();
            {
                tempCurrency.Setup(instance => instance.GetPrimaryStoreCurrency()).Returns(Task.FromResult(_currency));
                //tempCurrency.Setup(instance => instance.ConvertToPrimaryStoreCurrency(It.IsAny<decimal>(), _currency)).ReturnsAsync(5);
                //_currencyService = tempCurrency.Object;
            }
            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object, _eventPublisher);
            IRepository <Currency> _currencyRepository;
            var tempCurrencyRepository = new Mock <IRepository <Currency> >();
            {
                var IMongoCollection = new Mock <IMongoCollection <Currency> >().Object;
                IMongoCollection.InsertOne(_currency);


                tempCurrencyRepository.Setup(x => x.Table).Returns(IMongoCollection.AsQueryable());
                tempCurrencyRepository.Setup(x => x.GetByIdAsync(_currency.Id)).ReturnsAsync(_currency);
                _currencyRepository = tempCurrencyRepository.Object;
            }

            IStoreMappingService _storeMappingService = new Mock <IStoreMappingService>().Object;
            var _serviceProvider = new Mock <IServiceProvider>().Object;

            _currencyService = new CurrencyService(
                cacheManager, _currencyRepository, _storeMappingService,
                _currencySettings, new PluginFinder(_serviceProvider), _eventPublisher);


            _priceCalcService = new PriceCalculationService(
                _workContext,
                _storeContext,
                _discountService,
                _categoryService,
                _manufacturerService,
                _productAttributeParser,
                _productService,
                _customerProductService,
                _vendorService,
                _currencyService,
                _shoppingCartSettings,
                _catalogSettings);
        }
        public new void SetUp()
        {
            #region Test data

            //color (dropdownlist)
            ca1 = new CheckoutAttribute
            {
                Id                   = 1,
                Name                 = "Color",
                TextPrompt           = "Select color:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.DropdownList,
                DisplayOrder         = 1
            };
            cav1_1 = new CheckoutAttributeValue
            {
                Id                  = 11,
                Name                = "Green",
                DisplayOrder        = 1,
                CheckoutAttribute   = ca1,
                CheckoutAttributeId = ca1.Id
            };
            cav1_2 = new CheckoutAttributeValue
            {
                Id                  = 12,
                Name                = "Red",
                DisplayOrder        = 2,
                CheckoutAttribute   = ca1,
                CheckoutAttributeId = ca1.Id
            };
            ca1.CheckoutAttributeValues.Add(cav1_1);
            ca1.CheckoutAttributeValues.Add(cav1_2);

            //custom option (checkboxes)
            ca2 = new CheckoutAttribute
            {
                Id                   = 2,
                Name                 = "Custom option",
                TextPrompt           = "Select custom option:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.Checkboxes,
                DisplayOrder         = 2
            };
            cav2_1 = new CheckoutAttributeValue
            {
                Id                  = 21,
                Name                = "Option 1",
                DisplayOrder        = 1,
                CheckoutAttribute   = ca2,
                CheckoutAttributeId = ca2.Id
            };
            cav2_2 = new CheckoutAttributeValue
            {
                Id                  = 22,
                Name                = "Option 2",
                DisplayOrder        = 2,
                CheckoutAttribute   = ca2,
                CheckoutAttributeId = ca2.Id
            };
            ca2.CheckoutAttributeValues.Add(cav2_1);
            ca2.CheckoutAttributeValues.Add(cav2_2);

            //custom text
            ca3 = new CheckoutAttribute
            {
                Id                   = 3,
                Name                 = "Custom text",
                TextPrompt           = "Enter custom text:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.MultilineTextbox,
                DisplayOrder         = 3
            };


            #endregion

            _checkoutAttributeRepo = new Mock <IRepository <CheckoutAttribute> >();
            _checkoutAttributeRepo.Setup(x => x.Table).Returns(new List <CheckoutAttribute> {
                ca1, ca2, ca3
            }.AsQueryable());
            _checkoutAttributeRepo.Setup(x => x.GetById(ca1.Id)).Returns(ca1);
            _checkoutAttributeRepo.Setup(x => x.GetById(ca2.Id)).Returns(ca2);
            _checkoutAttributeRepo.Setup(x => x.GetById(ca3.Id)).Returns(ca3);

            _checkoutAttributeValueRepo = new Mock <IRepository <CheckoutAttributeValue> >();
            _checkoutAttributeValueRepo.Setup(x => x.Table).Returns(new List <CheckoutAttributeValue> {
                cav1_1, cav1_2, cav2_1, cav2_2
            }.AsQueryable());
            _checkoutAttributeValueRepo.Setup(x => x.GetById(cav1_1.Id)).Returns(cav1_1);
            _checkoutAttributeValueRepo.Setup(x => x.GetById(cav1_2.Id)).Returns(cav1_2);
            _checkoutAttributeValueRepo.Setup(x => x.GetById(cav2_1.Id)).Returns(cav2_1);
            _checkoutAttributeValueRepo.Setup(x => x.GetById(cav2_2.Id)).Returns(cav2_2);

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _storeMappingService = new Mock <IStoreMappingService>();

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

            _checkoutAttributeService = new CheckoutAttributeService(cacheManager, _eventPublisher.Object,
                                                                     _checkoutAttributeRepo.Object, _checkoutAttributeValueRepo.Object, _storeMappingService.Object);

            _checkoutAttributeParser = new CheckoutAttributeParser(_checkoutAttributeService);

            var workingLanguage = new Language();
            _workContext = new Mock <IWorkContext>();
            _workContext.Setup(x => x.WorkingLanguage).Returns(workingLanguage);
            _currencyService     = new Mock <ICurrencyService>();
            _taxService          = new Mock <ITaxService>();
            _priceFormatter      = new Mock <IPriceFormatter>();
            _downloadService     = new Mock <IDownloadService>();
            _webHelper           = new Mock <IWebHelper>();
            _localizationService = TestLocalizationService.Init();

            //_localizationService.Setup(ls=>ls.GetLocalized(It.IsAny<CheckoutAttribute>(), attribute => attribute.Name, It.IsAny<int?>(), true, true)).Returns()

            _checkoutAttributeFormatter = new CheckoutAttributeFormatter(_checkoutAttributeParser,
                                                                         _checkoutAttributeService, _currencyService.Object, _downloadService.Object, _localizationService,
                                                                         _priceFormatter.Object, _taxService.Object, _webHelper.Object, _workContext.Object);
        }
Ejemplo n.º 15
0
        public new void SetUp()
        {
            #region Test data

            //color (dropdownlist)
            pa1 = new ProductAttribute
            {
                Id   = 1,
                Name = "Color"
            };
            pam1_1 = new ProductAttributeMapping
            {
                Id                   = 11,
                ProductId            = 1,
                TextPrompt           = "Select color:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.DropdownList,
                DisplayOrder         = 1,
                ProductAttribute     = pa1,
                ProductAttributeId   = pa1.Id
            };
            pav1_1 = new ProductAttributeValue
            {
                Id                        = 11,
                Name                      = "Green",
                DisplayOrder              = 1,
                ProductAttributeMapping   = pam1_1,
                ProductAttributeMappingId = pam1_1.Id
            };
            pav1_2 = new ProductAttributeValue
            {
                Id                        = 12,
                Name                      = "Red",
                DisplayOrder              = 2,
                ProductAttributeMapping   = pam1_1,
                ProductAttributeMappingId = pam1_1.Id
            };
            pam1_1.ProductAttributeValues.Add(pav1_1);
            pam1_1.ProductAttributeValues.Add(pav1_2);

            //custom option (checkboxes)
            pa2 = new ProductAttribute
            {
                Id   = 2,
                Name = "Some custom option"
            };
            pam2_1 = new ProductAttributeMapping
            {
                Id                   = 21,
                ProductId            = 1,
                TextPrompt           = "Select at least one option:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.Checkboxes,
                DisplayOrder         = 2,
                ProductAttribute     = pa2,
                ProductAttributeId   = pa2.Id
            };
            pav2_1 = new ProductAttributeValue
            {
                Id                        = 21,
                Name                      = "Option 1",
                DisplayOrder              = 1,
                ProductAttributeMapping   = pam2_1,
                ProductAttributeMappingId = pam2_1.Id
            };
            pav2_2 = new ProductAttributeValue
            {
                Id                        = 22,
                Name                      = "Option 2",
                DisplayOrder              = 2,
                ProductAttributeMapping   = pam2_1,
                ProductAttributeMappingId = pam2_1.Id
            };
            pam2_1.ProductAttributeValues.Add(pav2_1);
            pam2_1.ProductAttributeValues.Add(pav2_2);

            //custom text
            pa3 = new ProductAttribute
            {
                Id   = 3,
                Name = "Custom text"
            };
            pam3_1 = new ProductAttributeMapping
            {
                Id                   = 31,
                ProductId            = 1,
                TextPrompt           = "Enter custom text:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.TextBox,
                DisplayOrder         = 1,
                ProductAttribute     = pa1,
                ProductAttributeId   = pa3.Id
            };

            //option radio
            pa4 = new ProductAttribute
            {
                Id   = 4,
                Name = "Radio list"
            };
            pam4_1 = new ProductAttributeMapping
            {
                Id                   = 41,
                ProductId            = 1,
                TextPrompt           = "Select option and enter the quantity:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.RadioList,
                DisplayOrder         = 2,
                ProductAttribute     = pa4,
                ProductAttributeId   = pa4.Id
            };
            pav4_1 = new ProductAttributeValue
            {
                Id                        = 41,
                Name                      = "Option with quantity",
                DisplayOrder              = 1,
                ProductAttributeMapping   = pam4_1,
                ProductAttributeMappingId = pam4_1.Id
            };

            #endregion

            _productAttributeRepo = new Mock <IRepository <ProductAttribute> >();
            _productAttributeRepo.Setup(x => x.Table).Returns(new List <ProductAttribute> {
                pa1, pa2, pa3, pa4
            }.AsQueryable());
            _productAttributeRepo.Setup(x => x.GetById(pa1.Id)).Returns(pa1);
            _productAttributeRepo.Setup(x => x.GetById(pa2.Id)).Returns(pa2);
            _productAttributeRepo.Setup(x => x.GetById(pa3.Id)).Returns(pa3);
            _productAttributeRepo.Setup(x => x.GetById(pa4.Id)).Returns(pa4);

            _productAttributeMappingRepo = new Mock <IRepository <ProductAttributeMapping> >();
            _productAttributeMappingRepo.Setup(x => x.Table).Returns(new List <ProductAttributeMapping> {
                pam1_1, pam2_1, pam3_1, pam4_1
            }.AsQueryable());
            _productAttributeMappingRepo.Setup(x => x.GetById(pam1_1.Id)).Returns(pam1_1);
            _productAttributeMappingRepo.Setup(x => x.GetById(pam2_1.Id)).Returns(pam2_1);
            _productAttributeMappingRepo.Setup(x => x.GetById(pam3_1.Id)).Returns(pam3_1);
            _productAttributeMappingRepo.Setup(x => x.GetById(pam4_1.Id)).Returns(pam4_1);

            _productAttributeCombinationRepo = new Mock <IRepository <ProductAttributeCombination> >();
            _productAttributeCombinationRepo.Setup(x => x.Table).Returns(new List <ProductAttributeCombination>().AsQueryable());

            _productAttributeValueRepo = new Mock <IRepository <ProductAttributeValue> >();
            _productAttributeValueRepo.Setup(x => x.Table).Returns(new List <ProductAttributeValue> {
                pav1_1, pav1_2, pav2_1, pav2_2, pav4_1
            }.AsQueryable());
            _productAttributeValueRepo.Setup(x => x.GetById(pav1_1.Id)).Returns(pav1_1);
            _productAttributeValueRepo.Setup(x => x.GetById(pav1_2.Id)).Returns(pav1_2);
            _productAttributeValueRepo.Setup(x => x.GetById(pav2_1.Id)).Returns(pav2_1);
            _productAttributeValueRepo.Setup(x => x.GetById(pav2_2.Id)).Returns(pav2_2);
            _productAttributeValueRepo.Setup(x => x.GetById(pav4_1.Id)).Returns(pav4_1);

            _predefinedProductAttributeValueRepo = new Mock <IRepository <PredefinedProductAttributeValue> >();

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

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _productAttributeService = new ProductAttributeService(cacheManager,
                                                                   _eventPublisher.Object,
                                                                   _predefinedProductAttributeValueRepo.Object,
                                                                   _productAttributeRepo.Object,
                                                                   _productAttributeCombinationRepo.Object,
                                                                   _productAttributeMappingRepo.Object,
                                                                   _productAttributeValueRepo.Object);

            _context = new Mock <IDbContext>();

            _productAttributeParser = new ProductAttributeParser(_context.Object, _productAttributeService);

            _priceCalculationService = new Mock <IPriceCalculationService>();

            var workingLanguage = new Language();
            _workContext = new Mock <IWorkContext>();
            _workContext.Setup(x => x.WorkingLanguage).Returns(workingLanguage);
            _currencyService     = new Mock <ICurrencyService>();
            _localizationService = TestLocalizationService.Init();

            _taxService           = new Mock <ITaxService>();
            _priceFormatter       = new Mock <IPriceFormatter>();
            _downloadService      = new Mock <IDownloadService>();
            _webHelper            = new Mock <IWebHelper>();
            _shoppingCartSettings = new ShoppingCartSettings();

            _productAttributeFormatter = new ProductAttributeFormatter(_currencyService.Object,
                                                                       _downloadService.Object,
                                                                       _localizationService,
                                                                       _priceCalculationService.Object,
                                                                       _priceFormatter.Object,
                                                                       _productAttributeParser,
                                                                       _taxService.Object,
                                                                       _webHelper.Object,
                                                                       _workContext.Object,
                                                                       _shoppingCartSettings);
        }
Ejemplo n.º 16
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>();

            var cacheManager = new TestMemoryCacheManager(new Mock <IMemoryCache>().Object);

            _currencySettings = new CurrencySettings
            {
                PrimaryStoreCurrencyId        = currencyUSD.Id,
                PrimaryExchangeRateCurrencyId = currencyEUR.Id
            };

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

            var pluginFinder = new PluginFinder(_eventPublisher.Object);

            _currencyService = new CurrencyService(_currencySettings, _eventPublisher.Object, pluginFinder, _currencyRepository.Object, cacheManager, _storeMappingService.Object);
        }