Skip to content

Commit ef16659

Browse files
authored
Merge pull request #152 from contentstack/enhc/DX-4423
Enhc/dx-4423- Add AssetFields() for CDA asset_fields[] — v2.26.0
2 parents 4ddec58 + ac2a06d commit ef16659

16 files changed

Lines changed: 931 additions & 8 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
### Version: 2.26.0
2+
#### Date: Feb-10-2026
3+
4+
##### Feat:
5+
- CDA / DAM 2.0 – AssetFields support
6+
- Added `AssetFields(params string[] fields)` to request specific asset-related metadata via the CDA `asset_fields[]` query parameter
7+
- Implemented on: Entry (single entry fetch), Query (entries find), Asset (single asset fetch), AssetLibrary (assets find)
8+
- Valid parameters: `user_defined_fields`, `embedded_metadata`, `ai_generated_metadata`, `visual_markups`
9+
- Method is chainable; when called with no arguments, the query parameter is not set
10+
111
### Version: 2.25.2
212
#### Date: Nov-13-2025
313

Contentstack.Core.Tests/AssetTest.cs

Lines changed: 183 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using Xunit;
33
using Contentstack.Core.Models;
44
using System.Threading.Tasks;
@@ -951,5 +951,187 @@ public void Where_WithSpecialCharacters_ShouldHandleCorrectly_Test()
951951
Assert.NotNull(result);
952952
Assert.IsType<AssetLibrary>(result);
953953
}
954+
955+
[Fact]
956+
public async Task AssetFields_SingleAsset_RequestSucceeds()
957+
{
958+
string uid = await FetchAssetUID();
959+
Asset asset = client.Asset(uid);
960+
961+
asset.AssetFields("user_defined_fields", "embedded_metadata", "ai_generated_metadata", "visual_markups");
962+
Asset result = await asset.Fetch();
963+
964+
if (result == null)
965+
Assert.Fail("Asset.Fetch with AssetFields did not return a result.");
966+
Assert.NotNull(result.Uid);
967+
Assert.NotEmpty(result.FileName);
968+
}
969+
970+
[Fact]
971+
public async Task AssetFields_AssetLibrary_RequestSucceeds()
972+
{
973+
AssetLibrary assetLibrary = client.AssetLibrary();
974+
assetLibrary.AssetFields("user_defined_fields", "ai_generated_metadata");
975+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
976+
977+
if (assets == null)
978+
Assert.Fail("AssetLibrary.FetchAll with AssetFields did not return a result.");
979+
Assert.NotNull(assets.Items);
980+
}
981+
982+
[Fact]
983+
public async Task AssetFields_ChainedWithIncludeMetadata_RequestSucceeds()
984+
{
985+
string uid = await FetchAssetUID();
986+
Asset result = await client.Asset(uid)
987+
.AssetFields("user_defined_fields")
988+
.IncludeMetadata()
989+
.Fetch();
990+
991+
if (result == null)
992+
Assert.Fail("Asset.Fetch with AssetFields and IncludeMetadata did not return a result.");
993+
Assert.NotNull(result.Uid);
994+
Assert.NotEmpty(result.FileName);
995+
}
996+
997+
[Fact]
998+
public async Task AssetFields_AssetLibrary_ChainedWithIncludeMetadata_RequestSucceeds()
999+
{
1000+
ContentstackCollection<Asset> assets = await client.AssetLibrary()
1001+
.AssetFields("user_defined_fields")
1002+
.IncludeMetadata()
1003+
.FetchAll();
1004+
1005+
if (assets == null)
1006+
Assert.Fail("AssetLibrary.FetchAll with AssetFields and IncludeMetadata did not return a result.");
1007+
Assert.NotNull(assets.Items);
1008+
}
1009+
1010+
[Fact]
1011+
public async Task AssetFields_SingleField_RequestSucceeds()
1012+
{
1013+
string uid = await FetchAssetUID();
1014+
Asset asset = client.Asset(uid);
1015+
asset.AssetFields("user_defined_fields");
1016+
Asset result = await asset.Fetch();
1017+
1018+
if (result == null)
1019+
Assert.Fail("Asset.Fetch with AssetFields single field did not return a result.");
1020+
Assert.NotNull(result.Uid);
1021+
Assert.NotEmpty(result.FileName);
1022+
}
1023+
1024+
[Fact]
1025+
public async Task AssetFields_WithMultipleFields_RequestSucceeds()
1026+
{
1027+
string uid = await FetchAssetUID();
1028+
Asset asset = client.Asset(uid);
1029+
asset.AssetFields("user_defined_fields", "embedded_metadata", "visual_markups");
1030+
Asset result = await asset.Fetch();
1031+
1032+
if (result == null)
1033+
Assert.Fail("Asset.Fetch with AssetFields multiple fields did not return a result.");
1034+
Assert.NotNull(result.Uid);
1035+
Assert.NotEmpty(result.FileName);
1036+
}
1037+
1038+
[Fact]
1039+
public async Task AssetFields_AssetLibrary_SingleField_RequestSucceeds()
1040+
{
1041+
AssetLibrary assetLibrary = client.AssetLibrary();
1042+
assetLibrary.AssetFields("user_defined_fields");
1043+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
1044+
1045+
if (assets == null)
1046+
Assert.Fail("AssetLibrary.FetchAll with AssetFields single field did not return a result.");
1047+
Assert.NotNull(assets.Items);
1048+
}
1049+
1050+
[Fact]
1051+
public async Task AssetFields_AssetLibrary_WithMultipleFields_RequestSucceeds()
1052+
{
1053+
AssetLibrary assetLibrary = client.AssetLibrary();
1054+
assetLibrary.AssetFields("user_defined_fields", "embedded_metadata", "ai_generated_metadata", "visual_markups");
1055+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
1056+
1057+
if (assets == null)
1058+
Assert.Fail("AssetLibrary.FetchAll with AssetFields multiple fields did not return a result.");
1059+
Assert.NotNull(assets.Items);
1060+
}
1061+
1062+
[Fact]
1063+
public async Task AssetFields_WithNoArguments_RequestSucceeds()
1064+
{
1065+
string uid = await FetchAssetUID();
1066+
Asset asset = client.Asset(uid);
1067+
asset.AssetFields();
1068+
Asset result = await asset.Fetch();
1069+
1070+
if (result == null)
1071+
Assert.Fail("Asset.Fetch with AssetFields() no arguments did not return a result.");
1072+
Assert.NotNull(result.Uid);
1073+
}
1074+
1075+
[Fact]
1076+
public async Task AssetFields_AssetLibrary_WithNoArguments_RequestSucceeds()
1077+
{
1078+
AssetLibrary assetLibrary = client.AssetLibrary();
1079+
assetLibrary.AssetFields();
1080+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
1081+
1082+
if (assets == null)
1083+
Assert.Fail("AssetLibrary.FetchAll with AssetFields() no arguments did not return a result.");
1084+
Assert.NotNull(assets.Items);
1085+
}
1086+
1087+
[Fact]
1088+
public async Task AssetFields_WithNull_RequestSucceeds()
1089+
{
1090+
string uid = await FetchAssetUID();
1091+
Asset asset = client.Asset(uid);
1092+
asset.AssetFields(null);
1093+
Asset result = await asset.Fetch();
1094+
1095+
if (result == null)
1096+
Assert.Fail("Asset.Fetch with AssetFields(null) did not return a result.");
1097+
Assert.NotNull(result.Uid);
1098+
}
1099+
1100+
[Fact]
1101+
public async Task AssetFields_WithEmptyArray_RequestSucceeds()
1102+
{
1103+
string uid = await FetchAssetUID();
1104+
Asset asset = client.Asset(uid);
1105+
asset.AssetFields(new string[0]);
1106+
Asset result = await asset.Fetch();
1107+
1108+
if (result == null)
1109+
Assert.Fail("Asset.Fetch with AssetFields(empty array) did not return a result.");
1110+
Assert.NotNull(result.Uid);
1111+
}
1112+
1113+
[Fact]
1114+
public async Task AssetFields_AssetLibrary_WithNull_RequestSucceeds()
1115+
{
1116+
AssetLibrary assetLibrary = client.AssetLibrary();
1117+
assetLibrary.AssetFields(null);
1118+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
1119+
1120+
if (assets == null)
1121+
Assert.Fail("AssetLibrary.FetchAll with AssetFields(null) did not return a result.");
1122+
Assert.NotNull(assets.Items);
1123+
}
1124+
1125+
[Fact]
1126+
public async Task AssetFields_AssetLibrary_WithEmptyArray_RequestSucceeds()
1127+
{
1128+
AssetLibrary assetLibrary = client.AssetLibrary();
1129+
assetLibrary.AssetFields(new string[0]);
1130+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
1131+
1132+
if (assets == null)
1133+
Assert.Fail("AssetLibrary.FetchAll with AssetFields(empty array) did not return a result.");
1134+
Assert.NotNull(assets.Items);
1135+
}
9541136
}
9551137
}

