Skip to content

Commit 827d2ed

Browse files
authored
Merge pull request #191 from contentstack/enhc/DX-8641
Enhc/dx 8641
2 parents c1e3eed + 93aefe5 commit 827d2ed

46 files changed

Lines changed: 383 additions & 523 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
- Migrated `LocaleModel` and `BulkOperationModels` to use `System.Text.Json` attributes
3737
- Added/updated unit and integration test coverage for Locale and Bulk Operations
3838
- Upgraded target framework to .NET 10 and removed all build warnings
39-
- **Note**:
40-
- This is a beta release and APIs/modules may continue evolving during migration stabilization
41-
- Release and Workflow setup within Bulk Operations module are currently commented out and will be uncommented once the Release and Workflow modules are migrated to System.Text.Json
39+
- Remaining modules migrated and re-enabled — `AuditLog`, `Extension`, `Label`, `Role`, `Taxonomy`, `Term`, `Webhook`, `DeliveryToken`, `ManagementToken`, and `CustomExtension` fully re-enabled with STJ attributes; all corresponding `Stack.*()` accessor methods restored
40+
- All `[JsonProperty]` replaced with `[JsonPropertyName]` across all model classes; `[JsonObject(ItemNullValueHandling)]` removed in favour of global `DefaultIgnoreCondition = WhenWritingNull`
41+
- OAuth module enabled — `OAuthHandler`, `OAuthTokenService`, `OAuthAppAuthorizationService`, and `OAuthAppRevocationService` now active; auto token refresh wired into `InvokeAsync` pipeline via `EnsureOAuthTokenIsValidAsync`
42+
- CustomWidgetModel scope serialization migrated from `JsonTextWriter` to `System.Text.Json.JsonSerializer.Serialize()`
43+
- Asset extension upload tests — 3 previously skipped tests (`Test002_Should_Create_Dashboard`, `Test003_Should_Create_Custom_Widget`, `Test004_Should_Create_Custom_field`) now have real implementations
44+
- Unit test coverage expanded — 991 → 1,242 passing tests; 24 previously excluded test files re-enabled covering AuditLog, Extension, Label, Role, Taxonomy, Term, Webhook, DeliveryToken, CustomExtension, and all infrastructure tests (HTTP pipeline, converters, runtime contexts, utilities)
45+
- Integration test coverage expanded — 4 previously excluded integration test files re-enabled: ContentType Expanded (`Contentstack012b`), DeliveryToken (`Contentstack016`), Taxonomy (`Contentstack017`), Role (`Contentstack019`)
4246

4347
## [v0.10.0](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.9.0)
4448
- Feat

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,4 @@
5151
<ProjectReference Include="..\Contentstack.Management.Core\contentstack.management.core.csproj" />
5252
</ItemGroup>
5353

54-
<ItemGroup>
55-
<!-- Exclude out-of-scope integration tests (still use Newtonsoft or depend on excluded SDK types) -->
56-
<!-- Contentstack004_ReleaseTest.cs - RE-ENABLED for Release module STJ migration -->
57-
<!-- Contentstack015_BulkOperationTest.cs - RE-ENABLED (Stack.Release() and Stack.Workflow() now active) -->
58-
<!-- Contentstack020_WorkflowTest.cs - RE-ENABLED for Workflow module STJ migration -->
59-
<Compile Remove="IntegrationTest\Contentstack012b_ContentTypeExpandedIntegrationTest.cs" />
60-
61-
</ItemGroup>
6254
</Project>

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack012b_ContentTypeExpandedIntegrationTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net;
66
using System.Threading.Tasks;
77
using Contentstack.Management.Core.Models;
8+
using Contentstack.Management.Core.Models.CustomExtension;
89
using Contentstack.Management.Core.Models.Fields;
910
using Contentstack.Management.Core.Tests.Helpers;
1011
using Contentstack.Management.Core.Tests.Model;

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using System.Text;
1111
using Contentstack.Management.Core.Models;
12+
using Contentstack.Management.Core.Models.CustomExtension;
1213
using Contentstack.Management.Core.Tests.Helpers;
1314
using Contentstack.Management.Core.Tests.Model;
1415
using Contentstack.Management.Core.Exceptions;
@@ -404,32 +405,92 @@ public async Task Test001_Should_Create_Asset()
404405
}
405406
}
406407

407-
// Tests 002-004 depend on Extension/CustomExtension SDK module (excluded from current scope)
408408
[TestMethod]
409409
[DoNotParallelize]
410-
[Ignore("Requires Extension SDK module (Models/CustomExtension) which is out of current scope")]
411410
public async Task Test002_Should_Create_Dashboard()
412411
{
413-
Assert.Inconclusive("Extension SDK module not available in current scope.");
414-
await System.Threading.Tasks.Task.CompletedTask;
412+
TestOutputLogger.LogContext("TestScenario", "CreateDashboardWidget");
413+
var path = Path.Combine(System.Environment.CurrentDirectory, "../../../Mock/extension.html");
414+
try
415+
{
416+
DashboardWidgetModel dashboard = new DashboardWidgetModel(
417+
path, "text/html", "Integration Test Dashboard",
418+
isEnable: true, defaultWidth: "half", tags: "dashboard,test");
419+
ContentstackResponse response = await _stack.Extension().UploadAsync(dashboard);
420+
TestOutputLogger.LogContext("StackAPIKey", _stack?.APIKey ?? "null");
421+
422+
if (response.IsSuccessStatusCode)
423+
{
424+
AssertLogger.IsNotNull(response.OpenJsonObjectResponse()["extension"], "CreateDashboard_ResponseContainsExtension");
425+
}
426+
else
427+
{
428+
AssertLogger.Fail("Dashboard Widget Creation Failed", response.OpenResponse());
429+
}
430+
}
431+
catch (Exception e)
432+
{
433+
AssertLogger.Fail("Dashboard Widget Creation Failed", e.Message);
434+
}
415435
}
416436

417437
[TestMethod]
418438
[DoNotParallelize]
419-
[Ignore("Requires Extension SDK module (Models/CustomExtension) which is out of current scope")]
420439
public async Task Test003_Should_Create_Custom_Widget()
421440
{
422-
Assert.Inconclusive("Extension SDK module not available in current scope.");
423-
await System.Threading.Tasks.Task.CompletedTask;
441+
TestOutputLogger.LogContext("TestScenario", "CreateCustomWidget");
442+
var path = Path.Combine(System.Environment.CurrentDirectory, "../../../Mock/extension.html");
443+
try
444+
{
445+
var scope = new ExtensionScope { ContentTypes = new List<string> { "$all" } };
446+
CustomWidgetModel widget = new CustomWidgetModel(
447+
path, "text/html", "Integration Test Widget",
448+
tags: "widget,test", scope: scope);
449+
ContentstackResponse response = await _stack.Extension().UploadAsync(widget);
450+
TestOutputLogger.LogContext("StackAPIKey", _stack?.APIKey ?? "null");
451+
452+
if (response.IsSuccessStatusCode)
453+
{
454+
AssertLogger.IsNotNull(response.OpenJsonObjectResponse()["extension"], "CreateCustomWidget_ResponseContainsExtension");
455+
}
456+
else
457+
{
458+
AssertLogger.Fail("Custom Widget Creation Failed", response.OpenResponse());
459+
}
460+
}
461+
catch (Exception e)
462+
{
463+
AssertLogger.Fail("Custom Widget Creation Failed", e.Message);
464+
}
424465
}
425466

426467
[TestMethod]
427468
[DoNotParallelize]
428-
[Ignore("Requires Extension SDK module (Models/CustomExtension) which is out of current scope")]
429469
public async Task Test004_Should_Create_Custom_field()
430470
{
431-
Assert.Inconclusive("Extension SDK module not available in current scope.");
432-
await System.Threading.Tasks.Task.CompletedTask;
471+
TestOutputLogger.LogContext("TestScenario", "CreateCustomField");
472+
var path = Path.Combine(System.Environment.CurrentDirectory, "../../../Mock/extension.html");
473+
try
474+
{
475+
CustomFieldModel field = new CustomFieldModel(
476+
path, "text/html", "Integration Test Field",
477+
dataType: "text", isMultiple: false, tags: "field,test");
478+
ContentstackResponse response = await _stack.Extension().UploadAsync(field);
479+
TestOutputLogger.LogContext("StackAPIKey", _stack?.APIKey ?? "null");
480+
481+
if (response.IsSuccessStatusCode)
482+
{
483+
AssertLogger.IsNotNull(response.OpenJsonObjectResponse()["extension"], "CreateCustomField_ResponseContainsExtension");
484+
}
485+
else
486+
{
487+
AssertLogger.Fail("Custom Field Creation Failed", response.OpenResponse());
488+
}
489+
}
490+
catch (Exception e)
491+
{
492+
AssertLogger.Fail("Custom Field Creation Failed", e.Message);
493+
}
433494
}
434495

