Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@
</ItemGroup>

<ItemGroup>
<!-- Temporarily exclude all integration tests that depend on excluded models -->
<Compile Remove="IntegrationTest\**\*.cs" />

<!-- Exclude model helpers and fixtures -->
<Compile Remove="Model\Models.cs" />
<Compile Remove="Helpers\ContentTypeFixtureLoader.cs" />
<!-- Exclude out-of-scope integration tests (still use Newtonsoft or depend on excluded SDK types) -->
<Compile Remove="IntegrationTest\Contentstack004_ReleaseTest.cs" />
<Compile Remove="IntegrationTest\Contentstack012b_ContentTypeExpandedIntegrationTest.cs" />

<Compile Remove="IntegrationTest\Contentstack015_BulkOperationTest.cs" />
<Compile Remove="IntegrationTest\Contentstack016_DeliveryTokenTest.cs" />
<Compile Remove="IntegrationTest\Contentstack017_TaxonomyTest.cs" />
<Compile Remove="IntegrationTest\Contentstack019_RoleTest.cs" />
<Compile Remove="IntegrationTest\Contentstack020_WorkflowTest.cs" />
</ItemGroup>
</Project>
14 changes: 6 additions & 8 deletions Contentstack.Management.Core.Tests/Contentstack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using Contentstack.Management.Core.Tests.Model;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace Contentstack.Management.Core.Tests
{
Expand Down Expand Up @@ -242,17 +242,15 @@ public static ContentstackClient CreateAuthenticatedClient()
return client;
}

public static T serialize<T>(JsonSerializer serializer, string filePath)
public static T serialize<T>(JsonSerializerOptions options, string filePath)
{
string response = GetResourceText(filePath);
JObject jObject = JObject.Parse(response);
return jObject.ToObject<T>(serializer);
return JsonSerializer.Deserialize<T>(response, options);
}
public static T serializeArray<T>(JsonSerializer serializer, string filePath)
public static T serializeArray<T>(JsonSerializerOptions options, string filePath)
{
string response = GetResourceText(filePath);
JArray jObject = JArray.Parse(response);
return jObject.ToObject<T>(serializer);
return JsonSerializer.Deserialize<T>(response, options);
}

public static string GetResourceText(string resourceName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Contentstack.Management.Core.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace Contentstack.Management.Core.Tests.Helpers
{
Expand All @@ -9,15 +9,15 @@ namespace Contentstack.Management.Core.Tests.Helpers
/// </summary>
public static class ContentTypeFixtureLoader
{
public static ContentModelling LoadFromMock(JsonSerializer serializer, string embeddedFileName, string uidSuffix)
public static ContentModelling LoadFromMock(JsonSerializerOptions options, string embeddedFileName, string uidSuffix)
{
var text = Contentstack.GetResourceText(embeddedFileName);
var jo = JObject.Parse(text);
var baseUid = jo["uid"]?.Value<string>() ?? "ct";
var jo = JsonNode.Parse(text)!.AsObject();
var baseUid = jo["uid"]?.GetValue<string>() ?? "ct";
jo["uid"] = $"{baseUid}_{uidSuffix}";
var title = jo["title"]?.Value<string>() ?? "CT";
var title = jo["title"]?.GetValue<string>() ?? "CT";
jo["title"] = $"{title} {uidSuffix}";
return jo.ToObject<ContentModelling>(serializer);
return JsonSerializer.Deserialize<ContentModelling>(jo.ToJsonString(), options);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Text.Json;

namespace Contentstack.Management.Core.Tests.Helpers
{
Expand Down Expand Up @@ -44,7 +44,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
errors = _additionalFields
};

var jsonContent = JsonConvert.SerializeObject(errorResponse);
var jsonContent = JsonSerializer.Serialize(errorResponse);
var response = new HttpResponseMessage(_statusCode)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json;

namespace Contentstack.Management.Core.Tests.Helpers
{
Expand Down Expand Up @@ -64,7 +64,7 @@ private static void Emit(object data)
{
try
{
var json = JsonConvert.SerializeObject(data, Formatting.None);
var json = JsonSerializer.Serialize(data);
Console.Write(START_MARKER);
Console.Write(json);
Console.WriteLine(END_MARKER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Contentstack.Management.Core.Tests.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Contentstack.Management.Core.Queryable;
using Newtonsoft.Json.Linq;
using System.Text.Json;

namespace Contentstack.Management.Core.Tests.IntegrationTest
{
Expand Down Expand Up @@ -145,7 +145,7 @@ public void Test005_Should_Return_Loggedin_User()

ContentstackResponse response = client.GetUser();

var user = response.OpenJObjectResponse();
var user = response.OpenJsonObjectResponse();

AssertLogger.IsNotNull(user, "user");

Expand All @@ -169,11 +169,11 @@ public async System.Threading.Tasks.Task Test006_Should_Return_Loggedin_User_Asy

ContentstackResponse response = await client.GetUserAsync();

var user = response.OpenJObjectResponse();
var user = response.OpenJsonObjectResponse();

AssertLogger.IsNotNull(user, "user");
AssertLogger.IsNotNull(user["user"]["organizations"], "organizations");
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JArray), "organizations");
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(System.Text.Json.Nodes.JsonArray), "organizations");
AssertLogger.IsNull(user["user"]["organizations"][0]["org_roles"], "org_roles");

}
Expand All @@ -199,11 +199,11 @@ public void Test007_Should_Return_Loggedin_User_With_Organizations_detail()

ContentstackResponse response = client.GetUser(collection);

var user = response.OpenJObjectResponse();
var user = response.OpenJsonObjectResponse();

AssertLogger.IsNotNull(user, "user");
AssertLogger.IsNotNull(user["user"]["organizations"], "organizations");
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JArray), "organizations");
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(System.Text.Json.Nodes.JsonArray), "organizations");
AssertLogger.IsNotNull(user["user"]["organizations"][0]["org_roles"], "org_roles");
}
catch (Exception e)
Expand Down Expand Up @@ -1000,7 +1000,7 @@ public void Test056_Should_Handle_Malformed_JSON_Response_Sync()
{
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed JSON");
}
catch (Newtonsoft.Json.JsonException)
catch (System.Text.Json.JsonException)
{
AssertLogger.IsTrue(true, "JsonException acceptable for malformed JSON");
}
Expand All @@ -1027,7 +1027,7 @@ public async System.Threading.Tasks.Task Test057_Should_Handle_Malformed_JSON_Re
{
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed JSON");
}
catch (Newtonsoft.Json.JsonException)
catch (System.Text.Json.JsonException)
{
AssertLogger.IsTrue(true, "JsonException acceptable for malformed JSON");
}
Expand Down Expand Up @@ -1058,7 +1058,7 @@ public void Test058_Should_Handle_Empty_Response_Body_Sync()
{
AssertLogger.IsTrue(true, "ArgumentException acceptable for empty response");
}
catch (Newtonsoft.Json.JsonReaderException)
catch (System.Text.Json.JsonException)
{
AssertLogger.IsTrue(true, "JsonReaderException acceptable for empty response");
}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ public async System.Threading.Tasks.Task Test059_Should_Handle_Empty_Response_Bo
{
AssertLogger.IsTrue(true, "ArgumentException acceptable for empty response");
}
catch (Newtonsoft.Json.JsonReaderException)
catch (System.Text.Json.JsonException)
{
AssertLogger.IsTrue(true, "JsonReaderException acceptable for empty response");
}
Expand Down Expand Up @@ -1141,7 +1141,7 @@ public void Test060_Should_Handle_Unexpected_Response_Structure_Sync()
{
AssertLogger.IsTrue(true, "KeyNotFoundException acceptable for unexpected structure");
}
catch (Newtonsoft.Json.JsonException)
catch (System.Text.Json.JsonException)
{
AssertLogger.IsTrue(true, "JsonException acceptable for unexpected structure");
}
Expand Down Expand Up @@ -1284,8 +1284,9 @@ public void Test069_Should_Handle_GetUser_With_Extremely_Large_Parameters_Sync()
catch (ContentstackErrorException errorException)
{
AssertLogger.IsTrue(errorException.StatusCode == HttpStatusCode.BadRequest ||
errorException.StatusCode == HttpStatusCode.RequestEntityTooLarge,
"Expected 400 or 413 for large parameters");
errorException.StatusCode == HttpStatusCode.RequestEntityTooLarge ||
errorException.StatusCode == HttpStatusCode.RequestUriTooLong,
"Expected 400, 413, or 414 for large parameters");
}
catch (Exception e)
{
Expand Down Expand Up @@ -1393,7 +1394,7 @@ public void Test073_Should_Handle_GetUser_Malformed_Response_Sync()
{
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed response");
}
catch (Newtonsoft.Json.JsonException)
catch (System.Text.Json.JsonException)
{
AssertLogger.IsTrue(true, "JsonException acceptable for malformed response");
}
Expand Down Expand Up @@ -1856,7 +1857,7 @@ public async System.Threading.Tasks.Task Test100_Should_Validate_Complete_Error_
{
results.Add((scenario, false, "TaskCanceledException"));
}
catch (Newtonsoft.Json.JsonException)
catch (System.Text.Json.JsonException)
{
results.Add((scenario, false, "JsonException"));
}
Expand Down
Loading
Loading