|
| 1 | +using System; |
| 2 | +using Xunit; |
| 3 | +using Contentstack.Core.Models; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Contentstack.Core.Configuration; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Linq; |
| 8 | +using System.Text.RegularExpressions; |
| 9 | +using System.Collections; |
| 10 | + |
| 11 | +namespace Contentstack.Core.Tests |
| 12 | +{ |
| 13 | + public class AssetTest |
| 14 | + { |
| 15 | + ContentstackClient client = StackConfig.GetStack(); |
| 16 | + |
| 17 | + [Fact] |
| 18 | + public async Task FetchAssetByUid() |
| 19 | + { |
| 20 | + Asset asset = client.Asset("blt649cfadb08b577db"); |
| 21 | + await asset.Fetch().ContinueWith((t) => |
| 22 | + { |
| 23 | + Asset result = t.Result; |
| 24 | + if (result == null) |
| 25 | + { |
| 26 | + Assert.False(true, "Entry.Fetch is not match with expected result."); |
| 27 | + } |
| 28 | + else |
| 29 | + { |
| 30 | + Assert.True(result.FileName.Length > 0); |
| 31 | + } |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public async Task FetchAssets() |
| 37 | + { |
| 38 | + AssetLibrary assetLibrary = client.AssetLibrary(); |
| 39 | + ContentstackCollection<Asset> assets = await assetLibrary.FetchAll(); |
| 40 | + Assert.True(assets.Count() > 0); |
| 41 | + foreach (Asset asset in assets) |
| 42 | + { |
| 43 | + Assert.True(asset.FileName.Length > 0); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public async Task FetchAssetsOrderByAscending() |
| 49 | + { |
| 50 | + AssetLibrary assetLibrary = client.AssetLibrary(); |
| 51 | + assetLibrary.SortWithKeyAndOrderBy("created_at", Internals.OrderBy.OrderByAscending); |
| 52 | + ContentstackCollection<Asset> assets = await assetLibrary.FetchAll(); |
| 53 | + Assert.True(assets.Count() > 0); |
| 54 | + DateTime dateTime = new DateTime(); |
| 55 | + foreach (Asset asset in assets) |
| 56 | + { |
| 57 | + if (dateTime != null) |
| 58 | + { |
| 59 | + if (dateTime.CompareTo(asset.GetCreateAt()) != -1) |
| 60 | + { |
| 61 | + Assert.False(true); |
| 62 | + } |
| 63 | + } |
| 64 | + dateTime = asset.GetCreateAt(); |
| 65 | + Assert.True(asset.FileName.Length > 0); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + [Fact] |
| 70 | + public async Task FetchAssetsIncludeRelativeURL() |
| 71 | + { |
| 72 | + AssetLibrary assetLibrary = client.AssetLibrary(); |
| 73 | + assetLibrary.IncludeRelativeUrls(); |
| 74 | + ContentstackCollection<Asset> assets = await assetLibrary.FetchAll(); |
| 75 | + Assert.True(assets.Count() > 0); |
| 76 | + foreach (Asset asset in assets) |
| 77 | + { |
| 78 | + Assert.DoesNotContain(asset.Url, "http"); |
| 79 | + Assert.True(asset.FileName.Length > 0); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments