Pinning the package version expected by NewProjectRestoresCorrectPackageVersion to 2.0.0.

This commit is contained in:
Livar Cunha 2017-09-06 15:40:31 -07:00
parent cbc87958cc
commit 093512a64e

View file

@ -75,14 +75,14 @@ namespace Microsoft.DotNet.New.Tests
} }
[Theory] [Theory]
[InlineData("console", "RuntimeFrameworkVersion", "microsoft.netcore.app")] [InlineData("console", "microsoft.netcore.app")]
[InlineData("classlib", "NetStandardImplicitPackageVersion", "netstandard.library")] [InlineData("classlib", "netstandard.library")]
public void NewProjectRestoresCorrectPackageVersion(string type, string propertyName, string packageName) public void NewProjectRestoresCorrectPackageVersion(string type, string packageName)
{ {
var rootPath = TestAssets.CreateTestDirectory(identifier: $"_{type}").FullName; var rootPath = TestAssets.CreateTestDirectory(identifier: $"_{type}").FullName;
var packagesDirectory = Path.Combine(rootPath, "packages"); var packagesDirectory = Path.Combine(rootPath, "packages");
var projectName = "Project"; var projectName = "Project";
var expectedVersion = GetFrameworkPackageVersion(); var expectedVersion = "2.0.0";
var repoRootNuGetConfig = Path.Combine(RepoDirectoriesProvider.RepoRoot, "NuGet.Config"); var repoRootNuGetConfig = Path.Combine(RepoDirectoriesProvider.RepoRoot, "NuGet.Config");
new NewCommand() new NewCommand()
@ -98,32 +98,6 @@ namespace Microsoft.DotNet.New.Tests
new DirectoryInfo(Path.Combine(packagesDirectory, packageName)) new DirectoryInfo(Path.Combine(packagesDirectory, packageName))
.Should().Exist() .Should().Exist()
.And.HaveDirectory(expectedVersion); .And.HaveDirectory(expectedVersion);
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"));
if (packageName == "microsoft.netcore.app")
{
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
.Single(library => string.Equals(library.Name, packageName, StringComparison.OrdinalIgnoreCase));
return dependency.Version;
}
}
} }
} }
} }