Adding a test that restores all c# templates and checks that none of them depend on a package produced by the CLI. I had to write this as a single test for all templates because it cuts the test time in about half to restore all the packages at once to the same folder than to clean and restore again everytime per template.

This commit is contained in:
Livar Cunha 2016-12-09 16:11:57 -08:00
parent 08527184b2
commit e1965327e0

View file

@ -21,7 +21,7 @@ namespace Microsoft.DotNet.New.Tests
[InlineData("Web", true)]
[InlineData("Mstest", false)]
[InlineData("XUnittest", false)]
public void When_dotnet_build_is_invoked_then_project_restores_and_builds_without_warnings(
public void ICanRestoreBuildAndPublishTheAppWithoutWarnings(
string projectType,
bool useNuGetConfigForAspNet)
{
@ -36,15 +36,56 @@ namespace Microsoft.DotNet.New.Tests
File.Copy("NuGet.tempaspnetpatch.config", Path.Combine(rootPath, "NuGet.Config"));
}
new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute($"restore /p:SkipInvalidConfigurations=true")
new RestoreCommand()
.WithWorkingDirectory(rootPath)
.Execute("/p:SkipInvalidConfigurations=true")
.Should().Pass();
var buildResult = new TestCommand("dotnet")
new BuildCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput("build")
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.NotHaveStdErr();
new PublishCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.NotHaveStdErr();
}
[Fact]
public void RestoreDoesNotUseAnyCliProducedPackagesOnItsTemplates()
{
var cSharpTemplates = new [] { "Console", "Lib", "Web", "Mstest", "XUnittest" };
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
var packagesDirectory = Path.Combine(rootPath, "packages");
foreach (var cSharpTemplate in cSharpTemplates)
{
var projectFolder = Path.Combine(rootPath, cSharpTemplate);
Directory.CreateDirectory(projectFolder);
CreateAndRestoreNewProject(cSharpTemplate, projectFolder, packagesDirectory);
}
Directory.EnumerateFiles(packagesDirectory, $"*.nupkg", SearchOption.AllDirectories)
.Should().NotContain(p => p.Contains("Microsoft.DotNet.Cli.Utils"));
}
private void CreateAndRestoreNewProject(
string projectType,
string projectFolder,
string packagesDirectory)
{
new TestCommand("dotnet") { WorkingDirectory = projectFolder }
.Execute($"new --type {projectType}")
.Should().Pass();
new RestoreCommand()
.WithWorkingDirectory(projectFolder)
.Execute($"--packages {packagesDirectory} /p:SkipInvalidConfigurations=true")
.Should().Pass();
}
}
}