Skip to content

Commit 5e0ad6d

Browse files
committed
feat: fixed taxonomy skipped test cases
1 parent 58206b6 commit 5e0ad6d

File tree

4 files changed

+128
-47630
lines changed

4 files changed

+128
-47630
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ packages/
2424
*/mono**
2525
*/appSettings.json
2626
api_referece/*
27-
.sonarqube/
27+
.sonarqube/
28+
*.html
29+
*.cobertura.xml
30+
integration-test-report_*.html

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Net;
3+
using System.Net.Http;
34
using Contentstack.Management.Core.Exceptions;
45
using Contentstack.Management.Core.Models;
56
using Contentstack.Management.Core.Tests.Helpers;
@@ -16,12 +17,20 @@ namespace Contentstack.Management.Core.Tests.IntegrationTest
1617
public class Contentstack001_LoginTest
1718
{
1819
private readonly IConfigurationRoot _configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
20+
21+
private static ContentstackClient CreateClientWithLogging()
22+
{
23+
var handler = new LoggingHttpHandler();
24+
var httpClient = new HttpClient(handler);
25+
return new ContentstackClient(httpClient, new ContentstackClientOptions());
26+
}
27+
1928
[TestMethod]
2029
[DoNotParallelize]
2130
public void Test001_Should_Return_Failuer_On_Wrong_Login_Credentials()
2231
{
2332
TestOutputLogger.LogContext("TestScenario", "WrongCredentials");
24-
ContentstackClient client = new ContentstackClient();
33+
ContentstackClient client = CreateClientWithLogging();
2534
NetworkCredential credentials = new NetworkCredential("mock_user", "mock_pasword");
2635

2736
try
@@ -42,7 +51,7 @@ public void Test001_Should_Return_Failuer_On_Wrong_Login_Credentials()
4251
public void Test002_Should_Return_Failuer_On_Wrong_Async_Login_Credentials()
4352
{
4453
TestOutputLogger.LogContext("TestScenario", "WrongCredentialsAsync");
45-
ContentstackClient client = new ContentstackClient();
54+
ContentstackClient client = CreateClientWithLogging();
4655
NetworkCredential credentials = new NetworkCredential("mock_user", "mock_pasword");
4756
var response = client.LoginAsync(credentials);
4857

@@ -65,7 +74,7 @@ public void Test002_Should_Return_Failuer_On_Wrong_Async_Login_Credentials()
6574
public async System.Threading.Tasks.Task Test003_Should_Return_Success_On_Async_Login()
6675
{
6776
TestOutputLogger.LogContext("TestScenario", "AsyncLoginSuccess");
68-
ContentstackClient client = new ContentstackClient();
77+
ContentstackClient client = CreateClientWithLogging();
6978

7079
try
7180
{
@@ -90,7 +99,7 @@ public void Test004_Should_Return_Success_On_Login()
9099
TestOutputLogger.LogContext("TestScenario", "SyncLoginSuccess");
91100
try
92101
{
93-
ContentstackClient client = new ContentstackClient();
102+
ContentstackClient client = CreateClientWithLogging();
94103

95104
ContentstackResponse contentstackResponse = client.Login(Contentstack.Credential);
96105
string loginResponse = contentstackResponse.OpenResponse();
@@ -111,7 +120,7 @@ public void Test005_Should_Return_Loggedin_User()
111120
TestOutputLogger.LogContext("TestScenario", "GetUser");
112121
try
113122
{
114-
ContentstackClient client = new ContentstackClient();
123+
ContentstackClient client = CreateClientWithLogging();
115124

116125
client.Login(Contentstack.Credential);
117126

@@ -135,7 +144,7 @@ public async System.Threading.Tasks.Task Test006_Should_Return_Loggedin_User_Asy
135144
TestOutputLogger.LogContext("TestScenario", "GetUserAsync");
136145
try
137146
{
138-
ContentstackClient client = new ContentstackClient();
147+
ContentstackClient client = CreateClientWithLogging();
139148

140149
await client.LoginAsync(Contentstack.Credential);
141150

@@ -165,7 +174,7 @@ public void Test007_Should_Return_Loggedin_User_With_Organizations_detail()
165174
ParameterCollection collection = new ParameterCollection();
166175
collection.Add("include_orgs_roles", true);
167176

168-
ContentstackClient client = new ContentstackClient();
177+
ContentstackClient client = CreateClientWithLogging();
169178

170179
client.Login(Contentstack.Credential);
171180

@@ -189,7 +198,7 @@ public void Test007_Should_Return_Loggedin_User_With_Organizations_detail()
189198
public void Test008_Should_Fail_Login_With_Invalid_MfaSecret()
190199
{
191200
TestOutputLogger.LogContext("TestScenario", "InvalidMfaSecret");
192-
ContentstackClient client = new ContentstackClient();
201+
ContentstackClient client = CreateClientWithLogging();
193202
NetworkCredential credentials = new NetworkCredential("test_user", "test_password");
194203
string invalidMfaSecret = "INVALID_BASE32_SECRET!@#";
195204

@@ -213,7 +222,7 @@ public void Test008_Should_Fail_Login_With_Invalid_MfaSecret()
213222
public void Test009_Should_Generate_TOTP_Token_With_Valid_MfaSecret()
214223
{
215224
TestOutputLogger.LogContext("TestScenario", "ValidMfaSecret");
216-
ContentstackClient client = new ContentstackClient();
225+
ContentstackClient client = CreateClientWithLogging();
217226
NetworkCredential credentials = new NetworkCredential("test_user", "test_password");
218227
string validMfaSecret = "JBSWY3DPEHPK3PXP";
219228

@@ -243,7 +252,7 @@ public void Test009_Should_Generate_TOTP_Token_With_Valid_MfaSecret()
243252
public async System.Threading.Tasks.Task Test010_Should_Generate_TOTP_Token_With_Valid_MfaSecret_Async()
244253
{
245254
TestOutputLogger.LogContext("TestScenario", "ValidMfaSecretAsync");
246-
ContentstackClient client = new ContentstackClient();
255+
ContentstackClient client = CreateClientWithLogging();
247256
NetworkCredential credentials = new NetworkCredential("test_user", "test_password");
248257
string validMfaSecret = "JBSWY3DPEHPK3PXP";
249258

@@ -273,7 +282,7 @@ public async System.Threading.Tasks.Task Test010_Should_Generate_TOTP_Token_With
273282
public void Test011_Should_Prefer_Explicit_Token_Over_MfaSecret()
274283
{
275284
TestOutputLogger.LogContext("TestScenario", "ExplicitTokenOverMfa");
276-
ContentstackClient client = new ContentstackClient();
285+
ContentstackClient client = CreateClientWithLogging();
277286
NetworkCredential credentials = new NetworkCredential("test_user", "test_password");
278287
string validMfaSecret = "JBSWY3DPEHPK3PXP";
279288
string explicitToken = "123456";

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

Lines changed: 104 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public class Contentstack017_TaxonomyTest
2121
private static string _asyncCreatedTaxonomyUid;
2222
private static string _importedTaxonomyUid;
2323
private static string _testLocaleCode;
24+
private static string _asyncTestLocaleCode;
2425
private static bool _weCreatedTestLocale;
26+
private static bool _weCreatedAsyncTestLocale;
2527
private static List<string> _createdTermUids;
2628
private static string _rootTermUid;
2729
private static string _childTermUid;
@@ -213,13 +215,17 @@ public void Test011_Should_Localize_Taxonomy()
213215
}
214216
string masterLocale = "en-us";
215217
_testLocaleCode = null;
218+
_asyncTestLocaleCode = null;
216219
foreach (var item in localesArray)
217220
{
218221
var code = item["code"]?.ToString();
219222
if (string.IsNullOrEmpty(code)) continue;
220-
if (!string.Equals(code, masterLocale, StringComparison.OrdinalIgnoreCase))
221-
{
223+
if (string.Equals(code, masterLocale, StringComparison.OrdinalIgnoreCase)) continue;
224+
if (_testLocaleCode == null)
222225
_testLocaleCode = code;
226+
else if (_asyncTestLocaleCode == null)
227+
{
228+
_asyncTestLocaleCode = code;
223229
break;
224230
}
225231
}
@@ -249,6 +255,27 @@ public void Test011_Should_Localize_Taxonomy()
249255
AssertLogger.Inconclusive("Stack has no non-master locale and could not create one; skipping taxonomy localize tests.");
250256
return;
251257
}
258+
if (string.IsNullOrEmpty(_asyncTestLocaleCode))
259+
{
260+
try
261+
{
262+
_asyncTestLocaleCode = "mr-in";
263+
var localeModel = new LocaleModel
264+
{
265+
Code = _asyncTestLocaleCode,
266+
Name = "Marathi (India)"
267+
};
268+
ContentstackResponse createResponse = _stack.Locale().Create(localeModel);
269+
if (createResponse.IsSuccessStatusCode)
270+
_weCreatedAsyncTestLocale = true;
271+
else
272+
_asyncTestLocaleCode = null;
273+
}
274+
catch (ContentstackErrorException)
275+
{
276+
_asyncTestLocaleCode = null;
277+
}
278+
}
252279

253280
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
254281
TestOutputLogger.LogContext("TestLocaleCode", _testLocaleCode ?? "");
@@ -268,6 +295,34 @@ public void Test011_Should_Localize_Taxonomy()
268295
AssertLogger.AreEqual(_testLocaleCode, wrapper.Taxonomy.Locale, "LocalizedLocale");
269296
}
270297

298+
[TestMethod]
299+
[DoNotParallelize]
300+
public async Task Test012_Should_Localize_Taxonomy_Async()
301+
{
302+
TestOutputLogger.LogContext("TestScenario", "Test012_Should_Localize_Taxonomy_Async");
303+
if (string.IsNullOrEmpty(_asyncTestLocaleCode))
304+
{
305+
AssertLogger.Inconclusive("No second non-master locale available; skipping async taxonomy localize test.");
306+
return;
307+
}
308+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
309+
TestOutputLogger.LogContext("AsyncTestLocaleCode", _asyncTestLocaleCode ?? "");
310+
var localizeModel = new TaxonomyModel
311+
{
312+
Uid = _taxonomyUid,
313+
Name = "Taxonomy Localized Async",
314+
Description = "Localized description async"
315+
};
316+
var coll = new ParameterCollection();
317+
coll.Add("locale", _asyncTestLocaleCode);
318+
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).LocalizeAsync(localizeModel, coll);
319+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"LocalizeAsync failed: {response.OpenResponse()}", "LocalizeAsyncSuccess");
320+
var wrapper = response.OpenTResponse<TaxonomyResponseModel>();
321+
AssertLogger.IsNotNull(wrapper?.Taxonomy, "Wrapper taxonomy");
322+
if (!string.IsNullOrEmpty(wrapper.Taxonomy.Locale))
323+
AssertLogger.AreEqual(_asyncTestLocaleCode, wrapper.Taxonomy.Locale, "LocalizedAsyncLocale");
324+
}
325+
271326
[TestMethod]
272327
[DoNotParallelize]
273328
public void Test013_Should_Throw_When_Localize_With_Invalid_Locale()
@@ -565,6 +620,33 @@ public void Test030_Should_Localize_Term()
565620
AssertLogger.IsNotNull(wrapper?.Term, "Term in response");
566621
}
567622

623+
[TestMethod]
624+
[DoNotParallelize]
625+
public async Task Test031_Should_Localize_Term_Async()
626+
{
627+
TestOutputLogger.LogContext("TestScenario", "Test031_Should_Localize_Term_Async");
628+
if (string.IsNullOrEmpty(_asyncTestLocaleCode))
629+
{
630+
AssertLogger.Inconclusive("No second non-master locale available.");
631+
return;
632+
}
633+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
634+
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
635+
TestOutputLogger.LogContext("AsyncTestLocaleCode", _asyncTestLocaleCode ?? "");
636+
var localizeModel = new TermModel
637+
{
638+
Uid = _rootTermUid,
639+
Name = "Root Term Localized Async",
640+
ParentUid = null
641+
};
642+
var coll = new ParameterCollection();
643+
coll.Add("locale", _asyncTestLocaleCode);
644+
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).LocalizeAsync(localizeModel, coll);
645+
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Term LocalizeAsync failed: {response.OpenResponse()}", "TermLocalizeAsyncSuccess");
646+
var wrapper = response.OpenTResponse<TermResponseModel>();
647+
AssertLogger.IsNotNull(wrapper?.Term, "Term in response");
648+
}
649+
568650
[TestMethod]
569651
[DoNotParallelize]
570652
public void Test032_Should_Move_Term()
@@ -576,27 +658,11 @@ public void Test032_Should_Move_Term()
576658
var moveModel = new TermMoveModel
577659
{
578660
ParentUid = _rootTermUid,
579-
Order = 0
661+
Order = 1
580662
};
581-
ContentstackResponse response = null;
582-
try
583-
{
584-
response = _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).Move(moveModel, null);
585-
}
586-
catch (ContentstackErrorException)
587-
{
588-
try
589-
{
590-
var coll = new ParameterCollection();
591-
coll.Add("force", true);
592-
response = _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).Move(moveModel, coll);
593-
}
594-
catch (ContentstackErrorException ex)
595-
{
596-
AssertLogger.Inconclusive(string.Format("Move term failed: {0}", ex.Message));
597-
return;
598-
}
599-
}
663+
var coll = new ParameterCollection();
664+
coll.Add("force", true);
665+
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).Move(moveModel, coll);
600666
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Move term failed: {response.OpenResponse()}", "MoveTermSuccess");
601667
var wrapper = response.OpenTResponse<TermResponseModel>();
602668
AssertLogger.IsNotNull(wrapper?.Term, "Term in response");
@@ -615,25 +681,9 @@ public async Task Test033_Should_Move_Term_Async()
615681
ParentUid = _rootTermUid,
616682
Order = 1
617683
};
618-
ContentstackResponse response = null;
619-
try
620-
{
621-
response = await _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).MoveAsync(moveModel, null);
622-
}
623-
catch (ContentstackErrorException)
624-
{
625-
try
626-
{
627-
var coll = new ParameterCollection();
628-
coll.Add("force", true);
629-
response = await _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).MoveAsync(moveModel, coll);
630-
}
631-
catch (ContentstackErrorException ex)
632-
{
633-
AssertLogger.Inconclusive(string.Format("Move term failed: {0}", ex.Message));
634-
return;
635-
}
636-
}
684+
var coll = new ParameterCollection();
685+
coll.Add("force", true);
686+
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).MoveAsync(moveModel, coll);
637687
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"MoveAsync term failed: {response.OpenResponse()}", "MoveAsyncTermSuccess");
638688
var wrapper = response.OpenTResponse<TermResponseModel>();
639689
AssertLogger.IsNotNull(wrapper?.Term, "Term in response");
@@ -820,6 +870,19 @@ public static void Cleanup()
820870
}
821871
}
822872

873+
if (_weCreatedAsyncTestLocale && !string.IsNullOrEmpty(_asyncTestLocaleCode))
874+
{
875+
try
876+
{
877+
stack.Locale(_asyncTestLocaleCode).Delete();
878+
Console.WriteLine($"[Cleanup] Deleted async test locale: {_asyncTestLocaleCode}");
879+
}
880+
catch (Exception ex)
881+
{
882+
Console.WriteLine($"[Cleanup] Failed to delete async test locale {_asyncTestLocaleCode}: {ex.Message}");
883+
}
884+
}
885+
823886
if (_weCreatedTestLocale && !string.IsNullOrEmpty(_testLocaleCode))
824887
{
825888
try

0 commit comments

Comments
 (0)