Exemplo n.º 1
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 TestCacheManager();

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

            _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);
        }
Exemplo n.º 2
0
        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,
                CheckoutAttributeId = ca1.Id
            };
            cav1_2 = new CheckoutAttributeValue
            {
                Id                  = 12,
                Name                = "Red",
                DisplayOrder        = 2,
                CheckoutAttributeId = ca1.Id
            };

            //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,
                CheckoutAttributeId = ca2.Id
            };
            cav2_2 = new CheckoutAttributeValue
            {
                Id                  = 22,
                Name                = "Option 2",
                DisplayOrder        = 2,
                CheckoutAttributeId = ca2.Id
            };

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


            #endregion

            _checkoutAttributeRepo = new FakeRepository <CheckoutAttribute>(new List <CheckoutAttribute> {
                ca1, ca2, ca3
            });

            _checkoutAttributeValueRepo = new FakeRepository <CheckoutAttributeValue>(new List <CheckoutAttributeValue> {
                cav1_1, cav1_2, cav2_1, cav2_2
            });

            var staticCacheManager = new TestCacheManager();

            _storeMappingService = new Mock <IStoreMappingService>();

            _checkoutAttributeService = new CheckoutAttributeService(staticCacheManager,
                                                                     _checkoutAttributeRepo, _checkoutAttributeValueRepo, _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);
        }