From a1d537f84d8545d739ec18f0436786fcd70f6468 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 26 May 2025 11:22:52 +0200 Subject: [PATCH 1/3] Update tests --- .../DotnetNewTestTemplatesTests.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs index 36ef06516a93..fcf1a4fa6ff8 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 = @@ -52,7 +52,7 @@ static DotnetNewTestTemplatesTests() { string templatePackagePath = Path.Combine( RepoTemplatePackages, - "Microsoft.DotNet.Common.ProjectTemplates.10.0", + "Microsoft.DotNet.Common.ProjectTemplates." + ToolsetInfo.CurrentTargetFrameworkVersion, "content"); var dummyLog = new NullTestOutputHelper(); @@ -66,7 +66,7 @@ static DotnetNewTestTemplatesTests() .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) .WithWorkingDirectory(CreateTemporaryFolder()) .Execute() - .Should().ExitWith(0); + .Should().Pass(); } [Theory] @@ -83,16 +83,16 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, .WithCustomHive(outputDirectory).WithRawArguments() .WithWorkingDirectory(workingDirectory) .Execute() - .Should().ExitWith(0); + .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,7 +106,7 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, .WithWorkingDirectory(outputDirectory) .Execute(outputDirectory); - result.Should().ExitWith(0); + result.Should().Pass(); result.StdOut.Should().Contain("Passed!"); result.StdOut.Should().MatchRegex(@"Passed:\s*2"); @@ -129,7 +129,7 @@ public void ProjectTemplate_CanBeInstalledAndTestsArePassing(string targetFramew .WithCustomHive(outputDirectory).WithRawArguments() .WithWorkingDirectory(workingDirectory) .Execute() - .Should().ExitWith(0); + .Should().Pass(); if (runDotnetTest) { @@ -137,7 +137,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"); @@ -167,7 +167,7 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can .WithCustomHive(outputDirectory).WithRawArguments() .WithWorkingDirectory(workingDirectory) .Execute() - .Should().ExitWith(0); + .Should().Pass(); if (runDotnetTest) { @@ -175,7 +175,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"); From 11ffff730b7b1122e4ae386eb9c61cfd661925cd Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 26 May 2025 11:25:39 +0200 Subject: [PATCH 2/3] apply suggestion --- test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs index fcf1a4fa6ff8..bc3c6e75da75 100644 --- a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs +++ b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs @@ -52,7 +52,7 @@ static DotnetNewTestTemplatesTests() { string templatePackagePath = Path.Combine( RepoTemplatePackages, - "Microsoft.DotNet.Common.ProjectTemplates." + ToolsetInfo.CurrentTargetFrameworkVersion, + $"Microsoft.DotNet.Common.ProjectTemplates.{ToolsetInfo.CurrentTargetFrameworkVersion}", "content"); var dummyLog = new NullTestOutputHelper(); From 3df91b3f62c6a199dc4ec84c93eb3cb97f54f6d8 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 26 May 2025 12:03:36 +0200 Subject: [PATCH 3/3] Add comments --- .../DotnetNewTestTemplatesTests.cs | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs index bc3c6e75da75..33785fc116e0 100644 --- a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs +++ b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs @@ -50,6 +50,7 @@ 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.{ToolsetInfo.CurrentTargetFrameworkVersion}", @@ -57,6 +58,8 @@ static DotnetNewTestTemplatesTests() 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().Pass(); + .Should() + .Pass(); } [Theory] @@ -80,10 +84,11 @@ 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().Pass(); + .WithCustomHive(outputDirectory).WithRawArguments() + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should() + .Pass(); var itemName = "test"; @@ -92,7 +97,8 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, .WithCustomHive(outputDirectory).WithRawArguments() .WithWorkingDirectory(workingDirectory) .Execute() - .Should().Pass(); + .Should() + .Pass(); if (language == Languages.FSharp) { @@ -109,6 +115,8 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, 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().Pass(); + .WithCustomHive(outputDirectory).WithRawArguments() + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should() + .Pass(); if (runDotnetTest) { @@ -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().Pass(); + .WithCustomHive(outputDirectory).WithRawArguments() + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should() + .Pass(); if (runDotnetTest) {