public void Can_Manage_Two_Baskets_Independently()
        {
            //// Arrange
            var customer1 = PreTestDataWorker.MakeExistingAnonymousCustomer();
            var customer2 = PreTestDataWorker.MakeExistingAnonymousCustomer();
            var basket1   = _itemCacheService.GetItemCacheWithKey(customer1, ItemCacheType.Basket);
            var basket2   = _itemCacheService.GetItemCacheWithKey(customer2, ItemCacheType.Basket);

            //// Act
            basket1.Items.Add(new ItemCacheLineItem(LineItemType.Product, "Kosher Salt", "KS", 1, 2.5M)
            {
                ContainerKey = basket1.Key
            });
            _itemCacheService.Save(basket1);

            basket2.Items.Add(new ItemCacheLineItem(LineItemType.Product, "Kosher Salt", "KS", 1, 2.5M)
            {
                ContainerKey = basket2.Key
            });

            basket2.Items.Add(new ItemCacheLineItem(LineItemType.Product, "Pickle dust", "PD", 20, 25.50M)
            {
                ContainerKey = basket2.Key
            });
            _itemCacheService.Save(basket2);

            //// Assert
            Assert.IsTrue(basket1.HasIdentity);
            Assert.IsTrue(basket2.HasIdentity);
            Assert.AreNotEqual(basket1.Key, basket2.Key);
            Assert.AreEqual(1, basket1.Items.Count);
            Assert.AreEqual(2, basket2.Items.Count);
        }
        public void Init()
        {
            _destination = new Address()
            {
                Name        = "Mindfly Web Design Studio",
                Address1    = "114 W. Magnolia St.  Suite 504",
                Locality    = "Bellingham",
                Region      = "WA",
                PostalCode  = "98225",
                CountryCode = "US"
            };

            PreTestDataWorker.DeleteAllItemCaches();
            PreTestDataWorker.DeleteAllInvoices();
            _customer = PreTestDataWorker.MakeExistingAnonymousCustomer();
            _basket   = Basket.GetBasket(MerchelloContext, _customer);

            for (var i = 0; i < ProductCount; i++)
            {
                _basket.AddItem(PreTestDataWorker.MakeExistingProduct(true, WeightPerProduct, PricePerProduct));
            }

            Basket.Save(MerchelloContext, _basket);

            _shipCountry = ShipCountryService.GetShipCountryByCountryCode(Catalog.Key, "US");
        }
Beispiel #3
0
        public void Init()
        {
            _warehouse = PreTestDataWorker.WarehouseService.GetDefaultWarehouse();

            PreTestDataWorker.DeleteAllProducts();
            _productService        = PreTestDataWorker.ProductService;
            _productVariantService = PreTestDataWorker.ProductVariantService;

            _product = PreTestDataWorker.MakeExistingProduct();
            _product.ProductOptions.Add(new ProductOption("Color"));
            _product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Black", "Blk"));
            _product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blu"));
            _product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            _product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Gre"));
            _product.ProductOptions.Add(new ProductOption("Size"));
            _product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            _product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "M"));
            _product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            _product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));
            _product.Height    = 20;
            _product.Weight    = 20;
            _product.Length    = 20;
            _product.Width     = 20;
            _product.Shippable = true;
            _productService.Save(_product);
        }
Beispiel #4
0
        public void Can_Update_Multiple_Products()
        {
            //// Arrange
            var count     = 4;
            var generated = PreTestDataWorker.MakeExistingProductCollection(count);
            var keys      = new List <Guid>();
            var changed   = new List <IProduct>();
            var name      = "Wizard's hat";

            //// Act
            foreach (var p in generated)
            {
                p.Name = name;
                keys.Add(p.Key);
                changed.Add(p);
            }
            _productService.Save(changed);
            var expected = _productService.GetByKeys(keys);

            //// Assert
            foreach (var p in expected)
            {
                Assert.IsTrue(name == p.Name);
            }
        }