Contentstack.Core.Tests/Contentstack.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<PackageReference Include="AutoFixture" Version="4.18.1" />
2929
<PackageReference Include="AutoFixture.AutoMoq" Version="4.18.1" />
3030
<PackageReference Include="Moq" Version="4.20.72" />
31+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
3132
</ItemGroup>
3233

3334
<ItemGroup>

Contentstack.Core.Tests/EntryTest.cs

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using Xunit;
33
using Contentstack.Core.Models;
44
using System.Threading.Tasks;
@@ -457,5 +457,112 @@ public async Task GetMetadata()
457457
Assert.True(true, "GetMetadata() returns a valid dictionary (may be empty)");
458458
}
459459
}
460+
461+
[Fact]
462+
public async Task AssetFields_SingleEntry_RequestSucceeds()
463+
{
464+
ContentType contenttype = client.ContentType(source);
465+
string uid = await GetUID("source1");
466+
Entry sourceEntry = contenttype.Entry(uid);
467+
468+
sourceEntry.AssetFields("user_defined_fields", "embedded_metadata", "ai_generated_metadata", "visual_markups");
469+
var result = await sourceEntry.Fetch<Entry>();
470+
471+
if (result == null)
472+
Assert.Fail("Entry.Fetch with AssetFields did not return a result.");
473+
Assert.NotNull(result.Uid);
474+
}
475+
476+
[Fact]
477+
public async Task AssetFields_ChainedWithIncludeMetadata_RequestSucceeds()
478+
{
479+
ContentType contenttype = client.ContentType(source);
480+
string uid = await GetUID("source1");
481+
Entry sourceEntry = contenttype.Entry(uid);
482+
483+
var result = await sourceEntry
484+
.AssetFields("user_defined_fields")
485+
.IncludeMetadata()
486+
.Fetch<Entry>();
487+
488+
if (result == null)
489+
Assert.Fail("Entry.Fetch with AssetFields and IncludeMetadata did not return a result.");
490+
Assert.NotNull(result.Uid);
491+
}
492+
493+
[Fact]
494+
public async Task AssetFields_SingleField_RequestSucceeds()
495+
{
496+
ContentType contenttype = client.ContentType(source);
497+
string uid = await GetUID("source1");
498+
Entry sourceEntry = contenttype.Entry(uid);
499+
500+
sourceEntry.AssetFields("user_defined_fields");
501+
var result = await sourceEntry.Fetch<Entry>();
502+
503+
if (result == null)
504+
Assert.Fail("Entry.Fetch with AssetFields single field did not return a result.");
505+
Assert.NotNull(result.Uid);
506+
}
507+
508+
[Fact]
509+
public async Task AssetFields_WithMultipleFields_RequestSucceeds()
510+
{
511+
ContentType contenttype = client.ContentType(source);
512+
string uid = await GetUID("source1");
513+
Entry sourceEntry = contenttype.Entry(uid);
514+
515+
sourceEntry.AssetFields("user_defined_fields", "embedded_metadata", "visual_markups");
516+
var result = await sourceEntry.Fetch<Entry>();
517+
518+
if (result == null)
519+
Assert.Fail("Entry.Fetch with AssetFields multiple fields did not return a result.");
520+
Assert.NotNull(result.Uid);
521+
}
522+
523+
[Fact]
524+
public async Task AssetFields_WithNoArguments_RequestSucceeds()
525+
{
526+
ContentType contenttype = client.ContentType(source);
527+
string uid = await GetUID("source1");
528+
Entry sourceEntry = contenttype.Entry(uid);
529+
530+
sourceEntry.AssetFields();
531+
var result = await sourceEntry.Fetch<Entry>();
532+
533+
if (result == null)
534+
Assert.Fail("Entry.Fetch with AssetFields() no arguments did not return a result.");
535+
Assert.NotNull(result.Uid);
536+
}
537+
538+
[Fact]
539+
public async Task AssetFields_WithNull_RequestSucceeds()
540+
{
541+
ContentType contenttype = client.ContentType(source);
542+
string uid = await GetUID("source1");
543+
Entry sourceEntry = contenttype.Entry(uid);
544+
545+
sourceEntry.AssetFields(null);
546+
var result = await sourceEntry.Fetch<Entry>();
547+
548+
if (result == null)
549+
Assert.Fail("Entry.Fetch with AssetFields(null) did not return a result.");
550+
Assert.NotNull(result.Uid);
551+
}
552+
553+
[Fact]
554+
public async Task AssetFields_WithEmptyArray_RequestSucceeds()
555+
{
556+
ContentType contenttype = client.ContentType(source);
557+
string uid = await GetUID("source1");
558+
Entry sourceEntry = contenttype.Entry(uid);
559+
560+
sourceEntry.AssetFields(new string[0]);
561+
var result = await sourceEntry.Fetch<Entry>();
562+
563+
if (result == null)
564+
Assert.Fail("Entry.Fetch with AssetFields(empty array) did not return a result.");
565+
Assert.NotNull(result.Uid);
566+
}
460567
}
461568
}

0 commit comments

Comments
 (0)