Skip to content

Commit 7986576

Browse files
authored
Merge pull request #181 from contentstack/enhc/DX-8549
feat: Migrated unit test cases and Integration test cases to STJ
2 parents e999cd3 + 25ef701 commit 7986576

88 files changed

Lines changed: 1156 additions & 1285 deletions

File tree

Some content is hidden

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

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@
5353
</ItemGroup>
5454

5555
<ItemGroup>
56-
<!-- Temporarily exclude all integration tests that depend on excluded models -->
57-
<Compile Remove="IntegrationTest\**\*.cs" />
58-
59-
<!-- Exclude model helpers and fixtures -->
60-
<Compile Remove="Model\Models.cs" />
61-
<Compile Remove="Helpers\ContentTypeFixtureLoader.cs" />
56+
<!-- Exclude out-of-scope integration tests (still use Newtonsoft or depend on excluded SDK types) -->
57+
<Compile Remove="IntegrationTest\Contentstack004_ReleaseTest.cs" />
58+
<Compile Remove="IntegrationTest\Contentstack012b_ContentTypeExpandedIntegrationTest.cs" />
59+
60+
<Compile Remove="IntegrationTest\Contentstack015_BulkOperationTest.cs" />
61+
<Compile Remove="IntegrationTest\Contentstack016_DeliveryTokenTest.cs" />
62+
<Compile Remove="IntegrationTest\Contentstack017_TaxonomyTest.cs" />
63+
<Compile Remove="IntegrationTest\Contentstack019_RoleTest.cs" />
64+
<Compile Remove="IntegrationTest\Contentstack020_WorkflowTest.cs" />
6265
</ItemGroup>
6366
</Project>

Contentstack.Management.Core.Tests/Contentstack.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
using Contentstack.Management.Core.Tests.Model;
1212
using Microsoft.Extensions.Configuration;
1313
using Microsoft.Extensions.Options;
14-
using Newtonsoft.Json;
15-
using Newtonsoft.Json.Linq;
14+
using System.Text.Json;
15+
using System.Text.Json.Nodes;
1616

1717
namespace Contentstack.Management.Core.Tests
1818
{
@@ -242,17 +242,15 @@ public static ContentstackClient CreateAuthenticatedClient()
242242
return client;
243243
}
244244

245-
public static T serialize<T>(JsonSerializer serializer, string filePath)
245+
public static T serialize<T>(JsonSerializerOptions options, string filePath)
246246
{
247247
string response = GetResourceText(filePath);
248-
JObject jObject = JObject.Parse(response);
249-
return jObject.ToObject<T>(serializer);
248+
return JsonSerializer.Deserialize<T>(response, options);
250249
}
251-
public static T serializeArray<T>(JsonSerializer serializer, string filePath)
250+
public static T serializeArray<T>(JsonSerializerOptions options, string filePath)
252251
{
253252
string response = GetResourceText(filePath);
254-
JArray jObject = JArray.Parse(response);
255-
return jObject.ToObject<T>(serializer);
253+
return JsonSerializer.Deserialize<T>(response, options);
256254
}
257255

258256
public static string GetResourceText(string resourceName)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Contentstack.Management.Core.Models;
2-
using Newtonsoft.Json;
3-
using Newtonsoft.Json.Linq;
2+
using System.Text.Json;
3+
using System.Text.Json.Nodes;
44