Beispiel #5
0
        public void Can_Rebuild_Product_Index()
        {
            // Arrange
            PreTestDataWorker.DeleteAllProducts();
            var products = MockProductDataMaker.MockProductCollectionForInserting(ProductCount);

            _productService.Save(products);

            //// Act
            var timer = new Stopwatch();

            timer.Start();
            ExamineManager.Instance.IndexProviderCollection["MerchelloProductIndexer"].RebuildIndex();
            timer.Stop();
            Console.Write("Time to index: " + timer.Elapsed.ToString());

            //// Assert
            var searcher = ExamineManager.Instance.SearchProviderCollection["MerchelloProductSearcher"];

            var criteria = searcher.CreateSearchCriteria(Merchello.Examine.IndexTypes.ProductVariant);

            criteria.Field("allDocs", "1");
            var results = searcher.Search(criteria);

            Assert.AreEqual(products.Count(), results.Count());
        }
Beispiel #6
0
        public void Can_Remove_An_Existing_Item_From_A_Basket()
        {
            //// Arrange
            var product1 = PreTestDataWorker.MakeExistingProduct();
            var product2 = PreTestDataWorker.MakeExistingProduct();
            var product3 = PreTestDataWorker.MakeExistingProduct();

            _basket.AddItem(product1);
            _basket.AddItem(product2);
            _basket.AddItem(product3);
            Basket.Save(MerchelloContext.Current, _basket);
            Assert.IsTrue(3 == _basket.Items.Count);

            //// Act
            _basket.RemoveItem(product2.Sku);
            Basket.Save(MerchelloContext.Current, _basket);
            _basket = Basket.GetBasket(MerchelloContext.Current, _customer);

            var price = _basket.TotalBasketPrice;

            Console.WriteLine(price);

            //// Assert
            Assert.IsTrue(2 == _basket.Items.Count);
        }
Beispiel #7
0
        public void Default_BasketPackagingStrategy_Returns_A_Shipment()
        {
            //// Arrange
            var notShippable = PreTestDataWorker.MakeExistingProduct(false);

            _basket.AddItem(notShippable);

            var destination = new Address()
            {
                Name        = "San Diego Zoo",
                Address1    = "2920 Zoo Dr",
                Locality    = "San Diego",
                Region      = "CA",
                PostalCode  = "92101",
                CountryCode = "US"
            };

            _basket.AddItem(notShippable);

            //// Act
            var strategy  = new DefaultWarehousePackagingStrategy(MerchelloContext.Current, _basket.Items, destination, Guid.NewGuid());
            var shipments = strategy.PackageShipments();

            //// Assert
            Assert.NotNull(shipments);
            Assert.AreEqual(1, shipments.Count());
            Assert.AreEqual(4, shipments.First().Items.Count);
        }
Beispiel #8
0
        public void Init()
        {
            PreTestDataWorker.DeleteAllItemCaches();

            _customer = PreTestDataWorker.MakeExistingAnonymousCustomer();
            _basket   = Basket.GetBasket(MerchelloContext.Current, _customer);
        }
