Beispiel #1
0
                public void SellableItemCompare_ByImportData_Images_05_SameCount_EachListWithDifferentDuplicates(
                    SellableItem ItemA,
                    ImagesComponent ImagesComponentA)
                {
                    /**********************************************
                    * Arrange
                    **********************************************/
                    var comparer = new ImportSellableItemComparer(SellableItemComparerConfiguration.ByImportData);

                    ItemA.Components.Add(ImagesComponentA);
                    var ItemB = ItemA.Clone();

                    ItemA.GetComponent <ImagesComponent>().Images.Add(ItemA.GetComponent <ImagesComponent>().Images[0].Clone().ToString());
                    ItemB.GetComponent <ImagesComponent>().Images.Add(ItemB.GetComponent <ImagesComponent>().Images[2].Clone().ToString());

                    /**********************************************
                    * Act
                    **********************************************/
                    bool   result        = false;
                    Action executeAction = () => result = comparer.Equals(ItemA, ItemB);

                    /**********************************************
                    * Assert
                    **********************************************/
                    executeAction.Should().NotThrow <Exception>();
                    ItemA.GetComponent <ImagesComponent>().Images.Count().Should().Be(ItemB.GetComponent <ImagesComponent>().Images.Count());
                    result.Should().BeFalse();
                }
Beispiel #2
0
                public void SellableItemCompare_ByImportData_Images_02_ImagesB_IsNull(
                    SellableItem ItemA,
                    ImagesComponent ImagesComponentA)
                {
                    /**********************************************
                    * Arrange
                    **********************************************/
                    var comparer = new ImportSellableItemComparer(SellableItemComparerConfiguration.ByImportData);

                    ItemA.Components.Add(ImagesComponentA);
                    var ItemB = ItemA.Clone();

                    ItemB.GetComponent <ImagesComponent>().Images = null;

                    /**********************************************
                    * Act
                    **********************************************/
                    bool   result        = false;
                    Action executeAction = () => result = comparer.Equals(ItemA, ItemB);

                    /**********************************************
                    * Assert
                    **********************************************/
                    executeAction.Should().NotThrow <Exception>();
                    ItemA.GetComponent <ImagesComponent>().Images.Count().Should().BeGreaterThan(0);
                    result.Should().BeFalse();
                }
Beispiel #3
0
        private async Task TransformImages(CommerceContext commerceContext, List <TransientImportSellableItemDataPolicy> transientDataList, List <SellableItem> importItems)
        {
            var listOfImageNames = transientDataList.SelectMany(d => d.ImageNameList).Distinct().ToList();

            listOfImageNames = listOfImageNames.Select(imageName => System.IO.Path.GetFileNameWithoutExtension(imageName)).ToList();
            var imageNameDictionary = await Command <GetMediaItemsCommand>().Process(commerceContext, listOfImageNames);

            if (imageNameDictionary.Count().Equals(0))
            {
                commerceContext.Logger.LogWarning($"{nameof(TransformImportToSellableItemsCommand)}-Warning no media found in Sitecore.");
                return;
            }

            foreach (var item in importItems)
            {
                var transientData = item.GetPolicy <TransientImportSellableItemDataPolicy>();

                if (transientData.ImageNameList == null || transientData.ImageNameList.Count().Equals(0))
                {
                    continue;
                }

                var imageComponent = new ImagesComponent();
                foreach (var imageName in transientData.ImageNameList)
                {
                    imageNameDictionary.TryGetValue(System.IO.Path.GetFileNameWithoutExtension(imageName), out string imageId);
                    if (!string.IsNullOrEmpty(imageId))
                    {
                        imageComponent.Images.Add(imageId);
                    }
                }

                item.Components.Add(imageComponent);
            }
        }
Beispiel #4
0
 private bool ImagesEquality(ImagesComponent x, ImagesComponent y)
 {
     if (x == null && y == null)
     {
         return(true);
     }
     if (x == null || y == null)
     {
         return(false);
     }
     if (x.Images == null && y.Images == null)
     {
         return(true);
     }
     if (x.Images == null || y.Images == null)
     {
         return(false);
     }
     return(x.Images.OrderBy(i => i, StringComparer.OrdinalIgnoreCase).SequenceEqual(y.Images.OrderBy(i => i, StringComparer.OrdinalIgnoreCase)));
 }