2017-02-01 01:31:37 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
2016-12-13 22:15:35 +00:00
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-02-10 20:14:04 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml.Linq;
|
2016-12-13 22:15:35 +00:00
|
|
|
|
using FluentAssertions;
|
2017-02-10 20:14:04 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2017-03-23 18:21:39 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyModel;
|
2017-01-06 22:48:27 +00:00
|
|
|
|
using Xunit;
|
2016-12-13 22:15:35 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.New.Tests
|
|
|
|
|
{
|
|
|
|
|
public class GivenThatIWantANewApp : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail()
|
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var rootPath = TestAssets.CreateTestDirectory().FullName;
|
2016-12-13 22:15:35 +00:00
|
|
|
|
|
2017-02-10 20:14:04 +00:00
|
|
|
|
new NewCommand()
|
|
|
|
|
.WithWorkingDirectory(rootPath)
|
2017-07-10 22:57:30 +00:00
|
|
|
|
.Execute($"console --debug:ephemeral-hive --no-restore");
|
2016-12-13 22:15:35 +00:00
|
|
|
|
|
|
|
|
|
DateTime expectedState = Directory.GetLastWriteTime(rootPath);
|
|
|
|
|
|
2017-02-10 20:14:04 +00:00
|
|
|
|
var result = new NewCommand()
|
|
|
|
|
.WithWorkingDirectory(rootPath)
|
2017-07-10 22:57:30 +00:00
|
|
|
|
.ExecuteWithCapturedOutput($"console --debug:ephemeral-hive --no-restore");
|
2016-12-13 22:15:35 +00:00
|
|
|
|
|
|
|
|
|
DateTime actualState = Directory.GetLastWriteTime(rootPath);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(expectedState, actualState);
|
|
|
|
|
|
2017-02-01 01:31:37 +00:00
|
|
|
|
result.Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RestoreDoesNotUseAnyCliProducedPackagesOnItsTemplates()
|
|
|
|
|
{
|
|
|
|
|
string[] cSharpTemplates = new[] { "console", "classlib", "mstest", "xunit", "web", "mvc", "webapi" };
|
|
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var rootPath = TestAssets.CreateTestDirectory().FullName;
|
2017-02-01 01:31:37 +00:00
|
|
|
|
var packagesDirectory = Path.Combine(rootPath, "packages");
|
|
|
|
|
|
2018-02-07 17:59:13 +00:00
|
|
|
|
var configFile = Path.Combine(RepoDirectoriesProvider.RepoRoot, "NuGet.Config");
|
2017-08-29 22:21:13 +00:00
|
|
|
|
|
2017-02-01 01:31:37 +00:00
|
|
|
|
foreach (string cSharpTemplate in cSharpTemplates)
|
|
|
|
|
{
|
|
|
|
|
var projectFolder = Path.Combine(rootPath, cSharpTemplate + "1");
|
|
|
|
|
Directory.CreateDirectory(projectFolder);
|
2017-08-29 22:21:13 +00:00
|
|
|
|
CreateAndRestoreNewProject(cSharpTemplate, projectFolder, packagesDirectory, configFile);
|
2017-02-01 01:31:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Directory.EnumerateFiles(packagesDirectory, $"*.nupkg", SearchOption.AllDirectories)
|
|
|
|
|
.Should().NotContain(p => p.Contains("Microsoft.DotNet.Cli.Utils"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateAndRestoreNewProject(
|
|
|
|
|
string projectType,
|
|
|
|
|
string projectFolder,
|
2017-08-29 22:21:13 +00:00
|
|
|
|
string packagesDirectory,
|
|
|
|
|
string configFile)
|
2017-02-01 01:31:37 +00:00
|
|
|
|
{
|
2017-02-10 20:14:04 +00:00
|
|
|
|
new NewCommand()
|
|
|
|
|
.WithWorkingDirectory(projectFolder)
|
2017-07-10 22:57:30 +00:00
|
|
|
|
.Execute($"{projectType} --debug:ephemeral-hive --no-restore")
|
2017-02-01 01:31:37 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(projectFolder)
|
2017-08-29 22:21:13 +00:00
|
|
|
|
.Execute($"--configfile {configFile} --packages {packagesDirectory}")
|
2017-02-01 01:31:37 +00:00
|
|
|
|
.Should().Pass();
|
2016-12-13 22:15:35 +00:00
|
|
|
|
}
|
2017-02-10 20:14:04 +00:00
|
|
|
|
|
2018-05-24 22:41:03 +00:00
|
|
|
|
// Remove the expectedVersion parameter once we have templates targetting netcoreapp2.2.
|
2017-03-23 18:21:39 +00:00
|
|
|
|
[Theory]
|
2018-08-04 03:02:55 +00:00
|
|
|
|
[InlineData("console", "microsoft.netcore.app", null)]
|
2018-07-31 23:39:48 +00:00
|
|
|
|
[InlineData("classlib", "netstandard.library", "2.0.3")] // FIXME: This is pinned to 2.0.3 due to https://github.com/dotnet/sdk/issues/2410
|
2018-05-24 22:41:03 +00:00
|
|
|
|
public void NewProjectRestoresCorrectPackageVersion(string type, string packageName, string expectedVersion)
|
2017-02-10 20:14:04 +00:00
|
|
|
|
{
|
2017-03-28 00:46:32 +00:00
|
|
|
|
var rootPath = TestAssets.CreateTestDirectory(identifier: $"_{type}").FullName;
|
2017-02-10 20:14:04 +00:00
|
|
|
|
var packagesDirectory = Path.Combine(rootPath, "packages");
|
2017-03-23 18:21:39 +00:00
|
|
|
|
var projectName = "Project";
|
2018-05-24 22:41:03 +00:00
|
|
|
|
expectedVersion = expectedVersion ?? GetFrameworkPackageVersion();
|
2017-12-18 17:51:07 +00:00
|
|
|
|
|
2017-04-03 17:45:35 +00:00
|
|
|
|
var repoRootNuGetConfig = Path.Combine(RepoDirectoriesProvider.RepoRoot, "NuGet.Config");
|
2017-02-10 20:14:04 +00:00
|
|
|
|
|
|
|
|
|
new NewCommand()
|
|
|
|
|
.WithWorkingDirectory(rootPath)
|
2017-07-10 22:57:30 +00:00
|
|
|
|
.Execute($"{type} --name {projectName} -o . --debug:ephemeral-hive --no-restore")
|
2017-02-10 20:14:04 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(rootPath)
|
2017-04-03 17:45:35 +00:00
|
|
|
|
.Execute($"--configfile {repoRootNuGetConfig} --packages {packagesDirectory}")
|
2017-02-10 20:14:04 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
2017-03-23 18:21:39 +00:00
|
|
|
|
new DirectoryInfo(Path.Combine(packagesDirectory, packageName))
|
2017-02-10 20:14:04 +00:00
|
|
|
|
.Should().Exist()
|
|
|
|
|
.And.HaveDirectory(expectedVersion);
|
2017-03-23 18:21:39 +00:00
|
|
|
|
|
|
|
|
|
string GetFrameworkPackageVersion()
|
|
|
|
|
{
|
|
|
|
|
var dotnetDir = new FileInfo(DotnetUnderTest.FullName).Directory;
|
|
|
|
|
var sharedFxDir = dotnetDir
|
|
|
|
|
.GetDirectory("shared", "Microsoft.NETCore.App")
|
|
|
|
|
.EnumerateDirectories()
|
2018-05-24 22:41:03 +00:00
|
|
|
|
.Single(d => d.Name.StartsWith("2.2.0"));
|
2017-03-23 18:21:39 +00:00
|
|
|
|
|
2017-03-23 19:54:07 +00:00
|
|
|
|
if (packageName == "microsoft.netcore.app")
|
2017-03-23 18:21:39 +00:00
|
|
|
|
{
|
|
|
|
|
return sharedFxDir.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var depsFile = Path.Combine(sharedFxDir.FullName, "Microsoft.NETCore.App.deps.json");
|
|
|
|
|
using (var stream = File.OpenRead(depsFile))
|
|
|
|
|
using (var reader = new DependencyContextJsonReader())
|
|
|
|
|
{
|
|
|
|
|
var context = reader.Read(stream);
|
|
|
|
|
var dependency = context
|
|
|
|
|
.RuntimeLibraries
|
2017-05-03 02:00:24 +00:00
|
|
|
|
.Single(library => string.Equals(library.Name, packageName, StringComparison.OrdinalIgnoreCase));
|
2017-03-23 18:21:39 +00:00
|
|
|
|
|
|
|
|
|
return dependency.Version;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-10 20:14:04 +00:00
|
|
|
|
}
|
2016-12-13 22:15:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|