public List <CollectibleItem> ConvertAssetsToCollectibleItems(CollectionPointAssets assets) { var output = new List <CollectibleItem>(); if (assets != null) { foreach (var asset in assets.ImageAssets) { var image = new CollectibleItem(); image.Id = asset.Id == Guid.Empty ? null : asset.Id.ToString(); image.ImageUrl = GenerateImageUrl(asset.Data.ImageAsset?.Iv.FirstOrDefault()); image.ValuePairs = Mapper.Map <Dictionary <string, int> >(asset.Data.Values?.Iv); image.Caption = asset.Data.Caption?.Iv; image.Credit = asset.Data.Credit?.Iv; if (asset.Data?.ShopifyIcon != null) { image.IconUrl = GenerateImageUrl(asset.Data.ShopifyIcon?.Iv.FirstOrDefault()); } output.Add(image); } foreach (var asset in assets.QuoteAssets) { var quote = new CollectibleItem(); quote.Id = asset.Id == Guid.Empty ? null : asset.Id.ToString(); quote.ValuePairs = Mapper.Map <Dictionary <string, int> >(asset.Data.Values?.Iv); if (asset.Data?.ShopifyIcon != null) { quote.IconUrl = GenerateImageUrl(asset.Data.ShopifyIcon?.Iv.FirstOrDefault()); } output.Add(quote); } } return(output); }
public List <CollectibleItemReference> ConvertAssetsToIdList(CollectionPointAssets cpAssets) { var output = new List <CollectibleItemReference>(); if (cpAssets != null) { foreach (var asset in cpAssets.ImageAssets) { var image = new CollectibleItemReference(); image.CollectabileId = asset.Id == Guid.Empty ? null : asset.Id.ToString(); image.CollectabileType = "Image"; image.AssetId = asset.Data.ImageAsset?.Iv.FirstOrDefault(); output.Add(image); } foreach (var asset in cpAssets.QuoteAssets) { var quote = new CollectibleItemReference(); quote.CollectabileId = asset.Id == Guid.Empty ? null : asset.Id.ToString(); quote.CollectabileType = "Quote"; //quote.AssetId = asset.ImageAsset.Iv.FirstOrDefault(); output.Add(quote); } } return(output); }
public async Task <CollectionPointAssets> GetCollectionAssets(List <string> iv)//, CollectionPoint cpData) { var dynamicClient = clientManager.CreateContentsClient <DynamicContentDetails, DynamicContentData>("collection-points"); var referenceData = await dynamicClient.GetAsync(new HashSet <Guid>(iv.Select(x => Guid.Parse(x)))); var assets = new CollectionPointAssets(); string jsonData; foreach (var content in referenceData.Items) { switch (content.SchemaName) { case "cp-image-asset": jsonData = JsonConvert.SerializeObject(content.Data, Formatting.None); var insertedImage = JsonConvert.DeserializeObject <ImageAsset>(jsonData); insertedImage.Id = content.Id; assets.ImageAssets.Add(insertedImage); break; case "cp-qoute-asset": jsonData = JsonConvert.SerializeObject(content.Data, Formatting.None); var insertedQuote = JsonConvert.DeserializeObject <QuoteAsset>(jsonData); insertedQuote.Id = content.Id; assets.QuoteAssets.Add(insertedQuote); break; } } return(assets); }
public async Task <CollectionPointAssets> GetAllCollectibleAssets(bool shopify, DateTime?dateLastTaken, string iv = null) { ContentQuery query = null; var collectabileAssets = new CollectionPointAssets(); if (!string.IsNullOrEmpty(iv) || dateLastTaken != null || shopify) { var queryDictionary = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(iv)) { CreateFieldDictonary("id", iv, queryDictionary); } if (dateLastTaken != null) { CreateFieldDictonary("lastModified", dateLastTaken.ToString(), queryDictionary); } if (shopify) { CreateFieldDictonary("data/ShowInShopify/iv", true, queryDictionary); } query = GetQuery(queryDictionary); } collectabileAssets.ImageAssets = await GetImageAssets(query); collectabileAssets.QuoteAssets = await GetQuoteAssets(query); return(collectabileAssets); }
public void ConvertAssetsToIdList_CPAssetsListShouldReturnListOfIds(CollectionPointAssets value, List <CollectibleItemReference> expected) { /* var value = GetCPAssets(); * var expected = GetExpectedAssetIdList();*/ var result = bl.ConvertAssetsToIdList(value); Assert.True(result.Count == expected.Count); Assert.Equal(expected.FirstOrDefault()?.AssetId, result.FirstOrDefault()?.AssetId); Assert.Equal(expected.FirstOrDefault()?.CollectabileId, result.FirstOrDefault()?.CollectabileId); Assert.Equal(expected.FirstOrDefault()?.CollectabileType, result.FirstOrDefault()?.CollectabileType); }
private static CollectionPointAssets GetCPAssets() { CollectionPointAssets value = new CollectionPointAssets(); value.ImageAssets = new List <ImageAsset>(); value.QuoteAssets = new List <QuoteAsset>(); value.ImageAssets.Add(new ImageAsset() { Id = new System.Guid("c8ad4314-fd8b-4200-994c-366bfd87ae12"), Data = { Caption = new Caption() { Iv = "Tamar test" }, Credit = new Caption() { Iv = "Thank you tamar" }, ImageAsset = new ImageAssetClass() { Iv = new List <string>() { "c8ad4314-fd8b-4200-994c-366bfd87ae13" } }, Values = new Values() { Iv = new List <Iv>() { new Iv() { StringValue = "hope", ValueNumber = "1" }, new Iv() { StringValue = "Fait", ValueNumber = "2" }, new Iv() { StringValue = "Unity", ValueNumber = "3" } } } } }); return(value); }
public void ConvertAssetsToCollectibleItems_CPAssetsListShouldReturnListOfCollectibleItems(CollectionPointAssets value, List <CollectibleItem> expected) { /* var value = GetCPAssets(); * List<CollectibleItem> expected = new List<CollectibleItem>(); * GetExpectedCollectabileItems(expected);*/ var result = bl.ConvertAssetsToCollectibleItems(value); Assert.True(result.Count == expected.Count); Assert.Equal(expected.FirstOrDefault()?.Id, result.FirstOrDefault()?.Id); Assert.Equal(expected.FirstOrDefault()?.Caption, result.FirstOrDefault()?.Caption); Assert.Equal(expected.FirstOrDefault()?.Credit, result.FirstOrDefault()?.Credit); Assert.Equal(expected.FirstOrDefault()?.IconUrl, result.FirstOrDefault()?.IconUrl); Assert.Equal(expected.FirstOrDefault()?.ImageUrl, result.FirstOrDefault()?.ImageUrl); if (result.Count > 0) { foreach (var item in result.Select((x, i) => new { Value = x, Index = i })) { if (item.Value?.ValuePairs != null) { foreach (var pair in item.Value?.ValuePairs) { Assert.Equal(expected[item.Index]?.ValuePairs[pair.Key], pair.Value); } } } } }