Skip to content

Commit f1df975

Browse files
committed
feat: Migrate SDK from Newtonsoft.Json to System.Text.Json
- Replace all [JsonProperty] attributes with [JsonPropertyName] across all model classes (LabelModel, ExtensionModel, RoleModel, OAuthResponse, OAuthAppAuthorizationResponse, ExtensionScope, RoleModel nested classes, Token models) - Remove [JsonObject] attributes — null handling covered globally by DefaultIgnoreCondition = WhenWritingNull - Replace Newtonsoft JsonSerializer/JsonConverter with System.Text.Json equivalents in all service constructors and model classes - Migrate ParameterCollection.AddQuery(JObject) → AddQuery(JsonNode) and QueryParamValue.JObjectParameterValue to use JsonNode - Remove OpenJObjectResponse() from IResponse and ContentstackResponse — replaced by OpenJsonObjectResponse() (System.Text.Json.Nodes.JsonObject) - Rewrite NodeJsonConverterTest and TextNodeJsonConverterTest using STJ public API (JsonSerializer.Serialize/Deserialize) - Rewrite CustomJsonConverter mock from Newtonsoft JsonConverter base to JsonConverter<object> (STJ) - Migrate CustomWidgetModel scope serialization from JsonTextWriter to JsonSerializer.Serialize - Remove Newtonsoft.Json 13.0.3 package reference from core csproj - Re-enable all previously excluded model files (Role, Taxonomy, Term, Extension, Label, AuditLog, Webhook, Token, CustomExtension) and uncomment corresponding Stack accessor methods - Re-enable 4 excluded integration test files and fix missing using directives - Re-enable all 25 excluded unit test files; fix ArgumentException vs InvalidOperationException assertions for uid-empty guard methods - Enable OAuth: remove Compile Remove for OAuthHandler.cs and Services/OAuth, uncomment OAuth methods and EnsureOAuthTokenIsValidAsync in ContentstackClient - Fix service constructor calls in Term, Taxonomy, Webhook, Extension, AuditLog — remove legacy serializer first-arg pattern - Update unit test count: 991 → 1,242 tests all passing
1 parent d55fc73 commit f1df975

49 files changed

Lines changed: 420 additions & 626 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
@@ -25,9 +25,13 @@
2525
- Migrated `LocaleModel` and `BulkOperationModels` to use `System.Text.Json` attributes
2626
- Added/updated unit and integration test coverage for Locale and Bulk Operations
2727
- Upgraded target framework to .NET 10 and removed all build warnings
28-
- **Note**:
29-
- This is a beta release and APIs/modules may continue evolving during migration stabilization
30-
- 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
28+
- 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
29+
- All `[JsonProperty]` replaced with `[JsonPropertyName]` across all model classes; `[JsonObject(ItemNullValueHandling)]` removed in favour of global `DefaultIgnoreCondition = WhenWritingNull`
30+
- OAuth module enabled — `OAuthHandler`, `OAuthTokenService`, `OAuthAppAuthorizationService`, and `OAuthAppRevocationService` now active; auto token refresh wired into `InvokeAsync` pipeline via `EnsureOAuthTokenIsValidAsync`
31+
- CustomWidgetModel scope serialization migrated from `JsonTextWriter` to `System.Text.Json.JsonSerializer.Serialize()`
32+
- 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
33+
- 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)
34+
- Integration test coverage expanded — 4 previously excluded integration test files re-enabled: ContentType Expanded (`Contentstack012b`), DeliveryToken (`Contentstack016`), Taxonomy (`Contentstack017`), Role (`Contentstack019`)
3135

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

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +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-
<Compile Remove="IntegrationTest\Contentstack016_DeliveryTokenTest.cs" />
61-
<Compile Remove="IntegrationTest\Contentstack017_TaxonomyTest.cs" />
62-
<Compile Remove="IntegrationTest\Contentstack019_RoleTest.cs" />
63-
</ItemGroup>
6454
</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/contentTypeSchema.json");
414+
try
415+
{
416+
DashboardWidgetModel dashboard = new DashboardWidgetModel(
417+
path, "application/json", "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/contentTypeSchema.json");
443+
try
444+
{
445+
var scope = new ExtensionScope { ContentTypes = new List<string> { "$all" } };
446+
CustomWidgetModel widget = new CustomWidgetModel(
447+
path, "application/json", "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/contentTypeSchema.json");
473+
try
474+
{
475+
CustomFieldModel field = new CustomFieldModel(
476+
path, "application/json", "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
@@ -3664,7 +3664,7 @@ private async Task CreateTestRelease()
36643664
if (response.IsSuccessStatusCode && responseJson["release"] != null)
36653665
_testReleaseUid = responseJson["release"]["uid"].ToString();
36663666
}
3667-
catch (Exception e) { }
3667+
catch (Exception) { }
36683668
await Task.CompletedTask;
36693669
}
36703670

0 commit comments

Comments
 (0)