Skip to content

Commit fc3a281

Browse files
committed
Revert "feat: Migration changes"
This reverts commit ca06d6b.
1 parent ca06d6b commit fc3a281

250 files changed

Lines changed: 2952 additions & 3593 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.

COMPREHENSIVE_MIGRATION_GUIDE.md

Lines changed: 0 additions & 942 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net10.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
<ReleaseVersion>$(Version)</ReleaseVersion>
@@ -24,6 +24,7 @@
2424
<PackageReference Include="AutoFixture.AutoMoq" Version="4.18.1" />
2525
<PackageReference Include="Moq" Version="4.20.72" />
2626
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.3.0" />
27+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
2728
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
2829
</ItemGroup>
2930

Contentstack.Management.Core.Tests/Contentstack.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
using System.Net;
66
using System.Net.Http;
77
using System.Reflection;
8-
using System.Text.Json;
98
using System.Threading.Tasks;
109
using Contentstack.Management.Core.Exceptions;
1110
using Contentstack.Management.Core.Tests.Helpers;
1211
using Contentstack.Management.Core.Tests.Model;
1312
using Microsoft.Extensions.Configuration;
1413
using Microsoft.Extensions.Options;
14+
using Newtonsoft.Json;
15+
using Newtonsoft.Json.Linq;
1516

1617
namespace Contentstack.Management.Core.Tests
1718
{
@@ -118,13 +119,17 @@ public static ContentstackResponse LoginWithRetry(ContentstackClient client, int
118119
}
119120
catch (Exception ex) when (IsAccountLockout(ex) && attempt < maxRetries)
120121
{
121-
int delay = baseDelayMs * (int)Math.Pow(2, attempt);
122+
int delay = baseDelayMs * (int)Math.Pow(2, attempt); // Exponential backoff
122123
System.Threading.Thread.Sleep(delay);
123124
}
124125
}
126+
// Final attempt without catching lockout
125127
return client.Login(Credential, null, MfaSecret);
126128
}
127129

130+
/// <summary>
131+
/// Executes async login with retry logic for account lockouts
132+
/// </summary>
128133
public static async Task<ContentstackResponse> LoginWithRetryAsync(ContentstackClient client, int maxRetries = 3, int baseDelayMs = 5000)
129134
{
130135
for (int attempt = 0; attempt <= maxRetries; attempt++)
@@ -135,61 +140,88 @@ public static async Task<ContentstackResponse> LoginWithRetryAsync(ContentstackC
135140
}
136141
catch (Exception ex) when (IsAccountLockout(ex) && attempt < maxRetries)
137142
{
138-
int delay = baseDelayMs * (int)Math.Pow(2, attempt);
143+
int delay = baseDelayMs * (int)Math.Pow(2, attempt); // Exponential backoff
139144
await Task.Delay(delay);
140145
}
141146
}
147+
// Final attempt without catching lockout
142148
return await client.LoginAsync(Credential, null, MfaSecret);
143149
}
144150

151+
/// <summary>
152+
/// Executes login with TOTP-aware retry logic for token reuse and account lockouts
153+
/// </summary>
145154
public static ContentstackResponse LoginWithTotpRetry(ContentstackClient client, int maxRetries = 3)
146155
{
147156
for (int attempt = 0; attempt <= maxRetries; attempt++)
148157
{
149158
try
150159
{
160+
// Ensure fresh TOTP window before each attempt
151161
EnsureFreshTotpWindow();
152162
return client.Login(Credential, null, MfaSecret);
153163
}
154164
catch (Exception ex) when (attempt < maxRetries)
155165
{
156166
if (IsTotpReuse(ex))
167+
{
168+
// Wait for fresh TOTP window (35+ seconds)
157169
System.Threading.Thread.Sleep(35000);
170+
}
158171
else if (IsAccountLockout(ex))
159172
{
173+
// Exponential backoff for account lockout
160174
int delay = 5000 * (int)Math.Pow(2, attempt);
161175
System.Threading.Thread.Sleep(delay);
162176
}
163177
else
178+
{
179+
// For other errors, short delay before retry
164180
System.Threading.Thread.Sleep(1000);
181+
}
165182
}
166183
}
184+
185+
// Final attempt without catching errors
167186
EnsureFreshTotpWindow();
168187
return client.Login(Credential, null, MfaSecret);
169188
}
170189

190+
/// <summary>
191+
/// Executes async login with TOTP-aware retry logic for token reuse and account lockouts
192+
/// </summary>
171193
public static async Task<ContentstackResponse> LoginWithTotpRetryAsync(ContentstackClient client, int maxRetries = 3)
172194
{
173195
for (int attempt = 0; attempt <= maxRetries; attempt++)
174196
{
175197
try
176198
{
199+
// Ensure fresh TOTP window before each attempt
177200
EnsureFreshTotpWindow();
178201
return await client.LoginAsync(Credential, null, MfaSecret);
179202
}
180203
catch (Exception ex) when (attempt < maxRetries)
181204
{
182205
if (IsTotpReuse(ex))
206+
{
207+
// Wait for fresh TOTP window (35+ seconds)
183208
await Task.Delay(35000);
209+
}
184210
else if (IsAccountLockout(ex))
185211
{
212+
// Exponential backoff for account lockout
186213
int delay = 5000 * (int)Math.Pow(2, attempt);
187214
await Task.Delay(delay);
188215
}
189216
else
217+
{
218+
// For other errors, short delay before retry
190219
await Task.Delay(1000);
220+
}
191221
}
192222
}
223+
224+
// Final attempt without catching errors
193225
EnsureFreshTotpWindow();
194226
return await client.LoginAsync(Credential, null, MfaSecret);
195227
}
@@ -210,16 +242,17 @@ public static ContentstackClient CreateAuthenticatedClient()
210242
return client;
211243
}
212244

213-
public static T serialize<T>(JsonSerializerOptions options, string filePath)
245+
public static T serialize<T>(JsonSerializer serializer, string filePath)
214246
{
215247
string response = GetResourceText(filePath);
216-
return JsonSerializer.Deserialize<T>(response, options);
248+
JObject jObject = JObject.Parse(response);
249+
return jObject.ToObject<T>(serializer);
217250
}
218-
219-
public static T serializeArray<T>(JsonSerializerOptions options, string filePath)
251+
public static T serializeArray<T>(JsonSerializer serializer, string filePath)
220252
{
221253
string response = GetResourceText(filePath);
222-
return JsonSerializer.Deserialize<T>(response, options);
254+
JArray jObject = JArray.Parse(response);
255+
return jObject.ToObject<T>(serializer);
223256
}
224257

225258
public static string GetResourceText(string resourceName)

Contentstack.Management.Core.Tests/GlobalUsings.cs

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Text.Json;
2-
using System.Text.Json.Nodes;
31
using Contentstack.Management.Core.Models;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Linq;
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(JsonSerializerOptions options, string embeddedFileName, string uidSuffix)
12+
public static ContentModelling LoadFromMock(JsonSerializer serializer, string embeddedFileName, string uidSuffix)
1313
{
1414
var text = Contentstack.GetResourceText(embeddedFileName);
15-
var root = JsonNode.Parse(text)!.AsObject();
16-
var baseUid = root["uid"]?.GetValue<string>() ?? "ct";
17-
root["uid"] = $"{baseUid}_{uidSuffix}";
18-
var title = root["title"]?.GetValue<string>() ?? "CT";
19-
root["title"] = $"{title} {uidSuffix}";
20-
return root.Deserialize<ContentModelling>(options);
15+
var jo = JObject.Parse(text);
16+
var baseUid = jo["uid"]?.Value<string>() ?? "ct";
17+
jo["uid"] = $"{baseUid}_{uidSuffix}";
18+
var title = jo["title"]?.Value<string>() ?? "CT";
19+
jo["title"] = $"{title} {uidSuffix}";
20+
return jo.ToObject<ContentModelling>(serializer);
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 System.Text.Json;
8+
using Newtonsoft.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 = JsonSerializer.Serialize(errorResponse);
47+
var jsonContent = JsonConvert.SerializeObject(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 System.Text.Json;
3+
using Newtonsoft.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 = JsonSerializer.Serialize(data);
67+
var json = JsonConvert.SerializeObject(data, Formatting.None);
6868
Console.Write(START_MARKER);
6969
Console.Write(json);
7070
Console.WriteLine(END_MARKER);

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +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;
1112

1213
namespace Contentstack.Management.Core.Tests.IntegrationTest
1314
{
@@ -144,7 +145,7 @@ public void Test005_Should_Return_Loggedin_User()
144145

145146
ContentstackResponse response = client.GetUser();
146147

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

149150
AssertLogger.IsNotNull(user, "user");
150151

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

169170
ContentstackResponse response = await client.GetUserAsync();
170171

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

173174
AssertLogger.IsNotNull(user, "user");
174175
AssertLogger.IsNotNull(user["user"]["organizations"], "organizations");
175-
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JsonArray), "organizations");
176+
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JArray), "organizations");
176177
AssertLogger.IsNull(user["user"]["organizations"][0]["org_roles"], "org_roles");
177178

178179
}
@@ -198,11 +199,11 @@ public void Test007_Should_Return_Loggedin_User_With_Organizations_detail()
198199

199200
ContentstackResponse response = client.GetUser(collection);
200201

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

203204
AssertLogger.IsNotNull(user, "user");
204205
AssertLogger.IsNotNull(user["user"]["organizations"], "organizations");
205-
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JsonArray), "organizations");
206+
AssertLogger.IsInstanceOfType(user["user"]["organizations"], typeof(JArray), "organizations");
206207
AssertLogger.IsNotNull(user["user"]["organizations"][0]["org_roles"], "org_roles");
207208
}
208209
catch (Exception e)
@@ -999,7 +1000,7 @@ public void Test056_Should_Handle_Malformed_JSON_Response_Sync()
9991000
{
10001001
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed JSON");
10011002
}
1002-
catch (JsonException)
1003+
catch (Newtonsoft.Json.JsonException)
10031004
{
10041005
AssertLogger.IsTrue(true, "JsonException acceptable for malformed JSON");
10051006
}
@@ -1026,7 +1027,7 @@ public async System.Threading.Tasks.Task Test057_Should_Handle_Malformed_JSON_Re
10261027
{
10271028
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed JSON");
10281029
}
1029-
catch (JsonException)
1030+
catch (Newtonsoft.Json.JsonException)
10301031
{
10311032
AssertLogger.IsTrue(true, "JsonException acceptable for malformed JSON");
10321033
}
@@ -1057,7 +1058,7 @@ public void Test058_Should_Handle_Empty_Response_Body_Sync()
10571058
{
10581059
AssertLogger.IsTrue(true, "ArgumentException acceptable for empty response");
10591060
}
1060-
catch (JsonException)
1061+
catch (Newtonsoft.Json.JsonReaderException)
10611062
{
10621063
AssertLogger.IsTrue(true, "JsonReaderException acceptable for empty response");
10631064
}
@@ -1088,7 +1089,7 @@ public async System.Threading.Tasks.Task Test059_Should_Handle_Empty_Response_Bo
10881089
{
10891090
AssertLogger.IsTrue(true, "ArgumentException acceptable for empty response");
10901091
}
1091-
catch (JsonException)
1092+
catch (Newtonsoft.Json.JsonReaderException)
10921093
{
10931094
AssertLogger.IsTrue(true, "JsonReaderException acceptable for empty response");
10941095
}
@@ -1140,7 +1141,7 @@ public void Test060_Should_Handle_Unexpected_Response_Structure_Sync()
11401141
{
11411142
AssertLogger.IsTrue(true, "KeyNotFoundException acceptable for unexpected structure");
11421143
}
1143-
catch (JsonException)
1144+
catch (Newtonsoft.Json.JsonException)
11441145
{
11451146
AssertLogger.IsTrue(true, "JsonException acceptable for unexpected structure");
11461147
}
@@ -1392,7 +1393,7 @@ public void Test073_Should_Handle_GetUser_Malformed_Response_Sync()
13921393
{
13931394
AssertLogger.IsTrue(true, "ContentstackErrorException acceptable for malformed response");
13941395
}
1395-
catch (JsonException)
1396+
catch (Newtonsoft.Json.JsonException)
13961397
{
13971398
AssertLogger.IsTrue(true, "JsonException acceptable for malformed response");
13981399
}
@@ -1855,7 +1856,7 @@ public async System.Threading.Tasks.Task Test100_Should_Validate_Complete_Error_
18551856
{
18561857
results.Add((scenario, false, "TaskCanceledException"));
18571858
}
1858-
catch (JsonException)
1859+
catch (Newtonsoft.Json.JsonException)
18591860
{
18601861
results.Add((scenario, false, "JsonException"));
18611862
}

0 commit comments

Comments
 (0)