Esempio n. 1
0
        public void AssertCopyProductTaskChainTaskCount()
        {
            //// Arrange
            const int Expected = 6;

            //// Act
            var copyChain = new CopyProductTaskChain(
                MerchelloContext.Current,
                _original,
                "test",
                Guid.NewGuid().ToString());

            //// Assert
            Assert.AreEqual(Expected, copyChain.TaskCount);
        }
Esempio n. 2
0
        public void AssertCopyProductTaskChainTaskCount()
        {
            //// Arrange
            const int Expected = 6;

            //// Act
            var copyChain = new CopyProductTaskChain(
                MerchelloContext.Current,
                _original,
                "test",
                Guid.NewGuid().ToString());

            //// Assert
            Assert.AreEqual(Expected, copyChain.TaskCount);
        }
Esempio n. 3
0
        public void Can_Copy_Product_As_A_Clone_Of_Original()
        {
            //// Arrange
            const string Sku       = "clone";
            const string Name      = "Clone";
            var          copyChain = new CopyProductTaskChain(
                MerchelloContext.Current,
                _original,
                Name,
                Sku);

            //// Act
            var attempt = copyChain.Copy();


            //// Assert
            Assert.IsTrue(attempt.Success);
            var clone = attempt.Result;

            Assert.IsTrue(clone.HasIdentity);
            Assert.AreNotEqual(_original.Key, clone.Key);

            Assert.AreEqual(Name, clone.Name);
            Assert.AreEqual(Sku, clone.Sku);
            Assert.AreEqual(false, clone.Available);

            //// product data
            this.AssertProductBaseData(_original, clone);

            //// product variant data
            foreach (var cloneVariant in clone.ProductVariants.ToArray())
            {
                var originalVariant = this.GetOrignalMatchingVariant(cloneVariant);
                this.AssertProductBaseData(originalVariant, cloneVariant);
            }

            //// collections
            this.AssertCollections(_original, clone);

            Assert.AreEqual(_original.Download, clone.Download);
            Assert.AreEqual(_original.OutOfStockPurchase, clone.OutOfStockPurchase);

            Assert.AreEqual(_original.ProductOptions.Count, clone.ProductOptions.Count);
            Assert.AreEqual(_original.ProductVariants.Count, clone.ProductVariants.Count);

            //// Detached Content
            AssertDetachedContent(_original, clone);
        }
Esempio n. 4
0
        public void Can_Copy_Product_As_A_Clone_Of_Original()
        {
            //// Arrange
            const string Sku = "clone";
            const string Name = "Clone";
            var copyChain = new CopyProductTaskChain(
                          MerchelloContext.Current,
                          _original,
                          Name,
                          Sku);

            //// Act
            var attempt = copyChain.Copy();

            //// Assert
            Assert.IsTrue(attempt.Success);
            var clone = attempt.Result;

            Assert.IsTrue(clone.HasIdentity);
            Assert.AreNotEqual(_original.Key, clone.Key);

            Assert.AreEqual(Name, clone.Name);
            Assert.AreEqual(Sku, clone.Sku);
            Assert.AreEqual(false, clone.Available);

            //// product data
            this.AssertProductBaseData(_original, clone);

            //// product variant data
            foreach (var cloneVariant in clone.ProductVariants.ToArray())
            {
                var originalVariant = this.GetOrignalMatchingVariant(cloneVariant);
                this.AssertProductBaseData(originalVariant, cloneVariant);
            }

            //// collections
            this.AssertCollections(_original, clone);

            Assert.AreEqual(_original.Download, clone.Download);
            Assert.AreEqual(_original.OutOfStockPurchase, clone.OutOfStockPurchase);

            Assert.AreEqual(_original.ProductOptions.Count, clone.ProductOptions.Count);
            Assert.AreEqual(_original.ProductVariants.Count, clone.ProductVariants.Count);

            //// Detached Content
            AssertDetachedContent(_original, clone);
        }
Esempio n. 5
0
        public ProductDisplay PostCopyProduct(ProductCopySave productCopySave)
        {
            var original = _productService.GetByKey(productCopySave.Product.Key);

            if (original == null)
            {
                throw new NullReferenceException("Product was not found");
            }

            var taskChain = new CopyProductTaskChain(original, productCopySave.Name, productCopySave.Sku);

            var attempt = taskChain.Copy();

            if (!attempt.Success)
            {
                throw attempt.Exception;
            }

            return(attempt.Result.ToProductDisplay());
        }
        public ProductDisplay PostCopyProduct(ProductCopySave productCopySave)
        {
            var original = _productService.GetByKey(productCopySave.Product.Key);

            if (original == null) throw new NullReferenceException("Product was not found");

            var taskChain = new CopyProductTaskChain(original, productCopySave.Name, productCopySave.Sku);

            var attempt = taskChain.Copy();

            if (!attempt.Success) throw attempt.Exception;

            return attempt.Result.ToProductDisplay();
        }