diff --git a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs index 36ef06516a93..33785fc116e0 100644 --- a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs +++ b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs @@ -11,7 +11,7 @@ public class DotnetNewTestTemplatesTests : BaseIntegrationTest private static readonly ImmutableArray SupportedTargetFrameworks = [ - "net10.0", + ToolsetInfo.CurrentTargetFramework ]; private static readonly (string ProjectTemplateName, string ItemTemplateName, string[] Languages, bool SupportsTestingPlatform)[] AvailableItemTemplates = @@ -50,13 +50,16 @@ public void WriteLine(string format, params object[] args) { } static DotnetNewTestTemplatesTests() { + // This is the live location of the build string templatePackagePath = Path.Combine( RepoTemplatePackages, - "Microsoft.DotNet.Common.ProjectTemplates.10.0", + $"Microsoft.DotNet.Common.ProjectTemplates.{ToolsetInfo.CurrentTargetFrameworkVersion}", "content"); var dummyLog = new NullTestOutputHelper(); + // Here we uninstall first, because we want to make sure we clean up before the installation + // i.e we want to make sure our installation is done new DotnetNewCommand(dummyLog, "uninstall", templatePackagePath) .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) .WithWorkingDirectory(CreateTemporaryFolder()) @@ -66,7 +69,8 @@ static DotnetNewTestTemplatesTests() .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) .WithWorkingDirectory(CreateTemporaryFolder()) .Execute() - .Should().ExitWith(0); + .Should() + .Pass(); } [Theory] @@ -80,19 +84,21 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, // Create new test project: dotnet new -n -f -lang string args = $"{projectTemplate} -n {testProjectName} -f {targetFramework} -lang {language} -o {outputDirectory}"; new DotnetNewCommand(_log, args) - .WithCustomHive(outputDirectory).WithRawArguments() - .WithWorkingDirectory(workingDirectory) - .Execute() - .Should().ExitWith(0); + .WithCustomHive(outputDirectory).WithRawArguments() + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should() + .Pass(); var itemName = "test"; - // Add test item to test project: dotnet new -n -lang -o + // Add test item to test project: dotnet new -n -lang -o new DotnetNewCommand(_log, $"{itemTemplate} -n {itemName} -lang {language} -o {outputDirectory}") .WithCustomHive(outputDirectory).WithRawArguments() .WithWorkingDirectory(workingDirectory) .Execute() - .Should().ExitWith(0); + .Should() + .Pass(); if (language == Languages.FSharp) { @@ -106,9 +112,11 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, .WithWorkingDirectory(outputDirectory) .Execute(outputDirectory); - result.Should().ExitWith(0); + result.Should().Pass(); result.StdOut.Should().Contain("Passed!"); + // We created another test class (which will contain 1 test), and we already have 1 test when we created the test project. + // Therefore, in total we would have 2. result.StdOut.Should().MatchRegex(@"Passed:\s*2"); Directory.Delete(outputDirectory, true); @@ -126,10 +134,11 @@ public void ProjectTemplate_CanBeInstalledAndTestsArePassing(string targetFramew // Create new test project: dotnet new -n -f -lang string args = $"{projectTemplate} -n {testProjectName} -f {targetFramework} -lang {language} -o {outputDirectory}"; new DotnetNewCommand(_log, args) - .WithCustomHive(outputDirectory).WithRawArguments() - .WithWorkingDirectory(workingDirectory) - .Execute() - .Should().ExitWith(0); + .WithCustomHive(outputDirectory).WithRawArguments() + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should() + .Pass(); if (runDotnetTest) { @@ -137,7 +146,7 @@ public void ProjectTemplate_CanBeInstalledAndTestsArePassing(string targetFramew .WithWorkingDirectory(outputDirectory) .Execute(outputDirectory); - result.Should().ExitWith(0); + result.Should().Pass(); result.StdOut.Should().Contain("Passed!"); result.StdOut.Should().MatchRegex(@"Passed:\s*1"); @@ -164,10 +173,11 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can // Create new test project: dotnet new -n -f -lang --coverage-tool --test-runner string args = $"{projectTemplate} -n {testProjectName} -f {targetFramework} -lang {language} -o {outputDirectory} --coverage-tool {coverageTool} --test-runner {testRunner}"; new DotnetNewCommand(_log, args) - .WithCustomHive(outputDirectory).WithRawArguments() - .WithWorkingDirectory(workingDirectory) - .Execute() - .Should().ExitWith(0); + .WithCustomHive(outputDirectory).WithRawArguments() + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should() + .Pass(); if (runDotnetTest) { @@ -175,7 +185,7 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can .WithWorkingDirectory(outputDirectory) .Execute(outputDirectory); - result.Should().ExitWith(0); + result.Should().Pass(); result.StdOut.Should().Contain("Passed!"); result.StdOut.Should().MatchRegex(@"Passed:\s*1");