-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentstack003_StackTest.cs
More file actions
1195 lines (1080 loc) · 49.3 KB
/
Contentstack003_StackTest.cs
File metadata and controls
1195 lines (1080 loc) · 49.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Tests.Helpers;
using Contentstack.Management.Core.Tests.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Contentstack.Management.Core.Tests.IntegrationTest
{
[TestClass]
public class Contentstack003_StackTest
{
private static ContentstackClient _client;
private readonly string _locale = "en-us";
private string _stackName = "DotNet Management Stack";
private string _updatestackName = "DotNet Management SDK Stack";
private string _description = "Integration testing Stack for DotNet Management SDK";
private OrganizationModel _org = Contentstack.Organization;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
_client = Contentstack.CreateAuthenticatedClient();
}
[ClassCleanup]
public static void ClassCleanup()
{
try { _client?.Logout(); } catch { }
_client = null;
}
[TestMethod]
[DoNotParallelize]
public void Test001_Should_Return_All_Stacks()
{
TestOutputLogger.LogContext("TestScenario", "ReturnAllStacks");
try
{
Stack stack = _client.Stack();
ContentstackResponse contentstackResponse = stack.GetAll();
var response = contentstackResponse.OpenJsonObjectResponse();
AssertLogger.IsNotNull(response, "response");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public async System.Threading.Tasks.Task Test002_Should_Return_All_StacksAsync()
{
TestOutputLogger.LogContext("TestScenario", "ReturnAllStacksAsync");
try
{
Stack stack = _client.Stack();
ContentstackResponse contentstackResponse = await stack.GetAllAsync();
var response = contentstackResponse.OpenJsonObjectResponse();
AssertLogger.IsNotNull(response, "response");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public void Test003_Should_Create_Stack()
{
TestOutputLogger.LogContext("TestScenario", "CreateStack");
try
{
Stack stack = _client.Stack();
ContentstackResponse contentstackResponse = stack.Create(_stackName, _locale, _org.Uid);
var response = contentstackResponse.OpenJsonObjectResponse();
StackResponse model = contentstackResponse.OpenTResponse<StackResponse>();
Contentstack.Stack = model.Stack;
TestOutputLogger.LogContext("StackApiKey", model.Stack.APIKey);
AssertLogger.IsNotNull(response, "response");
AssertLogger.IsNull(model.Stack.Description, "model.Stack.Description");
AssertLogger.AreEqual(_stackName, model.Stack.Name, "StackName");
AssertLogger.AreEqual(_locale, model.Stack.MasterLocale, "MasterLocale");
AssertLogger.AreEqual(_org.Uid, model.Stack.OrgUid, "OrgUid");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public void Test004_Should_Update_Stack()
{
TestOutputLogger.LogContext("TestScenario", "UpdateStack");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = stack.Update(_updatestackName);
var response = contentstackResponse.OpenJsonObjectResponse();
File.WriteAllText("./stackApiKey.txt", contentstackResponse.OpenResponse());
StackResponse model = contentstackResponse.OpenTResponse<StackResponse>();
Contentstack.Stack = model.Stack;
AssertLogger.IsNotNull(response, "response");
AssertLogger.IsNull(model.Stack.Description, "model.Stack.Description");
AssertLogger.AreEqual(Contentstack.Stack.APIKey, model.Stack.APIKey, "APIKey");
AssertLogger.AreEqual(_updatestackName, model.Stack.Name, "StackName");
AssertLogger.AreEqual(_locale, model.Stack.MasterLocale, "MasterLocale");
AssertLogger.AreEqual(_org.Uid, model.Stack.OrgUid, "OrgUid");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public async System.Threading.Tasks.Task Test005_Should_Update_Stack_Async()
{
TestOutputLogger.LogContext("TestScenario", "UpdateStackAsync");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = await stack.UpdateAsync(_updatestackName, _description);
var response = contentstackResponse.OpenJsonObjectResponse();
StackResponse model = contentstackResponse.OpenTResponse<StackResponse>();
Contentstack.Stack = model.Stack;
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual(Contentstack.Stack.APIKey, model.Stack.APIKey, "APIKey");
AssertLogger.AreEqual(_updatestackName, model.Stack.Name, "StackName");
AssertLogger.AreEqual(_locale, model.Stack.MasterLocale, "MasterLocale");
AssertLogger.AreEqual(_description, model.Stack.Description, "Description");
AssertLogger.AreEqual(_org.Uid, model.Stack.OrgUid, "OrgUid");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public void Test006_Should_Fetch_Stack()
{
TestOutputLogger.LogContext("TestScenario", "FetchStack");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = stack.Fetch();
var response = contentstackResponse.OpenJsonObjectResponse();
StackResponse model = contentstackResponse.OpenTResponse<StackResponse>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual(Contentstack.Stack.APIKey, model.Stack.APIKey, "APIKey");
AssertLogger.AreEqual(Contentstack.Stack.Name, model.Stack.Name, "StackName");
AssertLogger.AreEqual(Contentstack.Stack.MasterLocale, model.Stack.MasterLocale, "MasterLocale");
AssertLogger.AreEqual(Contentstack.Stack.Description, model.Stack.Description, "Description");
AssertLogger.AreEqual(Contentstack.Stack.OrgUid, model.Stack.OrgUid, "OrgUid");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public async System.Threading.Tasks.Task Test007_Should_Fetch_StackAsync()
{
TestOutputLogger.LogContext("TestScenario", "FetchStackAsync");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = await stack.FetchAsync();
var response = contentstackResponse.OpenJsonObjectResponse();
StackResponse model = contentstackResponse.OpenTResponse<StackResponse>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual(Contentstack.Stack.APIKey, model.Stack.APIKey, "APIKey");
AssertLogger.AreEqual(Contentstack.Stack.Name, model.Stack.Name, "StackName");
AssertLogger.AreEqual(Contentstack.Stack.MasterLocale, model.Stack.MasterLocale, "MasterLocale");
AssertLogger.AreEqual(Contentstack.Stack.Description, model.Stack.Description, "Description");
AssertLogger.AreEqual(Contentstack.Stack.OrgUid, model.Stack.OrgUid, "OrgUid");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public void Test008_Add_Stack_Settings()
{
TestOutputLogger.LogContext("TestScenario", "AddStackSettings");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
StackSettings settings = new StackSettings()
{
StackVariables = new Dictionary<string, object>()
{
{ "enforce_unique_urls", true },
{ "sys_rte_allowed_tags", "figure" }
}
};
ContentstackResponse contentstackResponse = stack.AddSettings(settings);
var response = contentstackResponse.OpenJsonObjectResponse();
StackSettingsModel model = contentstackResponse.OpenTResponse<StackSettingsModel>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual("Stack settings updated successfully.", model.Notice, "Notice");
AssertLogger.AreEqual(true, model.StackSettings.StackVariables["enforce_unique_urls"], "enforce_unique_urls");
AssertLogger.AreEqual("figure", model.StackSettings.StackVariables["sys_rte_allowed_tags"], "sys_rte_allowed_tags");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public void Test009_Stack_Settings()
{
TestOutputLogger.LogContext("TestScenario", "StackSettings");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = stack.Settings();
var response = contentstackResponse.OpenJsonObjectResponse();
StackSettingsModel model = contentstackResponse.OpenTResponse<StackSettingsModel>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.IsNull(model.Notice, "model.Notice");
AssertLogger.AreEqual(true, model.StackSettings.StackVariables["enforce_unique_urls"], "enforce_unique_urls");
AssertLogger.AreEqual("figure", model.StackSettings.StackVariables["sys_rte_allowed_tags"], "sys_rte_allowed_tags");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public void Test010_Reset_Stack_Settings()
{
TestOutputLogger.LogContext("TestScenario", "ResetStackSettings");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = stack.ResetSettings();
var response = contentstackResponse.OpenJsonObjectResponse();
StackSettingsModel model = contentstackResponse.OpenTResponse<StackSettingsModel>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual("Stack settings updated successfully.", model.Notice, "Notice");
AssertLogger.AreEqual(true, model.StackSettings.StackVariables["enforce_unique_urls"], "enforce_unique_urls");
AssertLogger.AreEqual("figure", model.StackSettings.StackVariables["sys_rte_allowed_tags"], "sys_rte_allowed_tags");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public async System.Threading.Tasks.Task Test011_Add_Stack_Settings_Async()
{
TestOutputLogger.LogContext("TestScenario", "AddStackSettingsAsync");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
StackSettings settings = new StackSettings()
{
Rte = new Dictionary<string, object>()
{
{ "cs_only_breakline", true },
}
};
ContentstackResponse contentstackResponse = await stack.AddSettingsAsync(settings);
var response = contentstackResponse.OpenJsonObjectResponse();
StackSettingsModel model = contentstackResponse.OpenTResponse<StackSettingsModel>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual("Stack settings updated successfully.", model.Notice, "Notice");
AssertLogger.AreEqual(true, model.StackSettings.Rte["cs_only_breakline"], "cs_only_breakline");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public async System.Threading.Tasks.Task Test012_Reset_Stack_Settings_Async()
{
TestOutputLogger.LogContext("TestScenario", "ResetStackSettingsAsync");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = await stack.ResetSettingsAsync();
var response = contentstackResponse.OpenJsonObjectResponse();
StackSettingsModel model = contentstackResponse.OpenTResponse<StackSettingsModel>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual("Stack settings updated successfully.", model.Notice, "Notice");
AssertLogger.AreEqual(true, model.StackSettings.StackVariables["enforce_unique_urls"], "enforce_unique_urls");
AssertLogger.AreEqual("figure", model.StackSettings.StackVariables["sys_rte_allowed_tags"], "sys_rte_allowed_tags");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
[TestMethod]
[DoNotParallelize]
public async System.Threading.Tasks.Task Test013_Stack_Settings_Async()
{
TestOutputLogger.LogContext("TestScenario", "StackSettingsAsync");
TestOutputLogger.LogContext("StackApiKey", Contentstack.Stack.APIKey);
try
{
Stack stack = _client.Stack(Contentstack.Stack.APIKey);
ContentstackResponse contentstackResponse = await stack.SettingsAsync();
var response = contentstackResponse.OpenJsonObjectResponse();
StackSettingsModel model = contentstackResponse.OpenTResponse<StackSettingsModel>();
AssertLogger.IsNotNull(response, "response");
AssertLogger.AreEqual(true, model.StackSettings.StackVariables["enforce_unique_urls"], "enforce_unique_urls");
AssertLogger.AreEqual("figure", model.StackSettings.StackVariables["sys_rte_allowed_tags"], "sys_rte_allowed_tags");
}
catch (Exception e)
{
AssertLogger.Fail(e.Message);
}
}
#region Negative and error-handling tests (Test014+)
/// <summary>Non-empty API key used only to exercise SDK preconditions without requiring Test003 to succeed.</summary>
private const string SdkNonEmptyApiKey = "bltSdkValidationNonEmptyApiKey00";
private const string InvalidStackApiKey = "bltNonExistentStackKey12345";
private static void AssertStackApiKeyOrInconclusive()
{
if (string.IsNullOrEmpty(Contentstack.Stack?.APIKey))
{
Assert.Inconclusive(
"Contentstack.Stack.APIKey is not set (Test003 create stack did not run or failed). Skipping test that requires a real stack.");
}
}
[TestMethod]
[DoNotParallelize]
public void Test014_Should_Fail_When_Not_Logged_In_Stack_GetAll()
{
TestOutputLogger.LogContext("TestScenario", "Stack_NotLoggedIn_GetAll");
var unauthenticatedClient = new ContentstackClient(new ContentstackClientOptions
{
Host = "api.contentstack.io"
});
var ex = Assert.ThrowsException<InvalidOperationException>(() =>
unauthenticatedClient.Stack().GetAll());
AssertLogger.IsTrue(
ex.Message.IndexOf("not logged in", StringComparison.OrdinalIgnoreCase) >= 0,
"Expected not-logged-in message",
"Stack_NotLoggedIn_Message");
}
[TestMethod]
[DoNotParallelize]
public void Test015_Should_Fail_With_Invalid_Auth_Token_Stack_GetAll()
{
TestOutputLogger.LogContext("TestScenario", "Stack_InvalidAuthToken_GetAll");
try
{
var invalidClient = new ContentstackClient(new ContentstackClientOptions
{
Host = "api.contentstack.io",
Authtoken = "invalid_auth_token_123"
});
invalidClient.Stack().GetAll();
AssertLogger.Fail("Expected exception for invalid auth token", "Stack_InvalidAuth_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackAuthError(ex, "Stack_InvalidAuthToken");
}
}
[TestMethod]
[DoNotParallelize]
public void Test016_Should_Throw_When_GetAll_With_Stack_Api_Key_Set()
{
TestOutputLogger.LogContext("TestScenario", "Stack_GetAll_InvalidApiKeyContext");
Assert.ThrowsException<InvalidOperationException>(() =>
_client.Stack(SdkNonEmptyApiKey).GetAll());
}
[TestMethod]
[DoNotParallelize]
public async Task Test017_Should_Throw_When_GetAllAsync_With_Stack_Api_Key_Set()
{
TestOutputLogger.LogContext("TestScenario", "Stack_GetAllAsync_InvalidApiKeyContext");
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() =>
_client.Stack(SdkNonEmptyApiKey).GetAllAsync());
}
[TestMethod]
[DoNotParallelize]
public void Test018_Should_Throw_When_Create_With_Stack_Api_Key_Set()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_InvalidApiKeyContext");
Assert.ThrowsException<InvalidOperationException>(() =>
_client.Stack(SdkNonEmptyApiKey).Create(_stackName, _locale, _org.Uid));
}
[TestMethod]
[DoNotParallelize]
public async Task Test019_Should_Throw_When_CreateAsync_With_Stack_Api_Key_Set()
{
TestOutputLogger.LogContext("TestScenario", "Stack_CreateAsync_InvalidApiKeyContext");
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() =>
_client.Stack(SdkNonEmptyApiKey).CreateAsync(_stackName, _locale, _org.Uid));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public void Test020_Should_Throw_When_Create_With_Invalid_Name_Sync(string invalidName)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_InvalidName_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack().Create(invalidName, _locale, _org.Uid));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public async Task Test021_Should_Throw_When_CreateAsync_With_Invalid_Name(string invalidName)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_InvalidName_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack().CreateAsync(invalidName, _locale, _org.Uid));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public void Test020b_Should_Throw_When_Create_With_Invalid_Locale_Sync(string invalidLocale)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_InvalidLocale_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack().Create(_stackName, invalidLocale, _org.Uid));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public async Task Test021b_Should_Throw_When_CreateAsync_With_Invalid_Locale(string invalidLocale)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_InvalidLocale_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack().CreateAsync(_stackName, invalidLocale, _org.Uid));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public void Test020c_Should_Throw_When_Create_With_Invalid_OrgUid_Sync(string invalidOrg)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_InvalidOrg_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack().Create(_stackName, _locale, invalidOrg));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public async Task Test021c_Should_Throw_When_CreateAsync_With_Invalid_OrgUid(string invalidOrg)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_InvalidOrg_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack().CreateAsync(_stackName, _locale, invalidOrg));
}
[TestMethod]
[DoNotParallelize]
public void Test022_Should_Throw_When_Fetch_Without_Api_Key_Sync()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Fetch_MissingApiKey_Sync");
Assert.ThrowsException<InvalidOperationException>(() => _client.Stack().Fetch());
}
[TestMethod]
[DoNotParallelize]
public async Task Test023_Should_Throw_When_FetchAsync_Without_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Fetch_MissingApiKey_Async");
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() => _client.Stack().FetchAsync());
}
[TestMethod]
[DoNotParallelize]
public void Test024_Should_Throw_When_Update_Without_Api_Key_Sync()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Update_MissingApiKey_Sync");
Assert.ThrowsException<InvalidOperationException>(() =>
_client.Stack().Update(_updatestackName));
}
[TestMethod]
[DoNotParallelize]
public async Task Test025_Should_Throw_When_UpdateAsync_Without_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Update_MissingApiKey_Async");
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() =>
_client.Stack().UpdateAsync(_updatestackName));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public void Test026_Should_Throw_When_Update_With_Invalid_Name_Sync(string invalidName)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Update_InvalidName_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).Update(invalidName));
}
[TestMethod]
[DoNotParallelize]
[DataRow(null)]
[DataRow("")]
public async Task Test027_Should_Throw_When_UpdateAsync_With_Invalid_Name(string invalidName)
{
TestOutputLogger.LogContext("TestScenario", "Stack_Update_InvalidName_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).UpdateAsync(invalidName));
}
[TestMethod]
[DoNotParallelize]
public void Test028_Should_Throw_When_Settings_Without_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Settings_MissingApiKey_Sync");
Assert.ThrowsException<InvalidOperationException>(() => _client.Stack().Settings());
}
[TestMethod]
[DoNotParallelize]
public async Task Test029_Should_Throw_When_SettingsAsync_Without_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Settings_MissingApiKey_Async");
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() => _client.Stack().SettingsAsync());
}
[TestMethod]
[DoNotParallelize]
public void Test030_Should_Throw_When_ResetSettings_Without_Api_Key_Sync()
{
TestOutputLogger.LogContext("TestScenario", "Stack_ResetSettings_MissingApiKey_Sync");
Assert.ThrowsException<InvalidOperationException>(() => _client.Stack().ResetSettings());
}
[TestMethod]
[DoNotParallelize]
public async Task Test031_Should_Throw_When_ResetSettingsAsync_Without_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_ResetSettings_MissingApiKey_Async");
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() => _client.Stack().ResetSettingsAsync());
}
[TestMethod]
[DoNotParallelize]
public void Test032_Should_Throw_When_AddSettings_Null_Sync()
{
TestOutputLogger.LogContext("TestScenario", "Stack_AddSettings_Null_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).AddSettings(null));
}
[TestMethod]
[DoNotParallelize]
public async Task Test033_Should_Throw_When_AddSettingsAsync_Null()
{
TestOutputLogger.LogContext("TestScenario", "Stack_AddSettings_Null_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).AddSettingsAsync(null));
}
[TestMethod]
[DoNotParallelize]
public void Test034_Should_Fail_Fetch_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Fetch_InvalidApiKey");
try
{
_client.Stack(InvalidStackApiKey).Fetch();
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_Fetch_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_Fetch_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public async Task Test035_Should_Fail_FetchAsync_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_FetchAsync_InvalidApiKey");
try
{
await _client.Stack(InvalidStackApiKey).FetchAsync();
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_FetchAsync_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_FetchAsync_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public void Test036_Should_Fail_Update_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Update_InvalidApiKey");
try
{
_client.Stack(InvalidStackApiKey).Update("SomeName");
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_Update_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_Update_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public async Task Test037_Should_Fail_UpdateAsync_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UpdateAsync_InvalidApiKey");
try
{
await _client.Stack(InvalidStackApiKey).UpdateAsync("SomeName");
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_UpdateAsync_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_UpdateAsync_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public void Test038_Should_Fail_Settings_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Settings_InvalidApiKey");
try
{
_client.Stack(InvalidStackApiKey).Settings();
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_Settings_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_Settings_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public async Task Test039_Should_Fail_SettingsAsync_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_SettingsAsync_InvalidApiKey");
try
{
await _client.Stack(InvalidStackApiKey).SettingsAsync();
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_SettingsAsync_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_SettingsAsync_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public void Test040_Should_Fail_ResetSettings_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_ResetSettings_InvalidApiKey");
try
{
_client.Stack(InvalidStackApiKey).ResetSettings();
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_Reset_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_Reset_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public async Task Test041_Should_Fail_ResetSettingsAsync_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_ResetSettingsAsync_InvalidApiKey");
try
{
await _client.Stack(InvalidStackApiKey).ResetSettingsAsync();
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_ResetAsync_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_ResetAsync_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public void Test042_Should_Fail_AddSettings_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_AddSettings_InvalidApiKey");
var settings = new StackSettings
{
StackVariables = new Dictionary<string, object> { { "enforce_unique_urls", true } }
};
try
{
_client.Stack(InvalidStackApiKey).AddSettings(settings);
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_AddSettings_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_AddSettings_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public async Task Test043_Should_Fail_AddSettingsAsync_With_Invalid_Stack_Api_Key()
{
TestOutputLogger.LogContext("TestScenario", "Stack_AddSettingsAsync_InvalidApiKey");
var settings = new StackSettings
{
StackVariables = new Dictionary<string, object> { { "enforce_unique_urls", true } }
};
try
{
await _client.Stack(InvalidStackApiKey).AddSettingsAsync(settings);
AssertLogger.Fail("Expected API error for invalid stack key", "Stack_AddSettingsAsync_InvalidKey_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_AddSettingsAsync_InvalidKey");
}
}
[TestMethod]
[DoNotParallelize]
public void Test044_Should_Fail_Create_With_Bogus_Organization_Uid()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Create_BogusOrgUid");
try
{
_client.Stack().Create(_stackName, _locale, "blt_bogus_organization_uid_99999");
AssertLogger.Fail("Expected API error for bogus organization", "Stack_Create_BogusOrg_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_Create_BogusOrg");
}
}
[TestMethod]
[DoNotParallelize]
public void Test045_Should_Throw_When_Share_Invitations_Null_Sync()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Share_NullInvitations_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).Share(null));
}
[TestMethod]
[DoNotParallelize]
public async Task Test046_Should_Throw_When_ShareAsync_Invitations_Null()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Share_NullInvitations_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).ShareAsync(null));
}
[TestMethod]
[DoNotParallelize]
public void Test047_Should_Throw_When_UnShare_Email_Null_Sync()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UnShare_NullEmail_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).UnShare(null));
}
[TestMethod]
[DoNotParallelize]
public async Task Test048_Should_Throw_When_UnShareAsync_Email_Null()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UnShare_NullEmail_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).UnShareAsync(null));
}
[TestMethod]
[DoNotParallelize]
public void Test049_Should_Fail_Share_With_Invalid_Email()
{
TestOutputLogger.LogContext("TestScenario", "Stack_Share_InvalidEmail");
AssertStackApiKeyOrInconclusive();
var invitations = new List<UserInvitation>
{
new UserInvitation
{
Email = "not-an-email",
Roles = new List<string> { "blt_fake_role_uid" }
}
};
try
{
_client.Stack(Contentstack.Stack.APIKey).Share(invitations);
AssertLogger.Fail("Expected API error for invalid share invitation", "Stack_Share_InvalidEmail_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_Share_InvalidEmail");
}
}
[TestMethod]
[DoNotParallelize]
public async Task Test050_Should_Fail_ShareAsync_With_Invalid_Role_Uid()
{
TestOutputLogger.LogContext("TestScenario", "Stack_ShareAsync_InvalidRoleUid");
AssertStackApiKeyOrInconclusive();
var invitations = new List<UserInvitation>
{
new UserInvitation
{
Email = "validformat+stackneg@test.invalid",
Roles = new List<string> { "blt_nonexistent_role_uid_12345" }
}
};
try
{
await _client.Stack(Contentstack.Stack.APIKey).ShareAsync(invitations);
AssertLogger.Fail("Expected API error for invalid role UID", "Stack_ShareAsync_InvalidRole_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_ShareAsync_InvalidRole");
}
}
[TestMethod]
[DoNotParallelize]
public void Test051_Should_Fail_UnShare_Non_Collaborator_Email()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UnShare_UnknownEmail");
AssertStackApiKeyOrInconclusive();
try
{
_client.Stack(Contentstack.Stack.APIKey).UnShare("noncollaborator_stack_neg@test.invalid");
AssertLogger.Fail("Expected API error for unknown collaborator", "Stack_UnShare_Unknown_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_UnShare_UnknownEmail");
}
}
[TestMethod]
[DoNotParallelize]
public async Task Test052_Should_Fail_UnShareAsync_Malformed_Email()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UnShareAsync_MalformedEmail");
AssertStackApiKeyOrInconclusive();
try
{
await _client.Stack(Contentstack.Stack.APIKey).UnShareAsync("not-an-email-address");
AssertLogger.Fail("Expected API error for malformed email", "Stack_UnShare_Malformed_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_UnShare_MalformedEmail");
}
}
[TestMethod]
[DoNotParallelize]
public void Test053_Should_Throw_When_UpdateUserRole_Null_List_Sync()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UpdateUserRole_Null_Sync");
Assert.ThrowsException<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).UpdateUserRole(null));
}
[TestMethod]
[DoNotParallelize]
public async Task Test054_Should_Throw_When_UpdateUserRoleAsync_Null_List()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UpdateUserRole_Null_Async");
await Assert.ThrowsExceptionAsync<ArgumentNullException>(() =>
_client.Stack(SdkNonEmptyApiKey).UpdateUserRoleAsync(null));
}
[TestMethod]
[DoNotParallelize]
public void Test055_Should_Fail_UpdateUserRole_Empty_List_API()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UpdateUserRole_EmptyList");
try
{
_client.Stack(SdkNonEmptyApiKey).UpdateUserRole(new List<UserInvitation>());
AssertLogger.Fail("Expected API error for empty user role list", "Stack_UpdateUserRole_Empty_NoException");
}
catch (ContentstackErrorException ex)
{
AssertStackValidationError(ex, "Stack_UpdateUserRole_Empty");
}
catch (ArgumentException)
{
AssertLogger.IsTrue(true, "SDK or API rejected empty list", "Stack_UpdateUserRole_Empty_Argument");
}
}
[TestMethod]
[DoNotParallelize]
public void Test056_Should_Fail_UpdateUserRole_Invalid_User_Uid_API()
{
TestOutputLogger.LogContext("TestScenario", "Stack_UpdateUserRole_InvalidUserUid");
var list = new List<UserInvitation>
{
new UserInvitation
{