55
namespace Contentstack.Management.Core.Tests.Helpers
66
{
@@ -9,15 +9,15 @@ namespace Contentstack.Management.Core.Tests.Helpers
99
/// </summary>
1010
public static class ContentTypeFixtureLoader
1111
{
12-
public static ContentModelling LoadFromMock(JsonSerializer serializer, string embeddedFileName, string uidSuffix)
12+
public static ContentModelling LoadFromMock(JsonSerializerOptions options, string embeddedFileName, string uidSuffix)
1313
{
1414
var text = Contentstack.GetResourceText(embeddedFileName);
15-
var jo = JObject.Parse(text);
16-
var baseUid = jo["uid"]?.Value<string>() ?? "ct";
15+
var jo = JsonNode.Parse(text)!.AsObject();
16+
var baseUid = jo["uid"]?.GetValue<string>() ?? "ct";
1717
jo["uid"] = $"{baseUid}_{uidSuffix}";
18-
var title = jo["title"]?.Value<string>() ?? "CT";
18+
var title = jo["title"]?.GetValue<string>() ?? "CT";
1919
jo["title"] = $"{title} {uidSuffix}";
20-
return jo.ToObject<ContentModelling>(serializer);
20+
return JsonSerializer.Deserialize<ContentModelling>(jo.ToJsonString(), options);
2121
}
2222
}
2323
}

Contentstack.Management.Core.Tests/Helpers/MockHttpStatusHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Text;
66
using System.Threading;
77
using System.Threading.Tasks;
8-
using Newtonsoft.Json;
8+
using System.Text.Json;
99

1010
namespace Contentstack.Management.Core.Tests.Helpers
1111
{
@@ -44,7 +44,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
4444
errors = _additionalFields
4545
};
4646

