77using System . Linq ;
88using System . Text . RegularExpressions ;
99using System . Collections ;
10+ using Newtonsoft . Json . Linq ;
1011
1112namespace Contentstack . Core . Tests
1213{
@@ -40,7 +41,7 @@ await asset.Fetch().ContinueWith((t) =>
4041 Assert . True ( result . FileName . Length > 0 ) ;
4142 }
4243 } ) ;
43- }
44+ }
4445
4546 [ Fact ]
4647 public async Task FetchAssets ( )
@@ -89,5 +90,93 @@ public async Task FetchAssetsIncludeRelativeURL()
8990 Assert . True ( asset . FileName . Length > 0 ) ;
9091 }
9192 }
93+
94+ [ Fact ]
95+ public async Task FetchAssetCountAsync ( )
96+ {
97+ AssetLibrary assetLibrary = client . AssetLibrary ( ) ;
98+ JObject jObject = await assetLibrary . Count ( ) ;
99+ if ( jObject == null )
100+ {
101+ Assert . False ( true , "Query.Exec is not match with expected result." ) ;
102+ }
103+ else if ( jObject != null )
104+ {
105+ Assert . Equal ( 5 , jObject . GetValue ( "assets" ) ) ;
106+ //Assert.True(true, "BuiltObject.Fetch is pass successfully.");
107+ }
108+ else
109+ {
110+ Assert . False ( true , "Result doesn't mathced the count." ) ;
111+ }
112+ }
113+
114+ [ Fact ]
115+ public async Task FetchAssetSkipLimit ( )
116+ {
117+ AssetLibrary assetLibrary = client . AssetLibrary ( ) . Skip ( 2 ) . Limit ( 5 ) ;
118+ ContentstackCollection < Asset > assets = await assetLibrary . FetchAll ( ) ;
119+ if ( assets == null )
120+ {
121+ Assert . False ( true , "Query.Exec is not match with expected result." ) ;
122+ }
123+ else if ( assets != null )
124+ {
125+ Assert . Equal ( 3 , assets . Items . Count ( ) ) ;
126+ }
127+ else
128+ {
129+ Assert . False ( true , "Result doesn't mathced the count." ) ;
130+ }
131+ }
132+
133+ [ Fact ]
134+ public async Task FetchAssetOnly ( )
135+ {
136+ AssetLibrary assetLibrary = client . AssetLibrary ( ) . Only ( new string [ ] { "url" } ) ;
137+ ContentstackCollection < Asset > assets = await assetLibrary . FetchAll ( ) ;
138+ if ( assets == null )
139+ {
140+ Assert . False ( true , "Query.Exec is not match with expected result." ) ;
141+ }
142+ else if ( assets != null )
143+ {
144+ foreach ( Asset asset in assets )
145+ {
146+ Assert . DoesNotContain ( asset . Url , "http" ) ;
147+ Assert . Null ( asset . Description ) ;
148+ Assert . Null ( asset . FileSize ) ;
149+ Assert . Null ( asset . Tags ) ;
150+ Assert . Null ( asset . Description ) ;
151+ }
152+ }
153+ else
154+ {
155+ Assert . False ( true , "Result doesn't mathced the count." ) ;
156+ }
157+ }
158+
159+ [ Fact ]
160+ public async Task FetchAssetExcept ( )
161+ {
162+ AssetLibrary assetLibrary = client . AssetLibrary ( ) . Except ( new string [ ] { "description" } ) ;
163+ ContentstackCollection < Asset > assets = await assetLibrary . FetchAll ( ) ;
164+ if ( assets == null )
165+ {
166+ Assert . False ( true , "Query.Exec is not match with expected result." ) ;
167+ }
168+ else if ( assets != null )
169+ {
170+ foreach ( Asset asset in assets )
171+ {
172+ Assert . DoesNotContain ( asset . Url , "http" ) ;
173+ Assert . Null ( asset . Description ) ;
174+ }
175+ }
176+ else
177+ {
178+ Assert . False ( true , "Result doesn't mathced the count." ) ;
179+ }
180+ }
92181 }
93- }
182+ }
0 commit comments