public void ProductOptionManager_DeleteSpecificationAttribute_ShouldRemoveAllValues()
        {
            var attribute = new ProductSpecificationAttribute { Name = "Test" };
            var option = new ProductSpecificationAttributeOption() { Name = "Test Value" };
            var product = new Product();
            var productSpecificationAttributes =
                Enumerable.Range(1, 10)
                          .Select(
                              i =>
                              new ProductSpecificationValue
                                  {
                                      ProductSpecificationAttributeOption = option,
                                      Product = product
                                  })
                          .ToList();
            option.Values = productSpecificationAttributes;
            Session.Transact(session =>
                                 {
                                     session.Save(product);
                                     session.Save(attribute);
                                     productSpecificationAttributes.ForEach(value => session.Save(value));
                                 });

            _productOptionManager.DeleteSpecificationAttributeOption(option);

            Session.QueryOver<ProductSpecificationValue>().RowCount().Should().Be(0);
        }
        public void ProductSpecificationAttributeOptionController_EditGet_ReturnsThePassedOptionAsViewModel()
        {
            var controller = GetProductSpecificationAttributeOptionController();
            var option = new ProductSpecificationAttributeOption();

            var edit = controller.Edit(option);

            edit.Model.Should().Be(option);
        }
        public void ProductSpecificationAttributeOptionController_DeletePOST_CallsDeleteOption()
        {
            var controller = GetProductSpecificationAttributeOptionController();
            var attribute = new ProductSpecificationAttribute();
            var option = new ProductSpecificationAttributeOption() { ProductSpecificationAttribute = attribute };
            
            var delete = controller.Delete_POST(option);

            A.CallTo(() => _productOptionManager.DeleteSpecificationAttributeOption(option)).MustHaveHappened();
        }
        public void ProductSpecificationAttributeOptionController_Delete_ReturnsOptionAsModel()
        {
            var controller = GetProductSpecificationAttributeOptionController();
            var attribute = new ProductSpecificationAttribute();
            var option = new ProductSpecificationAttributeOption() { ProductSpecificationAttribute = attribute };
            
            var delete = controller.Delete(option);

            delete.Model.Should().Be(option);
        }
        public void ProductSpecificationAttributeOptionController_Delete_ReturnsPartialViewResult()
        {
            var controller = GetProductSpecificationAttributeOptionController();
            var attribute = new ProductSpecificationAttribute();
            var option = new ProductSpecificationAttributeOption() { ProductSpecificationAttribute = attribute };

            var delete = controller.Delete(option);

            delete.Should().BeOfType<PartialViewResult>();
        }
        public void ProductSpecificationAttributeOptionController_Add_NotHappensIfNotValidAttributeIdIsSent()
        {
            var controller = GetProductSpecificationAttributeOptionController();
            var attribute = new ProductSpecificationAttribute();
            var option = new ProductSpecificationAttributeOption() { ProductSpecificationAttribute = attribute };

            var add = controller.Add(attribute.Id);

            A.CallTo(() => _productOptionManager.AddSpecificationAttributeOption(option)).MustNotHaveHappened();
        }
        public string ProcessSpecificationAttributeOptions(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            var optionDatas = dataReader.GetProductSpecificationOptions();

            _session.Transact(session =>
            {
                foreach (ProductSpecificationAttributeOptionData optionData in optionDatas)
                {
                    var option = new ProductSpecificationAttributeOption
                    {
                        Name = optionData.Name,
                        ProductSpecificationAttribute =
                            nopImportContext.FindNew<ProductSpecificationAttribute>(optionData.ProductSpecificationId)
                    };
                    session.Save(option);
                    nopImportContext.AddEntry(optionData.Id, option);
                }
            });
            return string.Format("{0} product specification attribute options processed", optionDatas.Count);

        }
        public void SetSpecificationValue(Product product, ProductSpecificationAttribute productSpecificationAttribute,
            string value)
        {
            ProductSpecificationValue valueAlias = null;
            ProductSpecificationAttributeOption optionAlias = null;
            ProductSpecificationValue specificationValue = _session.QueryOver(() => valueAlias)
                .JoinAlias(
                    () =>
                        valueAlias.ProductSpecificationAttributeOption,
                    () => optionAlias)
                .Where(
                    () => valueAlias.Product == product &&
                          optionAlias.ProductSpecificationAttribute ==
                          productSpecificationAttribute
                ).Cacheable().SingleOrDefault();

            ProductSpecificationAttributeOption option =
                productSpecificationAttribute.Options.FirstOrDefault(
                    attributeOption =>
                        string.Equals(attributeOption.Name, value, StringComparison.InvariantCultureIgnoreCase));
            if (option == null)
            {
                option = new ProductSpecificationAttributeOption
                {
                    ProductSpecificationAttribute = productSpecificationAttribute,
                    Name = value
                };
                _session.Save(option);
            }

            if (specificationValue != null)
            {
                specificationValue.ProductSpecificationAttributeOption = option;
                _session.Transact(session => session.Update(specificationValue));
            }
            else
            {
                var productSpecificationValue = new ProductSpecificationValue
                {
                    Product = product,
                    ProductSpecificationAttributeOption = option
                };
                product.SpecificationValues.Add(productSpecificationValue);
                _session.Transact(session => session.Update(product));
            }
        }
 public void DeleteSpecificationAttributeOption(ProductSpecificationAttributeOption option)
 {
     _session.Transact(session => session.Delete(option));
 }
 public void AddSpecificationAttributeOption(ProductSpecificationAttributeOption option)
 {
     if (option == null || string.IsNullOrWhiteSpace(option.Name))
         return;
     option.ProductSpecificationAttribute.Options.Add(option);
     _session.Transact(session => session.Save(option));
 }
 private static void SetValue(Product product, ProductSpecificationAttribute attribute, string value)
 {
     ProductSpecificationAttributeOption option = attribute.Options.FirstOrDefault(o => o.Name == value);
     if (option == null)
     {
         option = new ProductSpecificationAttributeOption
         {
             Name = value,
             ProductSpecificationAttribute = attribute
         };
         attribute.Options.Add(option);
     }
     product.SpecificationValues.Add(new ProductSpecificationValue
     {
         ProductSpecificationAttributeOption = option,
         Product = product
     });
 }
        public void ProductSpecificationAttributeOptionController_DeletePOST_ReturnsRedirectToRouteResult()
        {
            var controller = GetProductSpecificationAttributeOptionController();
            var attribute = new ProductSpecificationAttribute();
            var option = new ProductSpecificationAttributeOption() { ProductSpecificationAttribute = attribute };
            
            var delete = controller.Delete_POST(option);

            delete.Should().BeOfType<RedirectToRouteResult>();
        }
        public void ProductSpecificationAttributeOptionController_DeletePOST_RedirectsToIndex()
        {
            var controller = GetProductSpecificationAttributeOptionController();
            var attribute = new ProductSpecificationAttribute();
            var option = new ProductSpecificationAttributeOption() { ProductSpecificationAttribute = attribute };
            
            var delete = controller.Delete_POST(option);

            delete.RouteValues["action"].Should().Be("Index");
        }