public void BuildProductListFromVariantItemsPriceTest()
        {
            // Arrange
            var rules = new DefaultSiteRules();

            var productList = new ProductItemPagedList
            {
                ItemCount = 3,
                Items     = new ProductItemList
                {
                    new ProductItem {
                        Id = 1, GroupByKey = "v1", Name = "P1",
                    },
                    new ProductItem {
                        Id = 2, GroupByKey = "v2", Name = "P2",
                    },
                    new ProductItem {
                        Id = 3, GroupByKey = "v3", Name = "P3",
                    },
                }
            };

            var variantList = new VariantItemList
            {
                new VariantItem
                {
                    Id = 1, GroupByKey = "v1", Name = "P1", Price = new ProductPrice {
                        Value = 1.00M, Catalog = 1.00M, VatRate = 1.25M, PriceListId = 1
                    },
                    OnHand = new OnHand {
                        Value = 3, IsActive = true
                    },
                },
                new VariantItem
                {
                    Id = 2, GroupByKey = "v2", Name = "P2", Price = new ProductPrice {
                        Value = 2.00M, Catalog = 2.00M, VatRate = 1.25M, PriceListId = 2
                    },
                    OnHand = new OnHand {
                        Value = 3, IsActive = true
                    },
                },
                new VariantItem
                {
                    Id = 3, GroupByKey = "v3", Name = "P3", Price = new ProductPrice {
                        Value = 3.00M, Catalog = 3.00M, VatRate = 1.25M, PriceListId = 3
                    },
                    OnHand = new OnHand {
                        Value = 3, IsActive = true
                    },
                },
            };


            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            stormContext.Stub(x => x.CultureCode).Return("sv");
            StormContext.SetInstance(stormContext);

            var dictionary = MockRepository.GenerateMock <IApplicationDictionary>();

            // Act
            var productBuilder = new ProductListBuilder(dictionary, rules);
            var result         = productBuilder.BuildProductList(productList, variantList);

            // Assert
            Assert.AreNotEqual(null, result);
            Assert.AreEqual(3, result.ItemCount);
            Assert.AreEqual(1M, result.Items[0].Price.Display);
            Assert.AreEqual(2M, result.Items[1].Price.Display);
            Assert.AreEqual(3M, result.Items[2].Price.Display);
        }
        public void BuildProductListFromVariantItemsTest()
        {
            // Arrange
            var rules = new DefaultSiteRules();

            var productList = new ProductItemPagedList
            {
                ItemCount = 1,
                Items     = new ProductItemList
                {
                    new ProductItem
                    {
                        Id           = 1,
                        Name         = "Handske",
                        CategoryId   = 1,
                        Manufacturer = new ProductManufacturer {
                            Id = 1, Name = "Manufacturer"
                        },
                        AdditionalImageKeySeed = "14:" + Guid.Empty,
                        FlagIdSeed             = "",
                        Price  = 100.00M, PriceCatalog = 100.00M, VatRate = 1.25M, RecommendedQuantity = 1.000M,
                        OnHand = new OnHand {
                            Value = 10, IsActive = true
                        },
                        OnHandStore = new OnHand {
                            IsActive = false
                        },
                        OnHandSupplier = new OnHand {
                            IsActive = false
                        },
                        Key                    = Guid.NewGuid(),
                        ImageKey               = Guid.NewGuid(),
                        StatusId               = 1,
                        Type                   = 1,
                        GroupByKey             = "v1",
                        ParametricListSeed     = "111:11,112:12,200:20,300:30",
                        ParametricMultipleSeed = "113:13,113:14",
                        ParametricValueSeed    = "115:15,116:16,117:17,117:18",
                        VariantParametricSeed  = "200,300",
                    }
                }
            };

            var variantList = new VariantItemList
            {
                new VariantItem
                {
                    Id    = 1, GroupByKey = "v1", Name = "Handske 1", TypeId = 1, PartNo = "P1", ManufacturerPartNo = "P1", FlagIdSeed = "1", ImageKey = productList.Items[0].ImageKey,
                    Price = new ProductPrice {
                        Value = 100.00M, Catalog = 100.00M, VatRate = 1.25M, PriceListId = 1, IsBuyable = true, RecommendedQuantity = 1, IsRecommendedQuantityFixed = true
                    },
                    OnHand = new OnHand {
                        Value = 3, IsActive = true
                    },
                    Parametrics = new ParametricsSeed {
                        ListSeed = "200:20,300:30", MultipleSeed = "117:17", ValueSeed = ""
                    },
                    AdditionalImageKeySeed = "58:" + Guid.NewGuid()
                },
                new VariantItem
                {
                    Id    = 2, GroupByKey = "v1", Name = "Handske 2", TypeId = 1, PartNo = "P2", ManufacturerPartNo = "P2", FlagIdSeed = "2", ImageKey = Guid.NewGuid(),
                    Price = new ProductPrice {
                        Value = 100.00M, Catalog = 100.00M, VatRate = 1.25M, PriceListId = 1, IsBuyable = true, RecommendedQuantity = 1, IsRecommendedQuantityFixed = true
                    },
                    OnHand = new OnHand {
                        Value = 7, IsActive = true
                    },
                    Parametrics = new ParametricsSeed {
                        ListSeed = "200:21,300:31", MultipleSeed = "117:18", ValueSeed = ""
                    },
                    AdditionalImageKeySeed = "58:" + Guid.NewGuid(),
                },
            };


            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            stormContext.Stub(x => x.CultureCode).Return("sv");
            StormContext.SetInstance(stormContext);

            var dictionary = MockRepository.GenerateMock <IApplicationDictionary>();

            dictionary.Stub(x => x.ParametricInfo(111, "sv")).Return(new ParametricInfo {
                Id = 111, Type = ParametricType.ListValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 11, "sv")).Return(new ParametricValue {
                Id = 11, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.ListValue.ToString()
            });

            dictionary.Stub(x => x.ParametricInfo(112, "sv")).Return(new ParametricInfo {
                Id = 112, Type = ParametricType.ListValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 12, "sv")).Return(new ParametricValue {
                Id = 12, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.ListValue.ToString()
            });

            dictionary.Stub(x => x.ParametricInfo(113, "sv")).Return(new ParametricInfo {
                Id = 113, Type = ParametricType.MultiValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.MultiValue, 13, "sv")).Return(new ParametricValue {
                Id = 13, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.MultiValue, 14, "sv")).Return(new ParametricValue {
                Id = 14, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });

            dictionary.Stub(x => x.ParametricInfo(115, "sv")).Return(new ParametricInfo {
                Id = 115, Type = ParametricType.ListValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 15, "sv")).Return(new ParametricValue {
                Id = 15, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.ListValue.ToString()
            });

            dictionary.Stub(x => x.ParametricInfo(116, "sv")).Return(new ParametricInfo {
                Id = 116, Type = ParametricType.ListValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 16, "sv")).Return(new ParametricValue {
                Id = 16, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.ListValue.ToString()
            });

            dictionary.Stub(x => x.ParametricInfo(200, "sv")).Return(new ParametricInfo {
                Id = 200, Type = ParametricType.ListValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 20, "sv")).Return(new ParametricValue {
                Id = 20, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 21, "sv")).Return(new ParametricValue {
                Id = 21, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });

            dictionary.Stub(x => x.ParametricInfo(300, "sv")).Return(new ParametricInfo {
                Id = 300, Type = ParametricType.ListValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 30, "sv")).Return(new ParametricValue {
                Id = 30, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.ListValue, 31, "sv")).Return(new ParametricValue {
                Id = 31, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });

            dictionary.Stub(x => x.ParametricInfo(117, "sv")).Return(new ParametricInfo {
                Id = 117, Type = ParametricType.MultiValue, ValueType = ParametricValueType.Integer
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.MultiValue, 17, "sv")).Return(new ParametricValue {
                Id = 17, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });
            dictionary.Stub(x => x.ParametricValue(ParametricType.MultiValue, 18, "sv")).Return(new ParametricValue {
                Id = 18, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.MultiValue.ToString()
            });

            // Act
            var productBuilder = new ProductListBuilder(dictionary, rules);
            var result         = productBuilder.BuildProductList(productList, variantList);

            // Assert
            Assert.AreNotEqual(null, result);
            Assert.AreEqual(1, result.ItemCount);
            Assert.AreEqual(1, result.Items.Count);

            var product = result.Items[0];

            Assert.AreEqual("Manufacturer", product.Manufacturer.Name);
            Assert.AreEqual(2, product.Files.Count, "Files");
            Assert.AreEqual("Handske", product.Files[0].AltText);
            Assert.AreEqual(0, product.Flags.Count);
            Assert.AreEqual(5, product.Parametrics.Count, "Parametrics");

            Assert.AreEqual(2, product.Variants.Count, "Parametrics");
            var variant1 = product.Variants[0];

            Assert.AreEqual(1, variant1.Parametrics.Count, "Parametrics");
            Assert.AreEqual(2, variant1.VariantParametrics.Count, "VariantParametrics");
            Assert.AreEqual(1, variant1.Flags.Count);
            Assert.AreEqual(2, variant1.Files.Count);
        }