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-04-05 20:50:12 +00:00
|
|
|
|
.Execute($"console --debug:ephemeral-hive --skip-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-04-05 20:50:12 +00:00
|
|
|
|
.ExecuteWithCapturedOutput($"console --debug:ephemeral-hive --skip-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");
|
|
|
|
|
|
|
|
|
|
foreach (string cSharpTemplate in cSharpTemplates)
|
|
|
|
|
{
|
|
|
|
|
var projectFolder = Path.Combine(rootPath, cSharpTemplate + "1");
|
|
|
|
|
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)
|
|
|
|
|
{
|
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(projectFolder)
|
2017-04-05 20:50:12 +00:00
|
|
|
|
.Execute($"{projectType} --debug:ephemeral-hive --skip-restore")
|
2017-02-01 01:31:37 +00:00
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(projectFolder)
|
2017-04-03 17:45:35 +00:00
|
|
|
|
.Execute($"--configfile {repoRootNuGetConfig} --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
|
|
|
|
|
2017-03-23 18:21:39 +00:00
|
|
|
|
[Theory]
|
2017-03-23 19:54:07 +00:00
|
|
|
|
[InlineData("console", "RuntimeFrameworkVersion", "microsoft.netcore.app")]
|
|
|
|
|
[InlineData("classlib", "NetStandardImplicitPackageVersion", "netstandard.library")]
|
2017-03-23 18:21:39 +00:00
|
|
|
|
public void NewProjectRestoresCorrectPackageVersion(string type, string propertyName, string packageName)
|
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";
|
|
|
|
|
var expectedVersion = GetFrameworkPackageVersion();
|
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-04-05 20:50:12 +00:00
|
|
|
|
.Execute($"{type} --name {projectName} -o . --debug:ephemeral-hive --skip-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()
|
|
|
|
|
.Single(d => d.Name.StartsWith("2.0.0"));
|
|
|
|
|
|
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-03-23 19:54:07 +00:00
|
|
|
|
.Single(library => library.Name == packageName);
|
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
|
|
|
|
}
|
|
|
|
|
}
|