47-
var jsonContent = JsonConvert.SerializeObject(errorResponse);
47+
var jsonContent = JsonSerializer.Serialize(errorResponse);
4848
var response = new HttpResponseMessage(_statusCode)
4949
{
5050
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json"),

Contentstack.Management.Core.Tests/Helpers/TestOutputLogger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using Newtonsoft.Json;
3+
using System.Text.Json;
44

55
namespace Contentstack.Management.Core.Tests.Helpers
66
{
@@ -64,7 +64,7 @@ private static void Emit(object data)
6464
{
6565
try
6666
{
67-
var json = JsonConvert.SerializeObject(data, Formatting.None);
67+
var json = JsonSerializer.Serialize(data);
6868
Console.Write(START_MARKER);
6969
Console.Write(json);
7070
Console.WriteLine(END_MARKER);

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Contentstack.Management.Core.Tests.Helpers;
99
using Microsoft.VisualStudio.TestTools.UnitTesting;
1010
using Contentstack.Management.Core.Queryable;
11-
using Newtonsoft.Json.Linq;
11+
using System.Text.Json;
1212

1313
namespace Contentstack.Management.Core.Tests.IntegrationTest
1414
{
@@ -145,7 +145,7 @@ public void Test005_Should_Return_Loggedin_User()
145145

146146
ContentstackResponse response = client.GetUser();
147147

148-
var user = response.OpenJObjectResponse();
148+
var user = response.OpenJsonObjectResponse();
149149

150150
AssertLogger.IsNotNull(user, "user");
151151

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

170170
ContentstackResponse response = await client.GetUserAsync();
171171

172-
var user = response.OpenJObjectResponse();
172+
var user = response.OpenJsonObjectResponse();
173173

174174
AssertLogger.IsNotNull(user, "user");
175175
AssertLogger.IsNotNull(user["user"]["organizations"], "organizations");
176-
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JArray), "organizations");
176+
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(System.Text.Json.Nodes.JsonArray), "organizations");
177177
AssertLogger.IsNull(user["user"]["organizations"][0]["org_roles"], "org_roles");
178178

179179
}
@@ -199,11 +199,11 @@ public void Test007_Should_Return_Loggedin_User_With_Organizations_detail()
199199

200200
ContentstackResponse response = client.GetUser(collection);
201201

202-
var user = response.OpenJObjectResponse();
202+
var user = response.OpenJsonObjectResponse();
203203

204204
AssertLogger.IsNotNull(user, "user");
205205
AssertLogger.IsNotNull(user["user"]["organizations"], "organizations");
206-
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JArray), "organizations");
206+
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(System.Text.Json.Nodes.JsonArray), "organizations");
207207
AssertLogger.IsNotNull(user["user"]["organizations"][0]["org_roles"], "org_roles");
208208
}
209209
catch (Exception e)
@@ -1000,7 +1000,7 @@ public void Test056_Should_Handle_Malformed_JSON_Response_Sync()
10001000
{
10011001
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed JSON");
10021002
}
1003-
catch (Newtonsoft.Json.JsonException)
1003+
catch (System.Text.Json.JsonException)
10041004
{
10051005
AssertLogger.IsTrue(true, "JsonException acceptable for malformed JSON");
10061006
}
@@ -1027,7 +1027,7 @@ public async System.Threading.Tasks.Task Test057_Should_Handle_Malformed_JSON_Re
10271027
{
10281028
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed JSON");
10291029
}
1030-
catch (Newtonsoft.Json.JsonException)
1030+
catch (System.Text.Json.JsonException)
10311031
{
10321032
AssertLogger.IsTrue(true, "JsonException acceptable for malformed JSON");
10331033
}
@@ -1058,7 +1058,7 @@ public void Test058_Should_Handle_Empty_Response_Body_Sync()
10581058
{
10591059
AssertLogger.IsTrue(true, "ArgumentException acceptable for empty response");
10601060
}
1061-
catch (Newtonsoft.Json.JsonReaderException)
1061+
catch (System.Text.Json.JsonException)
10621062
{
10631063
AssertLogger.IsTrue(true, "JsonReaderException acceptable for empty response");
10641064
}
@@ -1089,7 +1089,7 @@ public async System.Threading.Tasks.Task Test059_Should_Handle_Empty_Response_Bo
10891089
{
10901090
AssertLogger.IsTrue(true, "ArgumentException acceptable for empty response");
10911091
}
1092-
catch (Newtonsoft.Json.JsonReaderException)
1092+
catch (System.Text.Json.JsonException)
10931093
{
10941094
AssertLogger.IsTrue(true, "JsonReaderException acceptable for empty response");
10951095
}
@@ -1141,7 +1141,7 @@ public void Test060_Should_Handle_Unexpected_Response_Structure_Sync()
11411141
{
11421142
AssertLogger.IsTrue(true, "KeyNotFoundException acceptable for unexpected structure");
11431143
}
1144-
catch (Newtonsoft.Json.JsonException)
1144+
catch (System.Text.Json.JsonException)
11451145
{
11461146
AssertLogger.IsTrue(true, "JsonException acceptable for unexpected structure");
11471147
}
@@ -1284,8 +1284,9 @@ public void Test069_Should_Handle_GetUser_With_Extremely_Large_Parameters_Sync()
12841284
catch (ContentstackErrorException errorException)
12851285
{
12861286
AssertLogger.IsTrue(errorException.StatusCode == HttpStatusCode.BadRequest ||
1287-
errorException.StatusCode == HttpStatusCode.RequestEntityTooLarge,
1288-
"Expected 400 or 413 for large parameters");
1287+
errorException.StatusCode == HttpStatusCode.RequestEntityTooLarge ||
1288+
errorException.StatusCode == HttpStatusCode.RequestUriTooLong,
1289+
"Expected 400, 413, or 414 for large parameters");
12891290
}
12901291
catch (Exception e)
12911292
{
@@ -1393,7 +1394,7 @@ public void Test073_Should_Handle_GetUser_Malformed_Response_Sync()
13931394
{
13941395
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed response");
13951396
}
1396-
catch (Newtonsoft.Json.JsonException)
1397+
catch (System.Text.Json.JsonException)
13971398
{
13981399
AssertLogger.IsTrue(true, "JsonException acceptable for malformed response");
13991400
}
@@ -1856,7 +1857,7 @@ public async System.Threading.Tasks.Task Test100_Should_Validate_Complete_Error_
18561857
{
18571858
results.Add((scenario, false, "TaskCanceledException"));
18581859
}
1859-
catch (Newtonsoft.Json.JsonException)
1860+
catch (System.Text.Json.JsonException)
18601861
{
18611862
results.Add((scenario, false, "JsonException"));
18621863
}

0 commit comments

Comments
 (0)