Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DotnetNewTestTemplatesTests : BaseIntegrationTest

private static readonly ImmutableArray<string> SupportedTargetFrameworks =
[
"net10.0",
ToolsetInfo.CurrentTargetFramework
];

private static readonly (string ProjectTemplateName, string ItemTemplateName, string[] Languages, bool SupportsTestingPlatform)[] AvailableItemTemplates =
Expand Down Expand Up @@ -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())
Expand All @@ -66,7 +69,8 @@ static DotnetNewTestTemplatesTests()
.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
.WithWorkingDirectory(CreateTemporaryFolder())
.Execute()
.Should().ExitWith(0);
.Should()
.Pass();
}

[Theory]
Expand All @@ -80,19 +84,21 @@ public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework,
// Create new test project: dotnet new <projectTemplate> -n <testProjectName> -f <targetFramework> -lang <language>
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 <itemTemplate> -n <test> -lang <language> -o <testProjectName>
// Add test item to test project: dotnet new <itemTemplate> -n <test> -lang <language> -o <outputDirectory>
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)
{
Expand All @@ -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);
Expand All @@ -126,18 +134,19 @@ public void ProjectTemplate_CanBeInstalledAndTestsArePassing(string targetFramew
// Create new test project: dotnet new <projectTemplate> -n <testProjectName> -f <targetFramework> -lang <language>
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)
{
var result = new DotnetTestCommand(_log, false)
.WithWorkingDirectory(outputDirectory)
.Execute(outputDirectory);

result.Should().ExitWith(0);
result.Should().Pass();

result.StdOut.Should().Contain("Passed!");
result.StdOut.Should().MatchRegex(@"Passed:\s*1");
Expand All @@ -164,18 +173,19 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can
// Create new test project: dotnet new <projectTemplate> -n <testProjectName> -f <targetFramework> -lang <language> --coverage-tool <coverageTool> --test-runner <testRunner>
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)
{
var result = new DotnetTestCommand(_log, false)
.WithWorkingDirectory(outputDirectory)
.Execute(outputDirectory);

result.Should().ExitWith(0);
result.Should().Pass();

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