Beispiel #9
0
        public void Can_Package_A_Basket_Using_Basket_ExtensionMethod()
        {
            //// Arrange
            var notShippable = PreTestDataWorker.MakeExistingProduct(false);

            _basket.AddItem(notShippable);

            var destination = new Address()
            {
                Name        = "San Diego Zoo",
                Address1    = "2920 Zoo Dr",
                Locality    = "San Diego",
                Region      = "CA",
                PostalCode  = "92101",
                CountryCode = "US"
            };

            //// Act
            var shipments = _basket.PackageBasket(MerchelloContext.Current, destination);

            //// Assert
            Assert.NotNull(shipments);
            Assert.AreEqual(1, shipments.Count());

            Assert.AreEqual(4, shipments.First().Items.Count);
        }
        public void Can_Verify_That_VariantsOnSale_Product_IsMarked_OnSale_Or_NotOnSale()
        {
            //// Arrange
            var product = PreTestDataWorker.MakeExistingProduct();
            var key     = product.Key;

            product.ProductOptions.Add(new ProductOption("Color"));

            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Black", "Black"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Grey", "Grey"));


            _productService.Save(product);

            Assert.IsTrue(product.ProductVariants.Any());
            Assert.IsTrue(product.ProductVariants.All(x => !x.OnSale));
            Assert.IsFalse(product.OnSale);

            //// Act
            foreach (var variant in product.ProductVariants)
            {
                variant.OnSale = true;
            }
            _productService.Save(product);

            //// Assert
            Assert.IsTrue(product.ProductVariants.All(x => x.OnSale), "Not all variants are on sale");
            Assert.IsTrue(product.OnSale, "Product is not on sale");

            product.ProductVariants.First().OnSale = false;
            _productService.Save(product);
            Assert.IsFalse(product.ProductVariants.All(x => x.OnSale), "All variants are on sale");
            Assert.IsFalse(product.OnSale, "Product is on sale");
        }
        public void Can_Remove_A_Choice_From_An_Option()
        {
            //// Arrange
            var catalog = PreTestDataWorker.WarehouseCatalog;
            var product = PreTestDataWorker.MakeExistingProduct();

            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Black", "Black"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            var removeChoice = new ProductAttribute("Grey", "Grey");

            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(removeChoice);
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));

            product.AddToCatalogInventory(catalog);

            _productService.Save(product);

            Assert.AreEqual(1, product.ProductOptions.Count, "ProductOption count is not 1");
            Assert.AreEqual(4, product.ProductVariants.Count, "ProductVariant count is not 4");

            //// Act
            product.ProductOptions.First(x => x.Name == "Color").Choices.RemoveItem(removeChoice.Key);
            _productService.Save(product);

            // Assert
            Assert.IsTrue(product.ProductOptions.First(x => x.Name == "Color").Choices.Count == 3);
            Assert.AreEqual(3, product.ProductVariants.Count, "ProductVariant count is not 3");
        }
Beispiel #12
0
        public void Init()
        {
            _gatewayProviderService = PreTestDataWorker.GatewayProviderService;
            _storeSettingService    = PreTestDataWorker.StoreSettingService;
            _shipCountryService     = PreTestDataWorker.ShipCountryService;


            _catalog = PreTestDataWorker.WarehouseService.GetDefaultWarehouse().WarehouseCatalogs.FirstOrDefault();

            PreTestDataWorker.DeleteAllShipCountries();
            var country     = _storeSettingService.GetCountryByCode("US");
            var shipCountry = new ShipCountry(_catalog.Key, country);

            _shipCountryService.Save(shipCountry);


            var shippingProvider =
                (FixedRateShippingGatewayProvider)MerchelloContext.Gateways.Shipping.CreateInstance(Core.Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey);

            Assert.NotNull(shippingProvider);

            var resource          = shippingProvider.ListResourcesOffered().FirstOrDefault();
            var gatewayShipMethod = shippingProvider.CreateShippingGatewayMethod(resource, shipCountry, "Ground");

            shippingProvider.SaveShippingGatewayMethod(gatewayShipMethod);
        }
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            PreTestDataWorker.DeleteAllCustomers();

            //var bootManager = new WebBootManager();
            //bootManager.Initialize();

            _address = new Address()
            {
                Name        = "Test",
                Address1    = "111 Somewhere Outwhere",
                Locality    = "Out There",
                PostalCode  = "98225",
                Region      = "WA",
                CountryCode = "US",
                Email       = "*****@*****.**"
            };

            InvoiceService.Saved += InvoiceServiceSaved;

            OrderService.Saved += OrderServiceSaved;

            //var invoiceProvider = (InvoiceIndexer)ExamineManager.Instance.IndexProviderCollection["MerchelloInvoiceIndexer"];
            //invoiceProvider.RebuildIndex();
        }