435496
private string _testAssetUid;

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack015_BulkOperationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3665,7 +3665,7 @@ private async Task CreateTestRelease()
36653665
if (response.IsSuccessStatusCode && responseJson["release"] != null)
36663666
_testReleaseUid = responseJson["release"]["uid"].ToString();
36673667
}
3668-
catch (Exception e) { }
3668+
catch (Exception) { }
36693669
await Task.CompletedTask;
36703670
}
36713671

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack019_RoleTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static bool RolesArrayContainsUid(JsonArray roles, string uid)
9494
return false;
9595
}
9696

97-
return roles.Any(r => r["uid"]?.ToString() == uid);
97+
return roles.Any(r => r?["uid"]?.ToString() == uid);
9898
}
9999

100100
/// <summary>

Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,8 @@
5454
</ItemGroup>
5555

5656
<ItemGroup>
57-
<!-- Out-of-scope model tests (not in the 12-module migration) -->
58-
<Compile Remove="Models\AuditLogTest.cs" />
59-
<Compile Remove="Models\BaseModelTest.cs" />
60-
<Compile Remove="Models\ExtensionTest.cs" />
61-
<Compile Remove="Models\ExtensionModelTest.cs" />
62-
<Compile Remove="Models\LabelTest.cs" />
63-
<!-- PublishQueueTest.cs - RE-ENABLED for PublishQueue module STJ migration -->
64-
<!-- PublishRuleTest.cs - RE-ENABLED for Workflow module STJ migration -->
65-
<!-- ReleaseTest.cs - RE-ENABLED for Release module STJ migration -->
66-
<!-- ReleaseItemTest.cs - RE-ENABLED for Release module STJ migration -->
67-
<Compile Remove="Models\RoleTest.cs" />
68-
<Compile Remove="Models\CustomExtensionTest.cs" />
69-
70-
<!-- OAuth tests (out of scope) -->
57+
<!-- OAuth tests excluded: OAuth is a separate feature, not part of STJ migration -->
7158
<Compile Remove="OAuth\**\*.cs" />
72-
73-
<!-- Infrastructure tests not yet migrated -->
74-
<Compile Remove="Queryable\QueryTest.cs" />
75-
<Compile Remove="Utils\TextNodeJsonConverterTest.cs" />
76-
<Compile Remove="Utils\NodeJsonConverterTest.cs" />
77-
<Compile Remove="Http\ContentstackHttpRequestTest.cs" />
78-
<Compile Remove="Http\ContentstackHttpResponseTest.cs" />
79-
<Compile Remove="Http\ContentstackErrorExceptionTest.cs" />
80-
<Compile Remove="Utils\ContentstackUtilitiesTest.cs" />
81-
<Compile Remove="Runtime\Pipeline\RetryHandler\RetryHandlerTest.cs" />
82-
<Compile Remove="Runtime\Pipeline\ContentstackRuntimePipelineTest.cs" />
83-
<Compile Remove="Runtime\Pipeline\RetryHandler\RetryHandlerIntegrationTest.cs" />
84-
<Compile Remove="Runtime\Pipeline\HttpHandler\HttpHandlerTest.cs" />
85-
<Compile Remove="Runtime\Pipeline\RetryHandler\DefaultRetryPolicyTest.cs" />
86-
<Compile Remove="Runtime\Contexts\ContextTest.cs" />
8759
</ItemGroup>
8860

8961
<ItemGroup>

Contentstack.Management.Core.Unit.Tests/Http/ContentstackHttpResponseTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void Should_Throw_Object_Disposed_Exception_On_Object_Dispose()
7575
contentstackHttpResponse.Dispose();
7676

7777
Assert.ThrowsException<ObjectDisposedException>(() => contentstackHttpResponse.OpenResponse());
78-
Assert.ThrowsException<ObjectDisposedException>(() => contentstackHttpResponse.OpenJObjectResponse());
78+
Assert.ThrowsException<ObjectDisposedException>(() => contentstackHttpResponse.OpenJsonObjectResponse());
7979
Assert.ThrowsException<ObjectDisposedException>(() => contentstackHttpResponse.OpenTResponse<StackModel>());
8080

8181
contentstackHttpResponse.Dispose();

Contentstack.Management.Core.Unit.Tests/Models/AuditLogTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void Should_Fetch_AuditLog()
5252
ContentstackResponse response = _stack.AuditLog(_fixture.Create<string>()).Fetch();
5353

5454
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
55-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
55+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
5656
}
5757

5858
[TestMethod]
@@ -61,7 +61,7 @@ public async System.Threading.Tasks.Task Should_Fetch_AuditLog_Async()
6161
ContentstackResponse response = await _stack.AuditLog(_fixture.Create<string>()).FetchAsync();
6262

