add tests for covering adding item templates (C# and VB) (#15343)
This commit is contained in:
parent
9c8f564d9e
commit
7da88e07cc
1 changed files with 69 additions and 16 deletions
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
@ -115,7 +116,7 @@ namespace EndToEnd.Tests
|
||||||
.Execute(newArgs)
|
.Execute(newArgs)
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
string publishArgs="-r win-arm64";
|
string publishArgs = "-r win-arm64";
|
||||||
new PublishCommand()
|
new PublishCommand()
|
||||||
.WithWorkingDirectory(projectDirectory)
|
.WithWorkingDirectory(projectDirectory)
|
||||||
.Execute(publishArgs)
|
.Execute(publishArgs)
|
||||||
|
@ -149,7 +150,7 @@ namespace EndToEnd.Tests
|
||||||
.Execute(newArgs)
|
.Execute(newArgs)
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
string publishArgs="-r win-arm64";
|
string publishArgs = "-r win-arm64";
|
||||||
new PublishCommand()
|
new PublishCommand()
|
||||||
.WithWorkingDirectory(projectDirectory)
|
.WithWorkingDirectory(projectDirectory)
|
||||||
.Execute(publishArgs)
|
.Execute(publishArgs)
|
||||||
|
@ -248,6 +249,47 @@ namespace EndToEnd.Tests
|
||||||
Assert.True(directory.EnumerateFileSystemInfos().Any());
|
Assert.True(directory.EnumerateFileSystemInfos().Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
// microsoft.dotnet.common.itemtemplates templates
|
||||||
|
[InlineData("class")]
|
||||||
|
[InlineData("struct")]
|
||||||
|
[InlineData("enum")]
|
||||||
|
[InlineData("record")]
|
||||||
|
[InlineData("interface")]
|
||||||
|
[InlineData("class", "C#")]
|
||||||
|
[InlineData("class", "VB")]
|
||||||
|
[InlineData("struct", "VB")]
|
||||||
|
[InlineData("enum", "VB")]
|
||||||
|
[InlineData("interface", "VB")]
|
||||||
|
public void ItCanCreateItemTemplateWithProjectRestriction(string templateName, string language = "")
|
||||||
|
{
|
||||||
|
var languageExtensionMap = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "", ".cs" },
|
||||||
|
{ "C#", ".cs" },
|
||||||
|
{ "VB", ".vb" }
|
||||||
|
};
|
||||||
|
|
||||||
|
DirectoryInfo directory = InstantiateProjectTemplate("classlib", language, withNoRestore: false);
|
||||||
|
string projectDirectory = directory.FullName;
|
||||||
|
string expectedItemName = $"TestItem_{templateName}";
|
||||||
|
string newArgs = $"{templateName} --name {expectedItemName} --debug:ephemeral-hive";
|
||||||
|
if (!string.IsNullOrWhiteSpace(language))
|
||||||
|
{
|
||||||
|
newArgs += $" --language {language}";
|
||||||
|
}
|
||||||
|
|
||||||
|
new NewCommandShim()
|
||||||
|
.WithWorkingDirectory(projectDirectory)
|
||||||
|
.Execute(newArgs)
|
||||||
|
.Should().Pass();
|
||||||
|
|
||||||
|
//check if the template created files
|
||||||
|
Assert.True(directory.Exists);
|
||||||
|
Assert.True(directory.EnumerateFileSystemInfos().Any());
|
||||||
|
Assert.True(directory.GetFile($"{expectedItemName}.{languageExtensionMap[language]}") != null);
|
||||||
|
}
|
||||||
|
|
||||||
[WindowsOnlyTheory]
|
[WindowsOnlyTheory]
|
||||||
[InlineData("wpf", Skip = "https://github.com/dotnet/wpf/issues/2363")]
|
[InlineData("wpf", Skip = "https://github.com/dotnet/wpf/issues/2363")]
|
||||||
[InlineData("winforms", Skip = "https://github.com/dotnet/wpf/issues/2363")]
|
[InlineData("winforms", Skip = "https://github.com/dotnet/wpf/issues/2363")]
|
||||||
|
@ -402,20 +444,9 @@ namespace EndToEnd.Tests
|
||||||
|
|
||||||
private static void TestTemplateCreateAndBuild(string templateName, bool build = true, bool selfContained = false, string language = "", string framework = "")
|
private static void TestTemplateCreateAndBuild(string templateName, bool build = true, bool selfContained = false, string language = "", string framework = "")
|
||||||
{
|
{
|
||||||
DirectoryInfo directory = TestAssets.CreateTestDirectory(identifier: string.IsNullOrWhiteSpace(language) ? templateName : $"{templateName}[{language}]");
|
DirectoryInfo directory = InstantiateProjectTemplate(templateName, language);
|
||||||
string projectDirectory = directory.FullName;
|
string projectDirectory = directory.FullName;
|
||||||
|
|
||||||
string newArgs = $"{templateName} --debug:ephemeral-hive --no-restore";
|
|
||||||
if (!string.IsNullOrWhiteSpace(language))
|
|
||||||
{
|
|
||||||
newArgs += $" --language {language}";
|
|
||||||
}
|
|
||||||
|
|
||||||
new NewCommandShim()
|
|
||||||
.WithWorkingDirectory(projectDirectory)
|
|
||||||
.Execute(newArgs)
|
|
||||||
.Should().Pass();
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(framework))
|
if (!string.IsNullOrWhiteSpace(framework))
|
||||||
{
|
{
|
||||||
//check if MSBuild TargetFramework property for *proj is set to expected framework
|
//check if MSBuild TargetFramework property for *proj is set to expected framework
|
||||||
|
@ -454,5 +485,27 @@ namespace EndToEnd.Tests
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DirectoryInfo InstantiateProjectTemplate(string templateName, string language = "", bool withNoRestore = true)
|
||||||
|
{
|
||||||
|
DirectoryInfo directory = TestAssets.CreateTestDirectory(
|
||||||
|
identifier: string.IsNullOrWhiteSpace(language)
|
||||||
|
? templateName
|
||||||
|
: $"{templateName}[{language}]");
|
||||||
|
string projectDirectory = directory.FullName;
|
||||||
|
|
||||||
|
string newArgs = $"{templateName} --debug:ephemeral-hive {(withNoRestore ? "--no-restore" : "")}";
|
||||||
|
if (!string.IsNullOrWhiteSpace(language))
|
||||||
|
{
|
||||||
|
newArgs += $" --language {language}";
|
||||||
|
}
|
||||||
|
|
||||||
|
new NewCommandShim()
|
||||||
|
.WithWorkingDirectory(projectDirectory)
|
||||||
|
.Execute(newArgs)
|
||||||
|
.Should().Pass();
|
||||||
|
|
||||||
|
return directory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue