-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathGivenThatIWantToInstallDotnetFromAScript.cs
663 lines (559 loc) · 28.9 KB
/
GivenThatIWantToInstallDotnetFromAScript.cs
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
// Copyright (c) Microsoft. All rights reserved.
using FluentAssertions;
using Install_Scripts.Test.Utils;
using Microsoft.NET.TestFramework.Assertions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.DotNet.InstallationScript.Tests
{
public class GivenThatIWantToInstallDotnetFromAScript : IDisposable
{
/// <summary>
/// All the channels that will be tested.
/// </summary>
private static readonly IReadOnlyList<(string channel, string versionRegex, Quality quality)> _channels =
new List<(string, string, Quality)>()
{
("2.1", "2\\.1\\..*", Quality.None),
("2.2", "2\\.2\\..*", Quality.None),
("3.0", "3\\.0\\..*", Quality.None),
("3.1", "3\\.1\\..*", Quality.None),
("5.0", "5\\.0\\..*", Quality.None),
("6.0", "6\\.0\\..*", Quality.Daily),
("6.0", "6\\.0\\..*", Quality.None),
("LTS", "8\\.0\\..*", Quality.None),
("7.0", "7\\.0\\..*", Quality.None),
("7.0", "7\\.0\\..*", Quality.Ga),
("8.0", "8\\.0\\..*", Quality.None),
("8.0", "8\\.0\\..*", Quality.Ga),
("STS", "9\\.0\\..*", Quality.None),
("9.0", "9\\.0\\..*", Quality.None),
("9.0", "9\\.0\\..*", Quality.Ga),
// 10 not available yet
//("10.0", "10\\.0\\..*", Quality.None),
//("10.0", "10\\.0\\..*", Quality.Preview),
//("10.0", "10\\.0\\..*", Quality.Ga),
};
/// <summary>
/// All the branches in runtime repos to be tested
/// </summary>
private static readonly IReadOnlyList<(string branch, string versionRegex, Quality quality)> _runtimeBranches =
new List<(string, string, Quality)>()
{
("release/2.1", "2\\.1\\..*", Quality.None),
("release/2.2", "2\\.2\\..*", Quality.None),
("release/3.0", "3\\.0\\..*", Quality.None),
("release/3.1", "3\\.1\\..*", Quality.None),
// ("release/5.0", "5\\.0\\..*", Quality.None), Broken scenario
// Branches are no longer supported starting 6.0, but there are channels that correspond to branches.
// this storage account does not allow public access
// ("6.0-preview2", "6\\.0\\..*", Quality.Daily | Quality.Signed),
("6.0-preview3", "6\\.0\\..*", Quality.Daily),
("6.0-preview4", "6\\.0\\..*", Quality.Daily),
("6.0", "6\\.0\\..*", Quality.None),
("7.0", "7\\.0\\..*", Quality.None),
("8.0", "8\\.0\\..*", Quality.None),
("9.0", "9\\.0\\..*", Quality.None),
};
/// <summary>
/// All the branches in installer repo to be tested
/// </summary>
private static readonly IReadOnlyList<(string branch, string versionRegex, Quality quality)> _sdkBranches =
new List<(string, string, Quality)>()
{
("release/2.1.8xx", "2\\.1\\.8.*", Quality.None),
("release/2.2.4xx", "2\\.2\\.4.*", Quality.None),
("release/3.0.1xx", "3\\.0\\.1.*", Quality.None),
// version is outdated. For more details check the link: https://github.com/dotnet/arcade/issues/10026
// ("release/3.1.4xx", "3\\.1\\.4.*", Quality.None),
("release/5.0.1xx", "5\\.0\\.1.*", Quality.None),
("release/5.0.2xx", "5\\.0\\.2.*", Quality.None),
// Branches are no longer supported starting 6.0, but there are channels that correspond to branches.
// this storage account does not allow public access
// ("6.0.1xx-preview2", "6\\.0\\.1.*", Quality.Daily | Quality.Signed),
("6.0.1xx-preview3", "6\\.0\\.1.*", Quality.Daily),
("6.0.1xx-preview4", "6\\.0\\.1.*", Quality.Daily),
("7.0.1xx", "7\\.0\\..*", Quality.Daily),
("8.0.1xx", "8\\.0\\..*", Quality.Daily),
("9.0.1xx", "9\\.0\\..*", Quality.Daily),
};
public static IEnumerable<object?[]> InstallSdkFromChannelTestCases
{
get
{
// Download SDK using branches as channels.
foreach (var sdkBranchInfo in _sdkBranches)
{
foreach (string? quality in GetQualityOptionsFromFlags(sdkBranchInfo.quality).DefaultIfEmpty())
{
yield return new object?[]
{
sdkBranchInfo.branch,
quality,
sdkBranchInfo.versionRegex,
};
}
}
// Download SDK from darc channels.
foreach (var channelInfo in _channels)
{
foreach(string? quality in GetQualityOptionsFromFlags(channelInfo.quality).DefaultIfEmpty())
{
yield return new object?[]
{
channelInfo.channel,
quality,
channelInfo.versionRegex,
};
}
}
}
}
public static IEnumerable<object?[]> InstallRuntimeFromChannelTestCases
{
get
{
// Download runtimes using branches as channels.
foreach (var runtimeBranchInfo in _runtimeBranches)
{
foreach (string? quality in GetQualityOptionsFromFlags(runtimeBranchInfo.quality).DefaultIfEmpty())
{
yield return new object?[]
{
runtimeBranchInfo.branch,
quality,
runtimeBranchInfo.versionRegex,
};
}
}
// Download runtimes using darc channels.
foreach (var channelInfo in _channels)
{
foreach (string? quality in GetQualityOptionsFromFlags(channelInfo.quality).DefaultIfEmpty())
{
yield return new object?[]
{
channelInfo.channel,
quality,
channelInfo.versionRegex,
};
}
}
}
}
/// <summary>
/// The directory that the install script will install the .NET into.
/// </summary>
private readonly string _sdkInstallationDirectory;
private readonly ITestOutputHelper outputHelper;
/// <summary>
/// Instantiates a GivenThatIWantToInstallTheSdkFromAScript instance.
/// </summary>
/// <remarks>This constructor is called once for each of the tests to run.</remarks>
public GivenThatIWantToInstallDotnetFromAScript(ITestOutputHelper testOutputHelper)
{
outputHelper = testOutputHelper;
_sdkInstallationDirectory = Path.Combine(
Path.GetTempPath(),
"InstallScript-Tests",
Path.GetRandomFileName());
// In case there are any files from previous runs, clean them up.
try
{
Directory.Delete(_sdkInstallationDirectory, true);
}
catch (DirectoryNotFoundException)
{
// This is expected. Ignore the exception.
}
Directory.CreateDirectory(_sdkInstallationDirectory);
}
/// <summary>
/// Disposes the instance.
/// </summary>
/// <remarks>This method is called after each test. It is used for cleaning
/// the leftover files from each test run.</remarks>
public void Dispose()
{
try
{
Directory.Delete(_sdkInstallationDirectory, true);
}
catch (DirectoryNotFoundException)
{
// Directory to cleanup may not be there if installation fails. Not an issue. Ignore the exception.
}
}
[Theory]
[MemberData(nameof(InstallSdkFromChannelTestCases))]
public void WhenInstallingTheSdk(string channel, string? quality, string versionRegex)
{
// Run install script to download and install.
var e = Encoding.UTF8;
var args = GetInstallScriptArgs(channel, null, quality, _sdkInstallationDirectory);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
// Run dotnet to verify that the version is installed into correct folder.
var dotnetArgs = new List<string> { "--info" };
var dotnetCommandResult = TestUtils.CreateDotnetCommand(dotnetArgs).ExecuteDotnetCommand(_sdkInstallationDirectory);
// On MacOS, installation directory has an extra /private at the beginning.
string installPathRegex = "\\[(/private)?" + Regex.Escape(Path.Combine(_sdkInstallationDirectory, "sdk")) + "\\]";
string regex = Regex.Escape(" ") + versionRegex + Regex.Escape(" ") + installPathRegex;
dotnetCommandResult.Should().HaveStdOutMatching(regex);
dotnetCommandResult.Should().Pass();
}
[Theory]
[MemberData(nameof(InstallRuntimeFromChannelTestCases))]
public void WhenInstallingDotnetRuntime(string channel, string? quality, string versionRegex)
{
// Run install script to download and install.
var args = GetInstallScriptArgs(channel, "dotnet", quality, _sdkInstallationDirectory);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
// Run dotnet to verify that the version is installed into correct folder.
var dotnetArgs = new List<string> { "--info" };
var dotnetCommandResult = TestUtils.CreateDotnetCommand(dotnetArgs).ExecuteDotnetCommand(_sdkInstallationDirectory);
string lineStartRegex = Regex.Escape(" Microsoft.NETCore.App ");
string lineEndRegex = "\\ \\[(/private)?" + Regex.Escape(Path.Combine(_sdkInstallationDirectory, "shared", "Microsoft.NETCore.App")) + "\\]";
string regex = lineStartRegex + versionRegex + lineEndRegex;
dotnetCommandResult.Should().HaveStdOutMatching(regex);
dotnetCommandResult.Should().Pass();
}
[Theory]
[MemberData(nameof(InstallRuntimeFromChannelTestCases))]
public void WhenInstallingAspNetCoreRuntime(string channel, string? quality, string versionRegex)
{
if (channel == "release/3.0"
|| channel == "release/3.1")
{
// These scenarios are broken.
return;
}
// Run install script to download and install.
var args = GetInstallScriptArgs(channel, "aspnetcore", quality, _sdkInstallationDirectory);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
// Run dotnet to verify that the version is installed into correct folder.
var dotnetArgs = new List<string> { "--info" };
var dotnetCommandResult = TestUtils.CreateDotnetCommand(dotnetArgs).ExecuteDotnetCommand(_sdkInstallationDirectory);
string lineStartRegex = Regex.Escape(" Microsoft.AspNetCore.App ");
string lineEndRegex = "\\ \\[(/private)?" + Regex.Escape(Path.Combine(_sdkInstallationDirectory, "shared", "Microsoft.AspNetCore.App")) + "\\]";
string regex = lineStartRegex + versionRegex + lineEndRegex;
dotnetCommandResult.Should().HaveStdOutMatching(regex);
dotnetCommandResult.Should().Pass();
}
[Theory]
[MemberData(nameof(InstallRuntimeFromChannelTestCases))]
public void WhenInstallingWindowsdesktopRuntime(string channel, string? quality, string versionRegex)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Don't install windowsdesktop if not on Windows.
return;
}
List<Regex> exclusions = new List<Regex>()
{
new Regex(".*2\\..*"), // Runtime is not supported in this version.
new Regex(".*3\\.0.*"), // Runtime is not supported in this version.
new Regex("release/3.1"), // Broken scenario.
new Regex("6.0"), // Broken scenario.
new Regex("6.0-preview2"), // Broken scenario.
};
if (exclusions.Any(e => e.IsMatch(channel)))
{
// Test is excluded.
return;
}
// Run install script to download and install.
var args = GetInstallScriptArgs(channel, "windowsdesktop", quality, _sdkInstallationDirectory);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
//commandResult.Should().NotHaveStdErr();
//commandResult.Should().HaveStdOutContaining("Installation finished");
//commandResult.Should().Pass();
//TestOutputHelper.PopulateTestLoggerOutput(outputHelper, commandResult);
// Dotnet CLI is not included in the windowsdesktop runtime. Therefore, version validation cannot be tested.
// Add the validation once the becomes available in the artifacts.
}
[Theory]
[MemberData(nameof(InstallSdkFromChannelTestCases))]
public void WhenInstallingTheSdkWithFeedCredential(string channel, string? quality, string versionRegex)
{
string feedCredential = "?" + Guid.NewGuid().ToString();
// Run install script to download and install.
var args = GetInstallScriptArgs(channel, null, quality, _sdkInstallationDirectory, feedCredential, verboseLogging: true);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().NotHaveStdErr();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdOutContainingIgnoreCase(feedCredential);
commandResult.Should().Pass();
}
[Theory]
[MemberData(nameof(InstallRuntimeFromChannelTestCases))]
public void WhenInstallingDotnetRuntimeWithFeedCredential(string channel, string? quality, string versionRegex)
{
string feedCredential = "?" + Guid.NewGuid().ToString();
// Run install script to download and install.
var args = GetInstallScriptArgs(channel, "dotnet", quality, _sdkInstallationDirectory, feedCredential, verboseLogging: true);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().NotHaveStdErr();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdOutContainingIgnoreCase(feedCredential);
commandResult.Should().Pass();
}
[Theory]
[InlineData("5.0.404-servicing.21560.14", "5.0.404")]
[InlineData("6.0.100-preview.6.21364.34")]
[InlineData("7.0.100-alpha.1.22054.9")]
[InlineData("8.0.404")]
[InlineData("9.0.100")]
public void WhenInstallingASpecificVersionOfTheSdk(string version, string? effectiveVersion = null)
{
// Run install script to download and install.
var args = GetInstallScriptArgs(channel: null, runtime: null, quality: null, _sdkInstallationDirectory, version: version);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
// Run dotnet to verify that the version is installed into correct folder.
var dotnetArgs = new List<string> { "--info" };
var dotnetCommandResult = TestUtils.CreateDotnetCommand(dotnetArgs).ExecuteDotnetCommand(_sdkInstallationDirectory);
// On MacOS, installation directory has an extra /private at the beginning.
string installPathRegex = "\\[(/private)?" + Regex.Escape(Path.Combine(_sdkInstallationDirectory, "sdk")) + "\\]";
string regex = Regex.Escape(" " + (effectiveVersion ?? version) + " ") + installPathRegex;
dotnetCommandResult.Should().HaveStdOutMatching(regex);
dotnetCommandResult.Should().Pass();
}
[Theory]
[InlineData("5.0.13-servicing.21560.6", "5.0.13")]
[InlineData("6.0.0-preview.4.21176.7")]
[InlineData("7.0.0-alpha.1.21528.8")]
[InlineData("8.0.11")]
[InlineData("9.0.0")]
public void WhenInstallingASpecificVersionOfDotnetRuntime(string version, string? effectiveVersion = null)
{
// Run install script to download and install.
var args = GetInstallScriptArgs(channel: null, "dotnet", quality: null, _sdkInstallationDirectory, version: version);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
// Run dotnet to verify that the version is installed into correct folder.
var dotnetArgs = new List<string> { "--info" };
var dotnetCommandResult = TestUtils.CreateDotnetCommand(dotnetArgs).ExecuteDotnetCommand(_sdkInstallationDirectory);
string lineStartRegex = Regex.Escape(" Microsoft.NETCore.App ");
string lineEndRegex = "\\ \\[(/private)?" + Regex.Escape(Path.Combine(_sdkInstallationDirectory, "shared", "Microsoft.NETCore.App")) + "\\]";
string regex = lineStartRegex + Regex.Escape(effectiveVersion ?? version) + lineEndRegex;
dotnetCommandResult.Should().HaveStdOutMatching(regex);
dotnetCommandResult.Should().Pass();
}
[Theory]
[InlineData("5.0.13-servicing.21552.32", "5.0.13")]
[InlineData("6.0.0-preview.4.21176.7")]
[InlineData("7.0.0-alpha.1.21567.15")]
[InlineData("8.0.11")]
[InlineData("9.0.0")]
public void WhenInstallingASpecificVersionOfAspNetCoreRuntime(string version, string? effectiveVersion = null)
{
// Run install script to download and install.
var args = GetInstallScriptArgs(channel: null, "aspnetcore", quality: null, _sdkInstallationDirectory, version: version);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
// Run dotnet to verify that the version is installed into correct folder.
var dotnetArgs = new List<string> { "--info" };
var dotnetCommandResult = TestUtils.CreateDotnetCommand(dotnetArgs).ExecuteDotnetCommand(_sdkInstallationDirectory);
string lineStartRegex = Regex.Escape(" Microsoft.AspNetCore.App ");
string lineEndRegex = "\\ \\[(/private)?" + Regex.Escape(Path.Combine(_sdkInstallationDirectory, "shared", "Microsoft.AspNetCore.App")) + "\\]";
string regex = lineStartRegex + Regex.Escape(effectiveVersion ?? version) + lineEndRegex;
dotnetCommandResult.Should().HaveStdOutMatching(regex);
dotnetCommandResult.Should().Pass();
}
[Theory]
// productVersion files are broken prior to 6.0 release.
// [InlineData("5.0.14-servicing.21614.9")]
[InlineData("6.0.1-servicing.21568.2")]
[InlineData("7.0.0-alpha.1.21472.1")]
[InlineData("8.0.11")]
[InlineData("9.0.0")]
public void WhenInstallingASpecificVersionOfWindowsdesktopRuntime(string version)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Don't install windowsdesktop if not on Windows.
return;
}
// Run install script to download and install.
var args = GetInstallScriptArgs(channel: null, "windowsdesktop", quality: null, _sdkInstallationDirectory, version: version);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().NotHaveStdErr();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().Pass();
// Dotnet CLI is not included in the windowsdesktop runtime. Therefore, version validation cannot be tested.
// Add the validation once the becomes available in the artifacts.
}
[Theory]
[InlineData("5.0.404-servicing.21560.14", "5.0.404")]
[InlineData("6.0.100-preview.6.21364.34")]
[InlineData("7.0.100-alpha.1.22054.9")]
[InlineData("8.0.11", null, "aspnetcore")]
[InlineData("9.0.0", null, "aspnetcore")]
[InlineData("5.0.13-servicing.21552.32", "5.0.13", "aspnetcore")]
[InlineData("6.0.0-preview.4.21176.7", null, "aspnetcore")]
[InlineData("7.0.0-alpha.1.21567.15", null, "aspnetcore")]
[InlineData("5.0.13-servicing.21560.6", "5.0.13", "dotnet")]
[InlineData("6.0.0-preview.4.21176.7", null, "dotnet")]
[InlineData("7.0.0-alpha.1.21528.8", null, "dotnet")]
[InlineData("6.0.1-servicing.21568.2", "6.0.1", "windowsdesktop")]
[InlineData("7.0.0-alpha.1.21472.1", null, "windowsdesktop")]
public void WhenInstallingAnAlreadyInstalledVersion(string version, string? effectiveVersion = null, string? runtime = null)
{
if (runtime == "windowsdesktop" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Don't install windowsdesktop if not on Windows.
return;
}
// Run install script to download and install.
var args = GetInstallScriptArgs(channel: null, runtime, quality: null, _sdkInstallationDirectory, version: version);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
// Run the same command. This time, it should say "already installed".
commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().NotHaveStdOutContaining("Installation finished");
commandResult.Should().HaveStdOutContaining($"with version '{effectiveVersion ?? version}' is already installed.");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
}
[Theory]
[InlineData(null, "2.4", "ga")]
[InlineData(null, "3.9", null)]
[InlineData(null, "6.a", "preview")]
[InlineData(null, "release/1.4.1xx", null)]
[InlineData(null, "LTS", "invalidQuality")]
[InlineData("dotnet", "2.4", "ga")]
[InlineData("dotnet", "3.9", null)]
[InlineData("dotnet", "6.a", "preview")]
[InlineData("dotnet", "release/1.4.1xx", null)]
[InlineData("dotnet", "LTS", "invalidQuality")]
public void WhenFailingToInstallWithFeedCredentials(string? runtime, string channel, string? quality)
{
string feedCredential = "?" + Guid.NewGuid().ToString();
// Run install script to download and install.
var args = GetInstallScriptArgs(channel, runtime, quality, _sdkInstallationDirectory, feedCredential, verboseLogging: true);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdErr();
commandResult.Should().NotHaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdOutContainingIgnoreCase(feedCredential);
}
[Theory]
[InlineData("8.0.303", Quality.Daily)]
public void WhenBothVersionAndQualityWereSpecified(string version, Quality quality)
{
var args = GetInstallScriptArgs(null, null, quality.ToString(), _sdkInstallationDirectory, version: version);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().Fail();
commandResult.Should().HaveStdErrContaining("Quality and Version options are not allowed to be specified simultaneously.");
commandResult.Should().NotHaveStdOutContaining("Installation finished");
}
[Theory]
[InlineData("8.0.303", null)]
public void WhenEitherVersionOrQualityWasSpecified(string? version, Quality? quality)
{
// Run install script to download and install.
var args = GetInstallScriptArgs(null, null, quality?.ToString(), _sdkInstallationDirectory, version: version);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
}
[Fact]
public void WhenNoArgsWereSpecified()
{
var args = GetInstallScriptArgs(null, null, null, installDir: _sdkInstallationDirectory);
var commandResult = TestUtils.CreateInstallCommand(args).ExecuteInstallation();
commandResult.Should().HaveStdOutContaining("Installation finished");
commandResult.Should().NotHaveStdErr();
commandResult.Should().Pass();
}
private static IEnumerable<string> GetInstallScriptArgs(
string? channel,
string? runtime,
string? quality,
string? installDir,
string? feedCredentials = null,
bool verboseLogging = false,
string? version = null)
{
if (!string.IsNullOrWhiteSpace(channel))
{
yield return "-Channel";
yield return channel;
}
if (!string.IsNullOrWhiteSpace(installDir))
{
yield return "-InstallDir";
yield return installDir;
}
if (!string.IsNullOrWhiteSpace(runtime))
{
yield return "-Runtime";
yield return runtime;
}
if (!string.IsNullOrWhiteSpace(quality))
{
yield return "-Quality";
yield return quality;
}
if (!string.IsNullOrWhiteSpace(feedCredentials))
{
yield return "-FeedCredential";
yield return feedCredentials;
}
if (!string.IsNullOrWhiteSpace(version))
{
yield return "-Version";
yield return version;
}
if (verboseLogging)
{
yield return "-Verbose";
}
}
private static IEnumerable<string> GetQualityOptionsFromFlags(Quality flags)
{
ulong flagsValue = (ulong)flags;
if(flagsValue == 0)
{
yield break;
}
foreach (Quality quality in Enum.GetValues(typeof(Quality)))
{
ulong qualityValue = (ulong)quality;
if(qualityValue == 0 || (qualityValue & (qualityValue-1)) != 0)
{
// No bits are set, or more than one bits are set
continue;
}
if ((flagsValue & qualityValue) != 0)
{
yield return quality.ToString();
}
}
}
}
}