Beispiel #14
0
        public void Can_Retrieve_A_Product_With_3_Options_With_Choices()
        {
            //// Arrange
            var expected = PreTestDataWorker.MakeExistingProduct();
            var key      = expected.Key;

            expected.ProductOptions.Add(new ProductOption("Color"));

            expected.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Black", "Black"));
            expected.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            expected.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Grey", "Grey"));

            expected.ProductOptions.Add(new ProductOption("Size"));
            expected.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            expected.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "M"));
            expected.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            expected.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));

            expected.ProductOptions.Add(new ProductOption("Material"));
            expected.ProductOptions.First(x => x.Name == "Material").Choices.Add(new ProductAttribute("Cotton", "Cotton"));
            expected.ProductOptions.First(x => x.Name == "Material").Choices.Add(new ProductAttribute("Wool", "Wool"));

            _productService.Save(expected);

            //// Act
            var retrieved = _productService.GetByKey(key);

            //// Assert
            Assert.NotNull(retrieved);
            Assert.IsTrue(3 == retrieved.ProductOptions.Count);
            Assert.IsTrue(3 == retrieved.ProductOptions.First(x => x.Name == "Color").Choices.Count);
            Assert.IsFalse(retrieved.IsDirty());
        }
        public void Can_Rebuild_Invoice_Index()
        {
            //// Arrange
            PreTestDataWorker.DeleteAllInvoices();
            var invoice1 = MockInvoiceDataMaker.InvoiceForInserting(_address, 100);
            var invoice2 = MockInvoiceDataMaker.InvoiceForInserting(_address, 200);

            PreTestDataWorker.InvoiceService.Save(invoice1);
            PreTestDataWorker.InvoiceService.Save(invoice2);

            //// Act
            var timer = new Stopwatch();

            timer.Start();
            ExamineManager.Instance.IndexProviderCollection["MerchelloInvoiceIndexer"].RebuildIndex();
            timer.Stop();
            Console.Write("Time to index: " + timer.Elapsed.ToString());

            //// Assert
            var searcher = ExamineManager.Instance.SearchProviderCollection["MerchelloInvoiceSearcher"];

            var criteria = searcher.CreateSearchCriteria(Merchello.Examine.IndexTypes.Invoice);

            criteria.Field("allDocs", "1");
            var results = searcher.Search(criteria);

            Assert.AreEqual(2, results.Count());
        }
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            PreTestDataWorker.DeleteAllPaymentMethods();
            PreTestDataWorker.DeleteAllShipCountries();

            // Merchello CoreBootStrap
            var bootManager = new WebBootManager();

            bootManager.Initialize();

            _merchelloContext = Core.MerchelloContext.Current;

            var defaultCatalog = PreTestDataWorker.WarehouseService.GetDefaultWarehouse().WarehouseCatalogs.FirstOrDefault();

            if (defaultCatalog == null)
            {
                Assert.Ignore("Default WarehouseCatalog is null");
            }

            var us        = _merchelloContext.Services.StoreSettingService.GetCountryByCode("US");
            var usCountry = new ShipCountry(defaultCatalog.Key, us);

            ((ServiceContext)_merchelloContext.Services).ShipCountryService.Save(usCountry);

            #region Settings -> Taxation

            var taxProvider = _merchelloContext.Gateways.Taxation.CreateInstance(Constants.ProviderKeys.Taxation.FixedRateTaxationProviderKey);

            taxProvider.DeleteAllTaxMethods();

            var gwTaxMethod = taxProvider.CreateTaxMethod("US", 0);

            gwTaxMethod.TaxMethod.Provinces["WA"].PercentAdjustment = 8.7M;

            taxProvider.SaveTaxMethod(gwTaxMethod);


            #endregion

            _address = new Address()
            {
                Address1    = "114 W. Magnolia St.",
                Address2    = "Suite 504",
                Locality    = "Bellingham",
                Region      = "WA",
                CountryCode = "US"
            };

            var gateway  = _merchelloContext.Gateways.Payment.GetAllActivatedProviders().FirstOrDefault();
            var provider = _merchelloContext.Gateways.Payment.CreateInstance(gateway.Key);
            var resource = provider.ListResourcesOffered().FirstOrDefault(x => x.ServiceCode == "Cash");
            var method   = provider.CreatePaymentMethod(resource, "Cash", "Cash Payments");
            provider.SavePaymentMethod(method);

            _paymentMethodKey = method.PaymentMethod.Key;
        }
        public void Can_Add_A_New_Product_To_The_Index()
        {
            PreTestDataWorker.DeleteAllProducts();

            //// Arrange
            var provider = (ProductIndexer)ExamineManager.Instance.IndexProviderCollection["MerchelloProductIndexer"];

            provider.RebuildIndex();

            var searcher = ExamineManager.Instance.SearchProviderCollection["MerchelloProductSearcher"];

            var productVariantService = PreTestDataWorker.ProductVariantService;

            //// Act
            var product = MockProductDataMaker.MockProductCollectionForInserting(1).First();

            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));
            product.ProductOptions.Add(new ProductOption("Size"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "Med"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));
            product.Height      = 11M;
            product.Width       = 11M;
            product.Length      = 11M;
            product.CostOfGoods = 15M;
            product.OnSale      = true;
            product.SalePrice   = 18M;
            _productService.Save(product);


            var attributes = new ProductAttributeCollection()
            {
                product.ProductOptions.First(x => x.Name == "Color").Choices.First(x => x.Sku == "Blue"),
                product.ProductOptions.First(x => x.Name == "Size").Choices.First(x => x.Sku == "XL")
            };

            productVariantService.CreateProductVariantWithKey(product, attributes);

            provider.AddProductToIndex(product);

            //// Assert
            var criteria = searcher.CreateSearchCriteria("productvariant", BooleanOperation.And);

            criteria.Field("productKey", product.Key.ToString()).And().Field("master", "true");

            ISearchResults results = searcher.Search(criteria);

            Assert.IsTrue(results.Count() == 1);
            var result = results.First();

            Assert.NotNull(result.Fields["productOptions"]);

            provider.RebuildIndex();
        }
        public void Init()
        {
            if (!_provider.Activated)
            {
                MerchelloContext.Gateways.Notification.ActivateProvider(_provider);
            }

            PreTestDataWorker.DeleteAllNotificationMethods();
        }
Beispiel #19
0
        public void Can_Verify_Attempting_To_Save_A_New_Product_With_An_Existing_Sku_Fails()
        {
            //// Arrange
            var existing    = PreTestDataWorker.MakeExistingProduct();
            var existingSku = existing.Sku;

            //// Act & Assert
            Assert.Throws <ArgumentException>(() => _productService.CreateProductWithKey("Same sku", existingSku, 19M));
        }
Beispiel #20
0
        public void Initialize()
        {
            PreTestDataWorker.DeleteAllAnonymousCustomers();
            PreTestDataWorker.DeleteAllCustomers();

            // create a customer for retrieval tests
            var customer = _customerService.CreateCustomerWithKey(
                FixtureLoginName,
                "firstName",
                "lastName",
                "*****@*****.**");
        }
        public override void Init()
        {
            base.Init();

            PreTestDataWorker.DeleteAllOrders();
            PreTestDataWorker.DeleteAllShipments();
            var invoice = SalePreparationMock.PrepareInvoice();

            PreTestDataWorker.InvoiceService.Save(invoice);
            _order = invoice.PrepareOrder(MerchelloContext);
            PreTestDataWorker.OrderService.Save(_order);
        }
Beispiel #22
0
        public void Can_Add_A_Product_To_A_Basket()
        {
            //// Arrange
            var product = PreTestDataWorker.MakeExistingProduct();

            //// Act
            _basket.AddItem(product.GetProductVariantForPurchase());
            Basket.Save(MerchelloContext.Current, _basket);

            //// Assert
            Assert.IsFalse(_basket.Items.IsEmpty);
        }
Beispiel #23
0
        public void Can_Verify_A_Sku_Exists()
        {
            //// Arrange
            var existing = PreTestDataWorker.MakeExistingProduct();
            var sku      = existing.Sku;

            //// Act
            var skuExists = _productService.SkuExists(sku);

            //// Assert
            Assert.IsTrue(skuExists);
        }
Beispiel #24
0
        public void Can_Retrieve_A_Product_By_Key()
        {
            //// Arrange
            var expected = PreTestDataWorker.MakeExistingProduct();
            var key      = expected.Key;

            //// Act
            var retrieved = _productService.GetByKey(key);

            //// Assert
            Assert.NotNull(retrieved);
            Assert.AreEqual(expected.Key, retrieved.Key);
        }
