diff --git a/test/EndToEnd/ProjectBuildTests.cs b/test/EndToEnd/ProjectBuildTests.cs index d80b0874e..dfb829dbb 100644 --- a/test/EndToEnd/ProjectBuildTests.cs +++ b/test/EndToEnd/ProjectBuildTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -242,6 +243,47 @@ namespace EndToEnd.Tests } } + [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() + { + { "", ".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] [InlineData("wpf")] [InlineData("winforms")] @@ -396,20 +438,9 @@ namespace EndToEnd.Tests private static void TestTemplateCreateAndBuild(string templateName, bool build = true, bool selfContained = false, string language = "", string framework = "", bool deleteTestDirectory = false) { - DirectoryInfo directory = TestAssets.CreateTestDirectory(identifier: string.IsNullOrWhiteSpace(language) ? templateName : $"{templateName}[{language}]"); + DirectoryInfo directory = InstantiateProjectTemplate(templateName, language); string projectDirectory = directory.FullName; - string newArgs = $"{templateName} --no-restore"; - if (!string.IsNullOrWhiteSpace(language)) - { - newArgs += $" --language {language}"; - } - - new NewCommandShim() - .WithWorkingDirectory(projectDirectory) - .Execute(newArgs) - .Should().Pass(); - if (!string.IsNullOrWhiteSpace(framework)) { //check if MSBuild TargetFramework property for *proj is set to expected framework @@ -454,5 +485,27 @@ namespace EndToEnd.Tests directory.Delete(true); } } + + 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; + } } } diff --git a/test/SdkTests/SdkTests.csproj b/test/SdkTests/SdkTests.csproj index 769da7f5f..ed098d33d 100644 --- a/test/SdkTests/SdkTests.csproj +++ b/test/SdkTests/SdkTests.csproj @@ -226,6 +226,11 @@ $(TestArgs) -testConfigFile "$(MSBuildThisFileDirectory)TestsToSkipPortableLinux.xml" + + + $(TestArgs) -testConfigFile "$(MSBuildThisFileDirectory)TestsToSkipOSX.xml" + + diff --git a/test/SdkTests/TestsToSkipOSX.xml b/test/SdkTests/TestsToSkipOSX.xml new file mode 100644 index 000000000..09330bb1f --- /dev/null +++ b/test/SdkTests/TestsToSkipOSX.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + +