-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathConfigureOptionsTests.cs
More file actions
1565 lines (1372 loc) · 78.3 KB
/
ConfigureOptionsTests.cs
File metadata and controls
1565 lines (1372 loc) · 78.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Serilog;
namespace Cli.Tests
{
/// <summary>
/// Validates that `dab configure [options]` configures settings with the user-provided options.
/// </summary>
[TestClass]
public class ConfigureOptionsTests : VerifyBase
{
private MockFileSystem? _fileSystem;
private FileSystemRuntimeConfigLoader? _runtimeConfigLoader;
private const string TEST_RUNTIME_CONFIG_FILE = "test-update-runtime-setting.json";
private const string TEST_DATASOURCE_HEALTH_NAME = "My Data Source";
[TestInitialize]
public void TestInitialize()
{
_fileSystem = FileSystemUtils.ProvisionMockFileSystem();
_runtimeConfigLoader = new FileSystemRuntimeConfigLoader(_fileSystem);
ILoggerFactory loggerFactory = TestLoggerSupport.ProvisionLoggerFactory();
SetLoggerForCliConfigGenerator(loggerFactory.CreateLogger<ConfigGenerator>());
SetCliUtilsLogger(loggerFactory.CreateLogger<Utils>());
}
/// <summary>
/// Validates that if depth-limit is not provided in `dab configure` options, then The config file must not change.
/// Example: if depth-limit is not provided in the config, it should not be added.
/// if { "depth-limit" : null } is provided in the config, it should not be removed.
/// Also, if { "depth-limit" : -1 } is provided in the config, it should not be removed.
/// </summary>
[DataTestMethod]
[DataRow(null, false, DisplayName = "Config: 'depth-limit' property not defined, should not be added.")]
[DataRow(null, true, DisplayName = "Config: 'depth-limit' is null. It should not be removed.")]
[DataRow(-1, true, DisplayName = "Config: 'depth-limit' is -1, should remain as is without change.")]
public void TestNoUpdateOnGraphQLDepthLimitInRuntimeSettings(object? depthLimit, bool isDepthLimitProvidedInConfig)
{
string depthLimitSection = "";
if (isDepthLimitProvidedInConfig)
{
if (depthLimit == null)
{
depthLimitSection = $@"""depth-limit"": null";
}
else
{
depthLimitSection = $@"""depth-limit"": {depthLimit}";
}
}
string initialConfig = TestHelper.GenerateConfigWithGivenDepthLimit(depthLimitSection);
// Arrange
_fileSystem!.AddFile(TEST_RUNTIME_CONFIG_FILE, initialConfig);
Assert.IsTrue(_fileSystem!.File.Exists(TEST_RUNTIME_CONFIG_FILE));
// Act: Run Configure with no options
ConfigureOptions options = new(
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsTrue(isSuccess);
// Assert that INITIAL_CONFIG is same as the updated config
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
if (isDepthLimitProvidedInConfig)
{
Assert.IsTrue(updatedConfig.Contains(depthLimitSection));
}
else
{
Assert.IsTrue(!updatedConfig.Contains("depth-limit"));
}
// Assert that INITIAL_CONFIG is same as the updated config
Assert.IsTrue(JToken.DeepEquals(JObject.Parse(initialConfig), JObject.Parse(updatedConfig)));
}
/// <summary>
/// Tests that running "dab configure --runtime.graphql.depth-limit 8" on a config with no depth-limit previously specified, results
/// in runtime.graphql.depthlimit property being set with the value 8.
[TestMethod]
public void TestAddDepthLimitForGraphQL()
{
// Arrange
_fileSystem!.AddFile(TEST_RUNTIME_CONFIG_FILE, new MockFileData(INITIAL_CONFIG));
int maxDepthLimit = 8;
Assert.IsTrue(_fileSystem!.File.Exists(TEST_RUNTIME_CONFIG_FILE));
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? config));
Assert.IsNull(config.Runtime!.GraphQL!.DepthLimit);
// Act: Attmepts to Add Depth Limit
ConfigureOptions options = new(
depthLimit: maxDepthLimit,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Depth Limit is added
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out config));
Assert.IsNotNull(config.Runtime?.GraphQL?.DepthLimit);
Assert.AreEqual(maxDepthLimit, config.Runtime.GraphQL.DepthLimit);
}
/// <summary>
/// Tests that running the "configure --azure-key-vault" commands on a config without AKV properties results
/// in a valid config being generated.
[TestMethod]
public void TestAddAKVOptions()
{
// Arrange
_fileSystem!.AddFile(TEST_RUNTIME_CONFIG_FILE, new MockFileData(INITIAL_CONFIG));
Assert.IsTrue(_fileSystem!.File.Exists(TEST_RUNTIME_CONFIG_FILE));
// Act: Attempts to add AKV options
ConfigureOptions options = new(
azureKeyVaultEndpoint: "foo",
azureKeyVaultRetryPolicyMaxCount: 1,
azureKeyVaultRetryPolicyDelaySeconds: 1,
azureKeyVaultRetryPolicyMaxDelaySeconds: 1,
azureKeyVaultRetryPolicyMode: AKVRetryPolicyMode.Exponential,
azureKeyVaultRetryPolicyNetworkTimeoutSeconds: 1,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the AKV options are added.
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? config));
Assert.IsNotNull(config.AzureKeyVault);
Assert.IsNotNull(config.AzureKeyVault?.RetryPolicy);
Assert.AreEqual("foo", config.AzureKeyVault?.Endpoint);
Assert.AreEqual(AKVRetryPolicyMode.Exponential, config.AzureKeyVault?.RetryPolicy.Mode);
Assert.AreEqual(1, config.AzureKeyVault?.RetryPolicy.MaxCount);
Assert.AreEqual(1, config.AzureKeyVault?.RetryPolicy.DelaySeconds);
Assert.AreEqual(1, config.AzureKeyVault?.RetryPolicy.MaxDelaySeconds);
Assert.AreEqual(1, config.AzureKeyVault?.RetryPolicy.NetworkTimeoutSeconds);
}
/// <summary>
/// Tests that running the "configure --azure-log-analytics" commands on a config without Azure Log Analytics properties results
/// in a valid config being generated.
[TestMethod]
public void TestAddAzureLogAnalyticsOptions()
{
// Arrange
_fileSystem!.AddFile(TEST_RUNTIME_CONFIG_FILE, new MockFileData(INITIAL_CONFIG));
Assert.IsTrue(_fileSystem!.File.Exists(TEST_RUNTIME_CONFIG_FILE));
// Act: Attempts to add Azure Log Analytics options
ConfigureOptions options = new(
azureLogAnalyticsEnabled: CliBool.True,
azureLogAnalyticsDabIdentifier: "dab-identifier-test",
azureLogAnalyticsFlushIntervalSeconds: 1,
azureLogAnalyticsCustomTableName: "custom-table-name-test",
azureLogAnalyticsDcrImmutableId: "dcr-immutable-id-test",
azureLogAnalyticsDceEndpoint: "dce-endpoint-test",
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Azure Log Analytics options are added.
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? config));
Assert.IsNotNull(config.Runtime);
Assert.IsNotNull(config.Runtime.Telemetry);
Assert.IsNotNull(config.Runtime.Telemetry.AzureLogAnalytics);
Assert.AreEqual(true, config.Runtime.Telemetry.AzureLogAnalytics.Enabled);
Assert.AreEqual("dab-identifier-test", config.Runtime.Telemetry.AzureLogAnalytics.DabIdentifier);
Assert.AreEqual(1, config.Runtime.Telemetry.AzureLogAnalytics.FlushIntervalSeconds);
Assert.IsNotNull(config.Runtime.Telemetry.AzureLogAnalytics.Auth);
Assert.AreEqual("custom-table-name-test", config.Runtime.Telemetry.AzureLogAnalytics.Auth.CustomTableName);
Assert.AreEqual("dcr-immutable-id-test", config.Runtime.Telemetry.AzureLogAnalytics.Auth.DcrImmutableId);
Assert.AreEqual("dce-endpoint-test", config.Runtime.Telemetry.AzureLogAnalytics.Auth.DceEndpoint);
}
/// <summary>
/// Tests that running the "configure --file" commands on a config without file sink properties results
/// in a valid config being generated.
/// </summary>
[TestMethod]
public void TestAddFileSinkOptions()
{
// Arrange
string fileSinkPath = "/custom/log/path.txt";
RollingInterval fileSinkRollingInterval = RollingInterval.Hour;
int fileSinkRetainedFileCountLimit = 5;
int fileSinkFileSizeLimitBytes = 2097152;
_fileSystem!.AddFile(TEST_RUNTIME_CONFIG_FILE, new MockFileData(INITIAL_CONFIG));
Assert.IsTrue(_fileSystem!.File.Exists(TEST_RUNTIME_CONFIG_FILE));
// Act: Attempts to add file options
ConfigureOptions options = new(
fileSinkEnabled: CliBool.True,
fileSinkPath: fileSinkPath,
fileSinkRollingInterval: fileSinkRollingInterval,
fileSinkRetainedFileCountLimit: fileSinkRetainedFileCountLimit,
fileSinkFileSizeLimitBytes: fileSinkFileSizeLimitBytes,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the file options are added.
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? config));
Assert.IsNotNull(config.Runtime);
Assert.IsNotNull(config.Runtime.Telemetry);
Assert.IsNotNull(config.Runtime.Telemetry.File);
Assert.AreEqual(true, config.Runtime.Telemetry.File.Enabled);
Assert.AreEqual(fileSinkPath, config.Runtime.Telemetry.File.Path);
Assert.AreEqual(fileSinkRollingInterval.ToString(), config.Runtime.Telemetry.File.RollingInterval);
Assert.AreEqual(fileSinkRetainedFileCountLimit, config.Runtime.Telemetry.File.RetainedFileCountLimit);
Assert.AreEqual(fileSinkFileSizeLimitBytes, config.Runtime.Telemetry.File.FileSizeLimitBytes);
}
/// <summary>
/// Tests that running "dab configure --runtime.graphql.enabled" on a config with various values results
/// in runtime. Takes in updated value for graphql.enabled and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(false, DisplayName = "Update GraphQL.Enabled to false.")]
[DataRow(true, DisplayName = "Validate GraphQL.Enabled to remain true.")]
public void TestUpdateEnabledForGraphQLSettings(bool updatedEnabledValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update enabled flag
ConfigureOptions options = new(
runtimeGraphQLEnabled: updatedEnabledValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Enabled Flag is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.GraphQL?.Enabled);
Assert.AreEqual(updatedEnabledValue, runtimeConfig.Runtime.GraphQL.Enabled);
}
/// <summary>
/// Tests that running "dab configure --runtime.graphql.path" on a config with various values results
/// in runtime config update. Takes in updated value for graphql.path and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow("/updatedPath", DisplayName = "Update path to /updatedPath for GraphQL.")]
[DataRow("/updated_Path", DisplayName = "Ensure underscore is allowed in GraphQL path name.")]
[DataRow("/updated-Path", DisplayName = "Ensure hyphen is allowed in GraphQL path name.")]
public void TestUpdatePathForGraphQLSettings(string updatedPathValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update path value
ConfigureOptions options = new(
runtimeGraphQLPath: updatedPathValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Path update is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.GraphQL?.Path);
Assert.AreEqual(updatedPathValue, runtimeConfig.Runtime.GraphQL.Path);
}
/// <summary>
/// Tests that running "dab configure --runtime.graphql.allow-introspection" on a
/// config with various values results in runtime config update.
/// Takes in updated value for graphql.allow-introspection and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(false, DisplayName = "Update GraphQL.AllowIntrospection to be false.")]
[DataRow(true, DisplayName = "Validate GraphQL.AllowIntrospection to remain true.")]
public void TestUpdateAllowIntrospectionForGraphQLSettings(bool updatedAllowIntrospectionValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update allow-introspection flag
ConfigureOptions options = new(
runtimeGraphQLAllowIntrospection: updatedAllowIntrospectionValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Allow-Introspection value is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.GraphQL?.AllowIntrospection);
Assert.AreEqual(updatedAllowIntrospectionValue, runtimeConfig.Runtime.GraphQL.AllowIntrospection);
}
/// <summary>
/// Tests that running "dab configure --runtime.graphql.multiple-mutations.create.enabled"
/// on a config with various values results in runtime config update.
/// Takes in updated value for multiple mutations.create.enabled and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(false, DisplayName = "Update GraphQL.MultipleMutation.Create.Enabled to be false.")]
[DataRow(true, DisplayName = "Validate GraphQL.MultipleMutation.Create.Enabled to remain true.")]
public void TestUpdateMultipleMutationCreateEnabledForGraphQLSettings(bool updatedMultipleMutationsCreateEnabledValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update multiple-mutations.create.enabled flag
ConfigureOptions options = new(
runtimeGraphQLMultipleMutationsCreateEnabled: updatedMultipleMutationsCreateEnabledValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Multiple-Mutation.Create.Enabled is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.GraphQL?.MultipleMutationOptions?.MultipleCreateOptions?.Enabled);
Assert.AreEqual(updatedMultipleMutationsCreateEnabledValue, runtimeConfig.Runtime.GraphQL.MultipleMutationOptions.MultipleCreateOptions.Enabled);
}
/// <summary>
/// Tests that running "dab configure --runtime.graphql.path" on a config with various values results
/// in runtime config update. Takes in updatedPath and updated value for allow-introspection and
/// validates whether the runtime config reflects those updated values
[TestMethod]
public void TestUpdateMultipleParametersForGraphQLSettings()
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
bool updatedAllowIntrospectionValue = false;
string updatedPathValue = "/updatedPath";
// Act: Attempts to update the path value and allow-introspection flag
ConfigureOptions options = new(
runtimeGraphQLPath: updatedPathValue,
runtimeGraphQLAllowIntrospection: updatedAllowIntrospectionValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the path is updated and allow introspection is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.GraphQL?.Path);
Assert.IsNotNull(runtimeConfig.Runtime?.GraphQL?.AllowIntrospection);
Assert.AreEqual(updatedPathValue, runtimeConfig.Runtime.GraphQL.Path);
Assert.AreEqual(updatedAllowIntrospectionValue, runtimeConfig.Runtime.GraphQL.AllowIntrospection);
}
/// <summary>
/// Tests that running "dab configure --runtime.rest.enabled {value}" on a config with various values results
/// in runtime config update. Takes in updated value for rest.enabled and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(false, DisplayName = "Update Rest.Enabled to false.")]
[DataRow(true, DisplayName = "Validate if Rest.Enabled remains true.")]
public void TestUpdateEnabledForRestSettings(bool updatedEnabledValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update enabled flag
ConfigureOptions options = new(
runtimeRestEnabled: updatedEnabledValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Enabled Flag is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Rest?.Enabled);
Assert.AreEqual(updatedEnabledValue, runtimeConfig.Runtime.Rest.Enabled);
}
/// <summary>
/// Tests that running "dab configure --runtime.rest.path {value}" on a config with various values results
/// in runtime config update. Takes in updated value for rest.path and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow("/updatedPath", DisplayName = "Update REST path to /updatedPath.")]
[DataRow("/updated_Path", DisplayName = "Ensure underscore is allowed in REST path.")]
[DataRow("/updated-Path", DisplayName = "Ensure hyphen is allowed in REST path.")]
public void TestUpdatePathForRestSettings(string updatedPathValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update path value
ConfigureOptions options = new(
runtimeRestPath: updatedPathValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Path update is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Rest?.Path);
Assert.AreEqual(updatedPathValue, runtimeConfig.Runtime.Rest.Path);
}
/// <summary>
/// Tests that running "dab configure --runtime.rest.request-body-strict" on a config with various values results
/// in runtime config update. Takes in updated value for rest.request-body-strict and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(false, DisplayName = "Update Rest.Request-Body-Strict to false.")]
[DataRow(true, DisplayName = "Validate if Rest.Request-body-Strict remains true.")]
public void TestUpdateRequestBodyStrictForRestSettings(bool updatedRequestBodyStrictValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update request-body-strict value
ConfigureOptions options = new(
runtimeRestRequestBodyStrict: updatedRequestBodyStrictValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the RequestBodyStrict Value is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Rest?.RequestBodyStrict);
Assert.AreEqual(updatedRequestBodyStrictValue, runtimeConfig.Runtime.Rest.RequestBodyStrict);
}
/// <summary>
/// Tests that running "dab configure --runtime.rest.enabled {value} --runtime.rest.path {value}"
/// on a config with various values results in runtime config update.
/// Takes in updated value for enabled and path and further
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(false, "/updatedPath", DisplayName = "Update enabled flag and path in Rest runtime settings.")]
public void TestUpdateMultipleParametersRestSettings(bool updatedEnabledValue, string updatedPathValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update the path value and enabled flag
ConfigureOptions options = new(
runtimeRestPath: updatedPathValue,
runtimeRestEnabled: updatedEnabledValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the path is updated and enabled is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Rest?.Path);
Assert.IsNotNull(runtimeConfig.Runtime?.Rest?.Enabled);
Assert.AreEqual(updatedPathValue, runtimeConfig.Runtime.Rest.Path);
Assert.AreEqual(updatedEnabledValue, runtimeConfig.Runtime.Rest.Enabled);
}
/// <summary>
/// Validates that running "dab configure --runtime.cache.enabled" on a config with various values results
/// in runtime config update. Takes in updated value for cache.enabled and
/// validates whether the runtime config reflects those updated values.
[DataTestMethod]
[DataRow(false, DisplayName = "Update Cache.Enabled to false.")]
[DataRow(true, DisplayName = "Validate if Cache.Enabled remains true.")]
public void TestUpdateEnabledForCacheSettings(bool updatedEnabledValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update cache enabled flag
ConfigureOptions options = new(
runtimeCacheEnabled: updatedEnabledValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the cache Enabled Flag is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Cache?.Enabled);
Assert.AreEqual(updatedEnabledValue, runtimeConfig.Runtime.Cache.Enabled);
}
/// <summary>
/// Tests that running "dab configure --runtime.cache.ttl-seconds" on a config with various values results
/// in runtime config update. Takes in updated value for cache.ttl-seconds and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(4, DisplayName = "Update global cache TTL to 4.")]
public void TestUpdateTTLForCacheSettings(int updatedTtlValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update TTL Value
ConfigureOptions options = new(
runtimeCacheTtl: updatedTtlValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the TTL Value is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Cache?.TtlSeconds);
Assert.AreEqual(updatedTtlValue, runtimeConfig.Runtime.Cache.TtlSeconds);
}
/// <summary>
/// Tests that running "dab configure --runtime.compression.level {value}" on a config with various values results
/// in runtime config update. Takes in updated value for compression.level and
/// validates whether the runtime config reflects those updated values.
[DataTestMethod]
[DataRow(CompressionLevel.Fastest, DisplayName = "Update Compression.Level to fastest.")]
[DataRow(CompressionLevel.Optimal, DisplayName = "Update Compression.Level to optimal.")]
[DataRow(CompressionLevel.None, DisplayName = "Update Compression.Level to none.")]
public void TestUpdateLevelForCompressionSettings(CompressionLevel updatedLevelValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update compression level value
ConfigureOptions options = new(
runtimeCompressionLevel: updatedLevelValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Level Value is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Compression?.Level);
Assert.AreEqual(updatedLevelValue, runtimeConfig.Runtime.Compression.Level);
}
/// <summary>
/// Tests that running "dab configure --runtime.host.mode {value}" on a config with various values results
/// in runtime config update. Takes in updated value for host.mode and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow("production", DisplayName = "Update mode to production for Host.")]
[DataRow("Production", DisplayName = "Update mode to Production for Host.")]
[DataRow("development", DisplayName = "Ensure mode is retained to development for Host.")]
[DataRow("Development", DisplayName = "Ensure mode is retained to Development for Host.")]
public void TestCaseInsensitiveUpdateModeForHostSettings(string modeValue)
{
// Arrange -> all the setup which includes creating options.
Enum.TryParse<HostMode>(modeValue, ignoreCase: true, out HostMode updatedModeValue);
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update host.mode value
ConfigureOptions options = new(
runtimeHostMode: updatedModeValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Mode in Host is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Host?.Mode);
Assert.AreEqual(updatedModeValue, runtimeConfig.Runtime.Host.Mode);
}
/// <summary>
/// Tests that running "dab configure --runtime.host.cors.origins {value}" on a config with various values results
/// in runtime config update. Takes in updated value for host.cors.origins and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow("https://localhost, https://localhost1", DisplayName = "Overwrite list of origins in Cors in Host with comma.")]
[DataRow("https://localhost https://localhost1", DisplayName = "Overwrite list of origins in Cors in Host with space.")]
public void TestUpdateCorsOriginsForHostSettings(string inputValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Convert the comma-separated string into a List<string>
List<string> originsValue = inputValue.Split(new char[] { ',', ' ' }).ToList();
// Act: Attempts to update host.cors.origins value
ConfigureOptions configureOptions = new(
runtimeHostCorsOrigins: originsValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(configureOptions, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Cors.Origins in Host is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Host?.Cors?.Origins);
CollectionAssert.AreEqual(originsValue.ToArray(), runtimeConfig.Runtime.Host.Cors.Origins);
}
/// <summary>
/// Tests that running "dab configure --runtime.host.cors.allow-credentials {value}" on a config with various values results
/// in runtime config update. Takes in updated value for host.cors.allow-credentials and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow(false, DisplayName = "Update cors.allow-credentials to false for Host.")]
[DataRow(true, DisplayName = "Update cors.allow-credentials to true for Host.")]
public void TestUpdateCorsAllowCredentialsHostSettings(bool allowCredentialsValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update host.cors.allow-credentials value
ConfigureOptions options = new(
runtimeHostCorsAllowCredentials: allowCredentialsValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the cors.allow-credentials in Host is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Host?.Cors?.AllowCredentials);
Assert.AreEqual(allowCredentialsValue, runtimeConfig.Runtime.Host.Cors.AllowCredentials);
}
/// <summary>
/// Tests that running "dab configure --runtime.host.authentication.provider {value}" on a config with various values results
/// in runtime config update. Takes in updated value for host.authentication.provider and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow("staticWebApps", DisplayName = "Update authentication.provider to StaticWebApps for Host.")]
[DataRow("Appservice", DisplayName = "Update authentication.provider to AppService for Host.")]
[DataRow("azuread", DisplayName = "Update authentication.provider to AzureAD for Host.")]
[DataRow("entraid", DisplayName = "Update authentication.provider to EntraID for Host.")]
public void TestUpdateAuthenticationProviderHostSettings(string authenticationProviderValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update host.authentication.provider value
ConfigureOptions options = new(
runtimeHostAuthenticationProvider: authenticationProviderValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the authentication.provider in Host is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Host?.Authentication?.Provider);
Assert.AreEqual(authenticationProviderValue, runtimeConfig.Runtime.Host.Authentication.Provider);
}
/// <summary>
/// Tests that running "dab configure --runtime.host.authentication.jwt.audience {value}" on a config with various values results
/// in runtime config update. Takes in updated value for host.authentication.jwt.audience and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow("updatedAudience", DisplayName = "Update authentication.jwt.audience to 'updatedAudience' for Host.")]
public void TestUpdateAuthenticationJwtAudienceHostSettings(string updatedJwtAudienceValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update host.authentication.jwt.audience value
ConfigureOptions options = new(
runtimeHostAuthenticationJwtAudience: updatedJwtAudienceValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the authentication.jwt.audience in Host is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Host?.Authentication?.Jwt?.Audience);
Assert.AreEqual(updatedJwtAudienceValue.ToString(), runtimeConfig.Runtime.Host.Authentication.Jwt.Audience);
}
/// <summary>
/// Tests that running "dab configure --runtime.host.authentication.jwt.issuer {value}" on a config with various values results
/// in runtime config update. Takes in updated value for host.authentication.jwt.issuer and
/// validates whether the runtime config reflects those updated values
[DataTestMethod]
[DataRow("updatedIssuer", DisplayName = "Update authentication.jwt.issuer to 'updatedIssuer' for Host.")]
public void TestUpdateAuthenticationJwtIssuerHostSettings(string updatedJwtIssuerValue)
{
// Arrange -> all the setup which includes creating options.
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
// Act: Attempts to update host.authentication.jwt.issuer value
ConfigureOptions options = new(
runtimeHostAuthenticationJwtIssuer: updatedJwtIssuerValue,
config: TEST_RUNTIME_CONFIG_FILE
);
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the authentication.jwt.issuer in Host is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig.Runtime?.Host?.Authentication?.Jwt?.Issuer);
Assert.AreEqual(updatedJwtIssuerValue.ToString(), runtimeConfig.Runtime.Host.Authentication.Jwt.Issuer);
}
/// <summary>
/// Test to update the current depth limit for GraphQL and removal the depth limit using -1.
/// When runtime.graphql.depth-limit has an initial value of 8.
/// validates that "dab configure --runtime.graphql.depth-limit {value}" sets the expected depth limit.
/// </summary>
[DataTestMethod]
[DataRow(20, DisplayName = "Update current depth limit for GraphQL.")]
[DataRow(-1, DisplayName = "Remove depth limit from GraphQL by setting depth limit to -1.")]
public void TestUpdateDepthLimitForGraphQL(int? newDepthLimit)
{
int currentDepthLimit = 8;
// Arrange
RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? config);
Assert.IsNotNull(config);
config = config with
{
Runtime = config.Runtime! with
{
GraphQL = config.Runtime.GraphQL! with
{
DepthLimit = currentDepthLimit
}
}
};
_fileSystem!.AddFile(TEST_RUNTIME_CONFIG_FILE, new MockFileData(config.ToJson()));
ConfigureOptions options = new(
depthLimit: newDepthLimit,
config: TEST_RUNTIME_CONFIG_FILE
);
// Act: Update Depth Limit
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert: Validate the Depth Limit is updated
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out config));
Assert.AreEqual(newDepthLimit, config.Runtime?.GraphQL?.DepthLimit);
}
/// <summary>
/// Tests the update of the database type in the runtime config.
/// dab configure `--data-source.database-type {dbType}`
/// This method verifies that the database type can be updated to various valid values, including different cases,
/// and ensures that the config file is correctly modified and parsed after the update.
/// </summary>
[DataTestMethod]
[DataRow("mssql", DisplayName = "Update the database type to MSSQL")]
[DataRow("MSSql", DisplayName = "Update the database type to MSSQL with different case")]
[DataRow("postgresql", DisplayName = "Update the database type to PostgreSQL")]
[DataRow("cosmosdb_nosql", DisplayName = "Update the database type to CosmosDB_NoSQL")]
[DataRow("cosmosdb_postgresql", DisplayName = "Update the database type to CosmosDB_PGSQL")]
[DataRow("mysql", DisplayName = "Update the database type to MySQL")]
public void TestDatabaseTypeUpdate(string dbType)
{
// Arrange
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
ConfigureOptions options = new(
dataSourceDatabaseType: dbType,
config: TEST_RUNTIME_CONFIG_FILE
);
// Act
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? config));
Assert.IsNotNull(config.Runtime);
Assert.AreEqual(config.DataSource.DatabaseType, Enum.Parse<DatabaseType>(dbType, ignoreCase: true));
}
/// <summary>
/// Tests the update of the database type from CosmosDB_NoSQL to MSSQL in the runtime config.
/// This method verifies that the database type can be changed from CosmosDB_NoSQL to MSSQL and that the
/// specific MSSQL option 'set-session-context' is correctly added to the configuration and the specific
/// cosmosDB options are removed.
/// Command: dab configure --data-source.database-type mssql --data-source.options.set-session-context true
/// </summary>
[TestMethod]
public void TestDatabaseTypeUpdateCosmosDB_NoSQLToMSSQL()
{
// Arrange
SetupFileSystemWithInitialConfig(INITIAL_COSMOSDB_NOSQL_CONFIG);
ConfigureOptions options = new(
dataSourceDatabaseType: "mssql",
dataSourceOptionsSetSessionContext: true,
config: TEST_RUNTIME_CONFIG_FILE
);
// Act
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? config));
Assert.IsNotNull(config.Runtime);
Assert.AreEqual(config.DataSource.DatabaseType, DatabaseType.MSSQL);
Assert.AreEqual(config.DataSource.Options!.GetValueOrDefault("set-session-context", false), true);
Assert.IsFalse(config.DataSource.Options!.ContainsKey("database"));
Assert.IsFalse(config.DataSource.Options!.ContainsKey("container"));
Assert.IsFalse(config.DataSource.Options!.ContainsKey("schema"));
}
/// <summary>
/// Tests the update of the database type from MSSQL to CosmosDB_NoSQL in the runtime config.
/// This method verifies that the database type can be changed from MSSQL to CosmosDB_NoSQL and that the
/// specific CosmosDB_NoSQL options such as database, container, and schema are correctly added to the config.
/// Command: dab configure --data-source.database-type cosmosdb_nosql
/// --data-source.options.database testdb --data-source.options.container testcontainer --data-source.options.schema testschema.gql
/// </summary>
[TestMethod]
public void TestDatabaseTypeUpdateMSSQLToCosmosDB_NoSQL()
{
// Arrange
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
ConfigureOptions options = new(
dataSourceDatabaseType: "cosmosdb_nosql",
dataSourceOptionsDatabase: "testdb",
dataSourceOptionsContainer: "testcontainer",
dataSourceOptionsSchema: "testschema.gql",
config: TEST_RUNTIME_CONFIG_FILE
);
// Act
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? config));
Assert.IsNotNull(config.Runtime);
Assert.AreEqual(config.DataSource.DatabaseType, DatabaseType.CosmosDB_NoSQL);
Assert.AreEqual(config.DataSource.Options!.GetValueOrDefault("database"), "testdb");
Assert.AreEqual(config.DataSource.Options!.GetValueOrDefault("container"), "testcontainer");
Assert.AreEqual(config.DataSource.Options!.GetValueOrDefault("schema"), "testschema.gql");
}
/// <summary>
/// Tests configuring database type with an invalid database type value.
/// This method verifies that when an invalid database type is provided,
/// the runtime config is not updated. It ensures that the method correctly identifies and handles
/// invalid database types by returning false.
/// </summary>
[TestMethod]
public void TestConfiguringInvalidDatabaseType()
{
// Arrange
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
ConfigureOptions options = new(
dataSourceDatabaseType: "invalid",
config: TEST_RUNTIME_CONFIG_FILE
);
// Act
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsFalse(isSuccess);
}
/// <summary>
/// Tests the failure scenario when attempting to add CosmosDB-specific options to an MSSQL database configuration.
/// This method verifies that the configuration process correctly fails when options such as database, container,
/// and schema, which are specific to CosmosDB_NoSQL, are provided for an MSSQL database type.
/// </summary>
[TestMethod]
public void TestFailureWhenAddingCosmosDbOptionsToMSSQLDatabase()
{
// Arrange
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
ConfigureOptions options = new(
dataSourceOptionsDatabase: "testdb",
dataSourceOptionsContainer: "testcontainer",
dataSourceOptionsSchema: "testschema.gql",
config: TEST_RUNTIME_CONFIG_FILE
);
// Act
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsFalse(isSuccess);
}
/// <summary>
/// Tests the failure scenario when attempting to add the 'set-session-context' option to a MySQL database configuration.
/// This method verifies that the configuration process correctly fails when the 'set-session-context' option,
/// which is specific to MSSQL/DWSQL, is provided for a MySQL database type.
/// </summary>
[TestMethod]
public void TestFailureWhenAddingSetSessionContextToMySQLDatabase()
{
// Arrange
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
ConfigureOptions options = new(
dataSourceDatabaseType: "mysql",
dataSourceOptionsSetSessionContext: true,
config: TEST_RUNTIME_CONFIG_FILE
);
// Act
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsFalse(isSuccess);
}
/// <summary>
/// Tests adding data-source.health.name to a config that doesn't have a health section.
/// This method verifies that the health.name can be added to a data source configuration
/// that doesn't previously have a health section.
/// Command: dab configure --data-source.health.name "My Data Source"
/// </summary>
[TestMethod]
public void TestAddDataSourceHealthName()
{
// Arrange
SetupFileSystemWithInitialConfig(INITIAL_CONFIG);
ConfigureOptions options = new(
dataSourceHealthName: TEST_DATASOURCE_HEALTH_NAME,
config: TEST_RUNTIME_CONFIG_FILE
);
// Act
bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!);
// Assert
Assert.IsTrue(isSuccess);
string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? config));
Assert.IsNotNull(config.DataSource);
Assert.IsNotNull(config.DataSource.Health);
Assert.AreEqual(TEST_DATASOURCE_HEALTH_NAME, config.DataSource.Health.Name);
Assert.IsTrue(config.DataSource.Health.Enabled); // Default value
}
/// <summary>
/// Tests updating data-source.health.name on a config that already has a health section.
/// This method verifies that the health.name can be updated while preserving other health settings.
/// Command: dab configure --data-source.health.name "Updated Name"
/// </summary>
[DataTestMethod]
[DataRow("New Name", DisplayName = "Update health name with a simple string")]
[DataRow("This is the value", DisplayName = "Update health name with the example from the issue")]
public void TestUpdateDataSourceHealthName(string healthName)
{
// Arrange - Config with existing health section
string configWithHealth = @"
{