6363
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
64-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
64+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
6565
}
6666

6767
[TestMethod]
@@ -70,7 +70,7 @@ public void Should_Find_AuditLog()
7070
ContentstackResponse response = _stack.AuditLog().FindAll();
7171

7272
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
73-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
73+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
7474
}
7575

7676
[TestMethod]
@@ -79,7 +79,7 @@ public async System.Threading.Tasks.Task Should_Find_AuditLog_Async()
7979
ContentstackResponse response = await _stack.AuditLog().FindAllAsync();
8080

8181
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
82-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
82+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
8383
}
8484

8585
}

Contentstack.Management.Core.Unit.Tests/Models/BaseModelTest.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using AutoFixture;
33
using Contentstack.Management.Core.Models;
44
using Contentstack.Management.Core.Unit.Tests.Mokes;
@@ -41,12 +41,12 @@ public void Initialize_ContentType()
4141
BaseModel<ContentModelling> baseModel = new BaseModel<ContentModelling>(_stack, _fixture.Create<string>());
4242

4343
Assert.IsNull(baseModel.Uid);
44-
Assert.ThrowsException<InvalidOperationException>(() => baseModel.Fetch());
45-
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => baseModel.FetchAsync());
46-
Assert.ThrowsException<InvalidOperationException>(() => baseModel.Update(new ContentModelling()));
47-
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => baseModel.UpdateAsync(new ContentModelling()));
48-
Assert.ThrowsException<InvalidOperationException>(() => baseModel.Delete());
49-
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => baseModel.DeleteAsync());
44+
Assert.ThrowsException<ArgumentException>(() => baseModel.Fetch());
45+
Assert.ThrowsExceptionAsync<ArgumentException>(() => baseModel.FetchAsync());
46+
Assert.ThrowsException<ArgumentException>(() => baseModel.Update(new ContentModelling()));
47+
Assert.ThrowsExceptionAsync<ArgumentException>(() => baseModel.UpdateAsync(new ContentModelling()));
48+
Assert.ThrowsException<ArgumentException>(() => baseModel.Delete());
49+
Assert.ThrowsExceptionAsync<ArgumentException>(() => baseModel.DeleteAsync());
5050

5151
}
5252
[TestMethod]
@@ -69,7 +69,7 @@ public void Should_Return_Mock_Response_On_Create()
6969
ContentstackResponse response = baseModel.Create(new ContentModelling());
7070

7171
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
72-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
72+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
7373
}
7474

7575
[TestMethod]
@@ -81,7 +81,7 @@ public async System.Threading.Tasks.Task Should_Return_Mock_Response_On_CreateAs
8181
ContentstackResponse response = await baseModel.CreateAsync(new ContentModelling());
8282

8383
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
84-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
84+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
8585
}
8686

8787
[TestMethod]
@@ -93,7 +93,7 @@ public void Should_Return_Mock_Response_On_Update()
9393
ContentstackResponse response = baseModel.Update(new ContentModelling());
9494

9595
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
96-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
96+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
9797
}
9898

9999
[TestMethod]
@@ -105,7 +105,7 @@ public async System.Threading.Tasks.Task Should_Return_Mock_Response_On_UpdateAs
105105
ContentstackResponse response = await baseModel.UpdateAsync(new ContentModelling());
106106

107107
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
108-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
108+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
109109
}
110110

111111
[TestMethod]
@@ -117,7 +117,7 @@ public void Should_Return_Mock_Response_On_Fetch()
117117
ContentstackResponse response = baseModel.Fetch();
118118

119119
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
120-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
120+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
121121
}
122122

123123
[TestMethod]
@@ -129,7 +129,7 @@ public async System.Threading.Tasks.Task Should_Return_Mock_Response_On_FetchAsy
129129
ContentstackResponse response = await baseModel.FetchAsync();
130130

131131
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
132-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
132+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
133133
}
134134

135135
[TestMethod]
@@ -141,7 +141,7 @@ public void Should_Return_Mock_Response_On_Delete()
141141
ContentstackResponse response = baseModel.Delete();
142142

143143
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
144-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
144+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
145145
}
146146

147147
[TestMethod]
@@ -153,7 +153,7 @@ public async System.Threading.Tasks.Task Should_Return_Mock_Response_On_DeleteAs
153153
ContentstackResponse response = await baseModel.DeleteAsync();
154154

155155
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
156-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
156+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
157157
}
158158
}
159159
}

0 commit comments

Comments
 (0)