8000 Update tests for test templates (#49145) · dotnet/sdk@0eb6d4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0eb6d4a

Browse files
Update tests for test templates (#49145)
1 parent 12a7f16 commit 0eb6d4a

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class DotnetNewTestTemplatesTests : BaseIntegrationTest
1111

1212
private static readonly ImmutableArray<string> SupportedTargetFrameworks =
1313
[
14-
"net10.0",
14+
ToolsetInfo.CurrentTargetFramework
1515
];
1616

1717
private static readonly (string ProjectTemplateName, string ItemTemplateName, string[] Languages, bool SupportsTestingPlatform)[] AvailableItemTemplates =
@@ -50,13 +50,16 @@ public void WriteLine(string format, params object[] args) { }
5050

5151
static DotnetNewTestTemplatesTests()
5252
{
53+
// This is the live location of the build
5354
string templatePackagePath = Path.Combine(
5455
RepoTemplatePackages,
55-
"Microsoft.DotNet.Common.ProjectTemplates.10.0",
56+
$"Microsoft.DotNet.Common.ProjectTemplates.{ToolsetInfo.CurrentTargetFrameworkVersion}",
5657
"content");
5758

5859
var dummyLog = new NullTestOutputHelper();
5960

61+
// Here we uninstall first, because we want to make sure we clean up before the installation
62+
// i.e we want to make sure our installation is done
6063
new DotnetNewCommand(dummyLog, "uninstall", templatePackagePath)
6164
.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
6265
.WithWorkingDirectory(CreateTemporaryFolder())
@@ -66,7 +69,8 @@ static DotnetNewTestTemplatesTests()
6669
.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
6770
.WithWorkingDirectory(CreateTemporaryFolder())
6871
.Execute()
69-
.Should().ExitWith(0);
72+
.Should()
73+
.Pass();
7074
}
7175

7276
[Theory]
@@ -80,19 +84,21 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework,
8084
// Create new test project: dotnet new <projectTemplate> -n <testProjectName> -f <targetFramework> -lang <language>
8185
string args = $"{projectTemplate} -n {testProjectName} -f {targetFramework} -lang {language} -o {outputDirectory}";
8286
new DotnetNewCommand(_log, args)
83-
.WithCustomHive(outputDirectory).WithRawArguments()
84-
.WithWorkingDirectory(workingDirectory)
85-
.Execute()
86-
.Should().ExitWith(0);
87+
.WithCustomHive(outputDirectory).WithRawArguments()
88+
.WithWorkingDirectory(workingDirectory)
89+
.Execute()
90+
.Should()
91+
.Pass();
8792

8893
var itemName = "test";
8994

90-
// Add test item to test project: dotnet new <itemTemplate> -n <test> -lang <language> -o <testProjectName>
95+
// Add test item to test project: dotnet new <itemTemplate> -n <test> -lang <language> -o <outputDirectory>
9196
new DotnetNewCommand(_log, $"{itemTemplate} -n {itemName} -lang {language} -o {outputDirectory}")
9297
.WithCustomHive(outputDirectory).WithRawArguments()
9398
.WithWorkingDirectory(workingDirectory)
9499
.Execute()
95-
.Should().ExitWith(0);
100+
.Should()
101+
.Pass();
96102

97103
if (language == Languages.FSharp)
98104
{
@@ -106,9 +112,11 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework,
106112
.WithWorkingDirectory(outputDirectory)
107113
.Execute(outputDirectory);
108114

109-
result.Should().ExitWith(0);
115+
result.Should().Pass();
110116

111117
result.StdOut.Should().Contain("Passed!");
118+
// We created another test class (which will contain 1 test), and we already have 1 test when we created the test project.
119+
// Therefore, in total we would have 2.
112120
result.StdOut.Should().MatchRegex(@"Passed:\s*2");
113121

114122
Directory.Delete(outputDirectory, true);
@@ -126,18 +134,19 @@ public void ProjectTemplate_CanBeInstalledAndTestsArePassing(string targetFramew
126134
// Create new test project: dotnet new <projectTemplate> -n <testProjectName> -f <targetFramework> -lang <language>
127135
string args = $"{projectTemplate} -n {testProjectName} -f {targetFramework} -lang {language} -o {outputDirectory}";
128136
new DotnetNewCommand(_log, args)
129-
.WithCustomHive(outputDirectory).WithRawArguments()
130-
.WithWorkingDirectory(workingDirectory)
131-
.Execute()
132-
.Should().ExitWith(0);
137+
.WithCustomHive(outputDirectory).WithRawArguments()
138+
.WithWorkingDirectory(workingDirectory)
139+
.Execute()
140+
.Should()
141+
.Pass();
133142

134143
if (runDotnetTest)
135144
6D4E {
136145
var result = new DotnetTestCommand(_log, false)
137146
.WithWorkingDirectory(outputDirectory)
138147
.Execute(outputDirectory);
139148

140-
result.Should().ExitWith(0);
149+
result.Should().Pass();
141150

142151
result.StdOut.Should().Contain("Passed!");
143152
result.StdOut.Should().MatchRegex(@"Passed:\s*1");
@@ -164,18 +173,19 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can
164173
// Create new test project: dotnet new <projectTemplate> -n <testProjectName> -f <targetFramework> -lang <language> --coverage-tool <coverageTool> --test-runner <testRunner>
165174
string args = $"{projectTemplate} -n {testProjectName} -f {targetFramework} -lang {language} -o {outputDirectory} --coverage-tool {coverageTool} --test-runner {testRunner}";
166175
new DotnetNewCommand(_log, args)
167-
.WithCustomHive(outputDirectory).WithRawArguments()
168-
.WithWorkingDirectory(workingDirectory)
169-
.Execute()
170-
.Should().ExitWith(0);
176+
.WithCustomHive(outputDirectory).WithRawArguments()
177+
.WithWorkingDirectory(workingDirectory)
178+
.Execute()
179+
.Should()
180+
.Pass();
171181

172182
if (runDotnetTest)
173183
{
174184
var result = new DotnetTestCommand(_log, false)
175185
.WithWorkingDirectory(outputDirectory)
176186
.Execute(outputDirectory);
177187

178-
result.Should().ExitWith(0);
188+
result.Should().Pass();
179189

180190
result.StdOut.Should().Contain("Passed!");
181191
result.StdOut.Should().MatchRegex(@"Passed:\s*1");

0 commit comments

Comments
 (0)
0