forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGivenThatTheUserIsRunningDotNetForTheFirstTime.cs
More file actions
249 lines (194 loc) · 9.81 KB
/
GivenThatTheUserIsRunningDotNetForTheFirstTime.cs
File metadata and controls
249 lines (194 loc) · 9.81 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable disable
using System.Runtime.CompilerServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
//[assembly: CollectionBehavior(DisableTestParallelization = true)]
namespace Microsoft.DotNet.Tests
{
public class DotNetFirstTime
{
public DirectoryInfo NugetFallbackFolder;
public DirectoryInfo DotDotnetFolder;
public string TestDirectory;
public TestCommand Setup(ITestOutputHelper log, TestAssetsManager testAssets, [CallerMemberName] string testName = null)
{
TestDirectory = testAssets.CreateTestDirectory(testName).Path;
var testNuGetHome = Path.Combine(TestDirectory, "nuget_home");
var cliTestFallbackFolder = Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder");
var profiled = Path.Combine(TestDirectory, "profile.d");
var pathsd = Path.Combine(TestDirectory, "paths.d");
var command = new DotnetCommand(log)
.WithWorkingDirectory(TestDirectory)
.WithEnvironmentVariable("APPDATA", testNuGetHome)
.WithEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER", cliTestFallbackFolder)
.WithEnvironmentVariable("DOTNET_CLI_TEST_LINUX_PROFILED_PATH", profiled)
.WithEnvironmentVariable("DOTNET_CLI_TEST_OSX_PATHSD_PATH", pathsd)
.WithEnvironmentVariable("SkipInvalidConfigurations", "true")
.WithEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName, testNuGetHome);
NugetFallbackFolder = new DirectoryInfo(cliTestFallbackFolder);
DotDotnetFolder = new DirectoryInfo(Path.Combine(testNuGetHome, ".dotnet"));
return command;
}
}
public class DotNetFirstTimeFixture : IDisposable
{
public CommandResult FirstDotnetNonVerbUseCommandResult;
public CommandResult FirstDotnetVerbUseCommandResult;
public CommandResult FirstDotnetWorkloadInfoResult;
public DirectoryInfo NugetFallbackFolder;
public DirectoryInfo DotDotnetFolder;
public string TestDirectory;
public Dictionary<string, string> ExtraEnvironmentVariables = new();
public void Init(ITestOutputHelper log, TestAssetsManager testAssets)
{
if (TestDirectory == null)
{
var dotnetFirstTime = new DotNetFirstTime();
var command = dotnetFirstTime.Setup(log, testAssets, testName: "Dotnet_first_time_experience_tests");
FirstDotnetNonVerbUseCommandResult = command.Execute("--info");
FirstDotnetVerbUseCommandResult = command.Execute("new", "--debug:ephemeral-hive");
TestDirectory = dotnetFirstTime.TestDirectory;
NugetFallbackFolder = dotnetFirstTime.NugetFallbackFolder;
DotDotnetFolder = dotnetFirstTime.DotDotnetFolder;
}
}
public void Dispose()
{
}
}
public class GivenThatTheUserIsRunningDotNetForTheFirstTime : SdkTest, IClassFixture<DotNetFirstTimeFixture>
{
DotNetFirstTimeFixture _fixture;
public GivenThatTheUserIsRunningDotNetForTheFirstTime(ITestOutputHelper log, DotNetFirstTimeFixture fixture) : base(log)
{
fixture.Init(log, _testAssetsManager);
_fixture = fixture;
}
[Fact]
public void UsingDotnetForTheFirstTimeSucceeds()
{
_fixture.FirstDotnetVerbUseCommandResult
.Should()
.Pass();
}
[Fact]
public void UsingDotnetForTheFirstTimeWithNonVerbsDoesNotPrintEula()
{
string firstTimeNonVerbUseMessage = Cli.Utils.LocalizableStrings.DotNetSdkInfoLabel;
_fixture.FirstDotnetNonVerbUseCommandResult.StdOut
.Should()
.StartWith(firstTimeNonVerbUseMessage);
}
[Fact]
public void ItShowsTheAppropriateMessageToTheUser()
{
var expectedVersion = GetDotnetVersion();
_fixture.FirstDotnetVerbUseCommandResult.StdErr
.Should()
.ContainVisuallySameFragment(string.Format(
Configurer.LocalizableStrings.FirstTimeMessageWelcome,
DotnetFirstTimeUseConfigurer.ParseDotNetVersion(expectedVersion),
expectedVersion))
.And.ContainVisuallySameFragment(Configurer.LocalizableStrings.FirstTimeMessageMoreInformation)
.And.NotContain("Restore completed in");
}
[WindowsOnlyFact]
public void FirstRunExperienceMessagesShouldGoToStdErr()
{
// This test ensures that first-run experience messages go to stderr,
// not stdout, to avoid interfering with completion commands and other
// tools that parse stdout. See: https://github.com/dotnet/sdk/issues/50444
var expectedVersion = GetDotnetVersion();
// StdErr should contain first-run messages
_fixture.FirstDotnetVerbUseCommandResult.StdErr
.Should()
.ContainVisuallySameFragment(string.Format(
Configurer.LocalizableStrings.FirstTimeMessageWelcome,
DotnetFirstTimeUseConfigurer.ParseDotNetVersion(expectedVersion),
expectedVersion))
.And.ContainVisuallySameFragment(Configurer.LocalizableStrings.FirstTimeMessageMoreInformation);
// StdOut should NOT contain first-run messages (they should only be in stderr)
_fixture.FirstDotnetVerbUseCommandResult.StdOut
.Should()
.NotContain("Welcome to .NET")
.And.NotContain("Write your first app");
}
[Fact]
public void ItCreatesAFirstUseSentinelFileUnderTheDotDotNetFolder()
{
_fixture.DotDotnetFolder
.Should()
.HaveFile($"{GetDotnetVersion()}.dotnetFirstUseSentinel");
}
[Fact]
public void ItCreatesAnAspNetCertificateSentinelFileUnderTheDotDotNetFolder()
{
_fixture.DotDotnetFolder
.Should()
.HaveFile($"{GetDotnetVersion()}.aspNetCertificateSentinel");
}
[Fact]
public void ItDoesNotCreateAFirstUseSentinelFileNorAnAspNetCertificateSentinelFileUnderTheDotDotNetFolderWhenInternalReportInstallSuccessIsInvoked()
{
var dotnetFirstTime = new DotNetFirstTime();
var command = dotnetFirstTime.Setup(Log, _testAssetsManager);
// Disable telemetry to prevent the creation of the .dotnet folder
// for machineid and docker cache files
command = command.WithEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "true");
command.Execute("internal-reportinstallsuccess", "test").Should().Pass();
var homeFolder = dotnetFirstTime.NugetFallbackFolder.Parent;
homeFolder.Should().NotExist();
}
[WindowsOnlyFact]
public void ItShowsTheTelemetryNoticeWhenInvokingACommandAfterInternalReportInstallSuccessHasBeenInvoked()
{
var dotnetFirstTime = new DotNetFirstTime();
var command = dotnetFirstTime.Setup(Log, _testAssetsManager);
command.Execute("internal-reportinstallsuccess", "test").Should().Pass();
var result = command.Execute("new", "--debug:ephemeral-hive");
var expectedVersion = GetDotnetVersion();
result.StdErr
.Should()
.ContainVisuallySameFragment(string.Format(
Configurer.LocalizableStrings.FirstTimeMessageWelcome,
DotnetFirstTimeUseConfigurer.ParseDotNetVersion(expectedVersion),
expectedVersion))
.And.ContainVisuallySameFragment(Configurer.LocalizableStrings.FirstTimeMessageMoreInformation);
}
[Fact]
public void ItShowsTheAspNetCertificateGenerationMessageWhenInvokingACommandAfterInternalReportInstallSuccessHasBeenInvoked()
{
var dotnetFirstTime = new DotNetFirstTime();
var command = dotnetFirstTime.Setup(Log, _testAssetsManager);
command.Execute("internal-reportinstallsuccess", "test").Should().Pass();
command.Execute("new", "--debug:ephemeral-hive");
}
[LinuxOnlyFact]
public void ItCreatesTheProfileFileOnLinuxWhenInvokedFromNativeInstaller()
{
var dotnetFirstTime = new DotNetFirstTime();
var command = dotnetFirstTime.Setup(Log, _testAssetsManager);
var profiled = Path.Combine(dotnetFirstTime.TestDirectory, "profile.d");
command.Execute("internal-reportinstallsuccess", "test").Should().Pass();
File.Exists(profiled).Should().BeTrue();
File.ReadAllText(profiled).Should().Be(
$"export PATH=\"$PATH:{CliFolderPathCalculator.ToolsShimPathInUnix.PathWithDollar}\"");
}
[MacOsOnlyFact]
public void ItCreatesThePathDFileOnMacOSWhenInvokedFromNativeInstaller()
{
var dotnetFirstTime = new DotNetFirstTime();
var command = dotnetFirstTime.Setup(Log, _testAssetsManager);
var pathsd = Path.Combine(dotnetFirstTime.TestDirectory, "paths.d");
command.Execute("internal-reportinstallsuccess", "test").Should().Pass();
File.Exists(pathsd).Should().BeTrue();
File.ReadAllText(pathsd).Should().Be(CliFolderPathCalculator.ToolsShimPathInUnix.PathWithTilde);
}
private string GetDotnetVersion()
{
return TestContext.Current.ToolsetUnderTest.SdkVersion;
}
}
}