Beispiel #25
0
        public void Can_Retrieve_A_Product_By_Sku()
        {
            //// Arrange
            var expected = PreTestDataWorker.MakeExistingProduct();
            var sku      = expected.Sku;

            //// Act
            var retrieved = _productService.GetBySku(sku);

            //// Assert
            Assert.NotNull(retrieved);
            Assert.AreEqual(sku, retrieved.Sku);
        }
        public void Can_Add_Choices_To_An_Option()
        {
            //// Arrange
            var product = PreTestDataWorker.MakeExistingProduct();

            product.ProductOptions.Add(new ProductOption("Color"));

            //// Act
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Black", "Black"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Black", "Blue"));

            //// Assert
            Assert.IsTrue(product.ProductOptions.First(x => x.Name == "Color").Choices.Any());
        }
Beispiel #27
0
        public void Can_Delete_A_Product()
        {
            //// Arrange
            var product = PreTestDataWorker.MakeExistingProduct();
            var key     = product.Key;

            //// Act
            _productService.Delete(product);

            //// Assert
            var retrieved = _productService.GetByKey(key);

            Assert.IsNull(retrieved);
        }
        public void Can_Create_A_Product_Then_Add_Options_And_Modify_Choices1()
        {
            //// Arrange
            var catalog = PreTestDataWorker.WarehouseCatalog;
            var product = PreTestDataWorker.MakeExistingProduct();

            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Black", "Black"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            var removeChoice = new ProductAttribute("Grey", "Grey");

            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(removeChoice);
            product.ProductOptions.Add(new ProductOption("Size"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));

            // this creates a record in the CatalogInventory as if the product was marked "shippable"
            // all variants generated with this option will also be marked shippable.
            product.AddToCatalogInventory(catalog);

            _productService.Save(product);

            Assert.AreEqual(2, product.ProductOptions.Count, "ProductOption count is not 2");
            Assert.AreEqual(6, product.ProductVariants.Count, "ProductVariant count is not 6");

            //// Remove a choice
            product.ProductOptions.First(x => x.Name == "Color").Choices.Remove(removeChoice);
            _productService.Save(product);

            // Assert the variants
            Assert.AreEqual(2, product.ProductOptions.Count, "ProductOption count is not 2");
            Assert.AreEqual(4, product.ProductVariants.Count, "ProductVariant count is not 4");

            //// Add a new size
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "Md"));

            _productService.Save(product);
            Assert.AreEqual(2, product.ProductOptions.Count, "ProductOption count is not 2");
            Assert.AreEqual(6, product.ProductVariants.Count, "ProductVariant count is not 6");

            //// Add a new product option
            product.ProductOptions.Add(new ProductOption("Material"));
            product.ProductOptions.First(x => x.Name == "Material").Choices.Add(new ProductAttribute("Wool", "Wool"));
            product.ProductOptions.First(x => x.Name == "Material").Choices.Add(new ProductAttribute("Cotton", "Cotton"));
            _productService.Save(product);

            Assert.AreEqual(3, product.ProductOptions.Count, "ProductOption count is not 3");
            Assert.AreEqual(12, product.ProductVariants.Count, "ProductVariant count is not 12");
        }
        public override void Init()
        {
            base.Init();

            PreTestDataWorker.DeleteAllOrders();
            PreTestDataWorker.DeleteAllShipments();
            var invoice = SalePreparationMock.PrepareInvoice();

            PreTestDataWorker.InvoiceService.Save(invoice);
            _order = invoice.PrepareOrder(MerchelloContext.Current);
            PreTestDataWorker.OrderService.Save(_order);

            _shipMethodKey =
                invoice.ShippingLineItems().FirstOrDefault().ExtendedData.GetShipment <InvoiceLineItem>().ShipMethodKey;
        }
Beispiel #30
0
        public void ShippableProductVisitor_Returns_Only_Shippable_Products()
        {
            //// Arrange
            var notShippable = PreTestDataWorker.MakeExistingProduct(false);

            _basket.AddItem(notShippable);

            const int expected = 4;
            var       visitor  = new ShippableProductVisitor();

            //// Act
            _basket.Accept(visitor);

            //// Assert
            Assert.AreEqual(expected, visitor.ShippableItems.Count());
        }