@@ -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