From f0a50c92ac2ef7a04b6dbcf134ebe87b3bbbfaac Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Mon, 26 Sep 2016 13:47:55 -0700 Subject: [PATCH] Fixing issues small issues found during build and tests. --- .../project.json | 2 +- .../Compilation/LibraryExporter.cs | 3 + .../Graph/LockFileExtensions.cs | 6 +- .../LibraryDescription.cs | 29 ++++- .../ProjectReader.cs | 7 +- .../Resolution/ProjectDependencyProvider.cs | 2 +- .../commands/dotnet-pack/PackageGenerator.cs | 13 +- .../Helpers/DependencyTypeChangeFinder.cs | 6 +- .../GivenAProjectToolsCommandResolver.cs | 5 +- .../project.json | 8 +- ...hatIWantToCreateFileCollectionsFromJson.cs | 2 - .../GivenThatIWantToLoadAProjectJsonFile.cs | 33 +++-- .../LibraryExporterPackageTests.cs | 62 ++++----- .../LockFilePatchingTests.cs | 95 ++------------ .../LockFileReaderTests.cs | 120 ------------------ .../PackageDependencyProviderTests.cs | 13 +- .../ProjectContextBuilderTests.cs | 6 +- .../project.json | 3 +- 18 files changed, 122 insertions(+), 293 deletions(-) delete mode 100644 test/Microsoft.DotNet.ProjectModel.Tests/LockFileReaderTests.cs diff --git a/src/Microsoft.DotNet.Compiler.Common/project.json b/src/Microsoft.DotNet.Compiler.Common/project.json index d527346ba..ce94b9421 100644 --- a/src/Microsoft.DotNet.Compiler.Common/project.json +++ b/src/Microsoft.DotNet.Compiler.Common/project.json @@ -14,7 +14,7 @@ "Microsoft.DotNet.Files": { "target": "project" }, - "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.9" + "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15" }, "frameworks": { "net451": { diff --git a/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs b/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs index d9ead1959..5f16dc6f6 100644 --- a/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs +++ b/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs @@ -212,13 +212,16 @@ namespace Microsoft.DotNet.ProjectModel.Compilation var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage(); var languageGroups = library.ContentFiles.GroupBy(file => file.CodeLanguage); + var selectedGroup = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ?? + languageGroups.FirstOrDefault(g => g.Key == "any") ?? languageGroups.FirstOrDefault(g => g.Key == null); if (selectedGroup != null) { foreach (var contentFile in selectedGroup) { if (contentFile.CodeLanguage != null && + contentFile.CodeLanguage != "any" && string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0) { continue; diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileExtensions.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileExtensions.cs index be97d3de8..175e66679 100644 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileExtensions.cs +++ b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileExtensions.cs @@ -29,6 +29,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph // The lock file should contain dependencies for each framework plus dependencies shared by all frameworks if (lockFile.ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1) { + Console.WriteLine($"Different count; {lockFile.ProjectFileDependencyGroups.Count} != {actualTargetFrameworks.Count() + 1}"); return false; } @@ -38,7 +39,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph var expectedDependencies = group.Dependencies.OrderBy(x => x); // If the framework name is empty, the associated dependencies are shared by all frameworks - if (group.FrameworkName == null) + if (string.IsNullOrEmpty(group.FrameworkName)) { actualDependencies = project.Dependencies .Select(d => d.LibraryRange.ToLockFileDependencyGroupString()) @@ -47,7 +48,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph else { var framework = actualTargetFrameworks - .FirstOrDefault(f => Equals(f.FrameworkName, group.FrameworkName)); + .FirstOrDefault(f => Equals(f.FrameworkName.DotNetFrameworkName, group.FrameworkName)); if (framework == null) { return false; @@ -60,6 +61,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph if (!actualDependencies.SequenceEqual(expectedDependencies)) { + Console.WriteLine($"ActualDependencies don't match"); return false; } } diff --git a/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs b/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs index 6355984dd..10152c2a0 100644 --- a/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs +++ b/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; using System.Linq; +using Microsoft.DotNet.PlatformAbstractions; using NuGet.Frameworks; using NuGet.LibraryModel; @@ -33,7 +35,8 @@ namespace Microsoft.DotNet.ProjectModel public LibraryIdentity Identity { get; } public string Hash { get; } - public HashSet RequestedRanges { get; } = new HashSet(); + public HashSet RequestedRanges { get; } = + new HashSet(new LibraryRangeEqualityComparer()); public List Parents { get; } = new List(); public string Path { get; } public IEnumerable Dependencies { get; } @@ -46,5 +49,29 @@ namespace Microsoft.DotNet.ProjectModel { return $"{Identity} ({Identity.Type}) = {Path}"; } + + // For diagnostics, we don't want to duplicate requested dependencies so we + // dedupe dependencies defined in project.json + private class LibraryRangeEqualityComparer : IEqualityComparer + { + public bool Equals(ProjectLibraryDependency x, ProjectLibraryDependency y) + { + return x.Equals(y) && + x.SourceColumn == y.SourceColumn && + x.SourceLine == y.SourceLine && + string.Equals(x.SourceFilePath, y.SourceFilePath, StringComparison.Ordinal); + } + + public int GetHashCode(ProjectLibraryDependency obj) + { + var combiner = HashCodeCombiner.Start(); + combiner.Add(obj); + combiner.Add(obj.SourceFilePath); + combiner.Add(obj.SourceLine); + combiner.Add(obj.SourceColumn); + + return combiner.CombinedHash; + } + } } } diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs b/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs index 091076c88..f1bcc4305 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs @@ -278,7 +278,7 @@ namespace Microsoft.DotNet.ProjectModel var dependencyValue = dependency.Value; var dependencyTypeValue = LibraryDependencyType.Default; - var target = isGacOrFrameworkReference ? LibraryDependencyTarget.Reference: LibraryDependencyTarget.None; + var target = isGacOrFrameworkReference ? LibraryDependencyTarget.Reference : LibraryDependencyTarget.All; string dependencyVersionAsString = null; if (dependencyValue.Type == JTokenType.Object) @@ -334,7 +334,10 @@ namespace Microsoft.DotNet.ProjectModel dependency.Key, dependencyVersionRange, target), - Type = dependencyTypeValue + Type = dependencyTypeValue, + SourceFilePath = projectPath, + SourceLine = lineInfo.LineNumber, + SourceColumn = lineInfo.LinePosition }); } } diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs index 0b9cb615c..192b03c33 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs @@ -95,7 +95,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution if (!dependencies.Any(dep => string.Equals(dep.Name, dependencyName, StringComparison.OrdinalIgnoreCase))) { dependencies.Add(new ProjectLibraryDependency { - LibraryRange = new LibraryRange(dependencyName, LibraryDependencyTarget.All) + LibraryRange = new LibraryRange(dependencyName, LibraryDependencyTarget.Reference) }); } } diff --git a/src/dotnet/commands/dotnet-pack/PackageGenerator.cs b/src/dotnet/commands/dotnet-pack/PackageGenerator.cs index 62873dd6f..9d88b1df6 100644 --- a/src/dotnet/commands/dotnet-pack/PackageGenerator.cs +++ b/src/dotnet/commands/dotnet-pack/PackageGenerator.cs @@ -124,7 +124,10 @@ namespace Microsoft.DotNet.Tools.Compiler if (Project.PackOptions.PackInclude != null) { - var files = IncludeFilesResolver.GetIncludeFiles(Project.PackOptions.PackInclude, "/", diagnostics: packDiagnostics); + var files = IncludeFilesResolver.GetIncludeFiles( + Project.PackOptions.PackInclude, + "/", + diagnostics: packDiagnostics); PackageBuilder.Files.AddRange(GetPackageFiles(files, packDiagnostics)); } else if (Project.Files.PackInclude != null && Project.Files.PackInclude.Any()) @@ -300,9 +303,10 @@ namespace Microsoft.DotNet.Tools.Compiler { continue; } - + // TODO: Efficiency - var dependencyDescription = context.LibraryManager.GetLibraries().First(l => l.RequestedRanges.Contains(dependency)); + var dependencyDescription = + context.LibraryManager.GetLibraries().First(l => l.RequestedRanges.Contains(dependency)); // REVIEW: Can we get this far with unresolved dependencies if (dependencyDescription == null || !dependencyDescription.Resolved) @@ -318,7 +322,8 @@ namespace Microsoft.DotNet.Tools.Compiler if (dependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference) { - PackageBuilder.FrameworkAssemblies.Add(new FrameworkAssemblyReference(dependency.Name, new[] { context.TargetFramework })); + PackageBuilder.FrameworkAssemblies.Add( + new FrameworkAssemblyReference(dependency.Name, new[] { context.TargetFramework })); Reporter.Verbose.WriteLine($"Adding framework assembly {dependency.Name.Yellow()}"); } diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs index eed52c0b9..da48518fc 100644 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs +++ b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs @@ -54,10 +54,10 @@ namespace Microsoft.DotNet.ProjectModel.Server.Helpers return new DiagnosticMessage( ErrorCodes.NU1010, $"The type of dependency {library.Identity.Name} was changed.", - string.Empty, + libraryRange.SourceFilePath, DiagnosticMessageSeverity.Error, - 0, - 0, + libraryRange.SourceLine, + libraryRange.SourceColumn, library); } diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs index 14908478a..070b0800f 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs @@ -1,15 +1,14 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; using System.IO; using System.Linq; using FluentAssertions; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Frameworks; +using NuGet.ProjectModel; using NuGet.Versioning; using Xunit; @@ -208,7 +207,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests new NuGetVersion("1.0.0"), s_toolPackageFramework); - var lockFile = LockFileReader.Read(lockFilePath, designTime: false); + var lockFile = new LockFileFormat().Read(lockFilePath); var depsJsonFile = Path.Combine( Path.GetDirectoryName(lockFilePath), diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/project.json b/test/Microsoft.DotNet.Cli.Utils.Tests/project.json index 6bc05de32..febb3f9f2 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/project.json +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/project.json @@ -20,10 +20,10 @@ }, "System.Diagnostics.TraceSource": "4.0.0", "System.Runtime.Serialization.Primitives": "4.1.1", - "NuGet.Versioning": "3.6.0-beta.1.msbuild.4", - "NuGet.Packaging": "3.6.0-beta.1.msbuild.4", - "NuGet.Frameworks": "3.6.0-beta.1.msbuild.4", - "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.4", + "NuGet.Versioning": "3.6.0-beta.1.msbuild.15", + "NuGet.Packaging": "3.6.0-beta.1.msbuild.15", + "NuGet.Frameworks": "3.6.0-beta.1.msbuild.15", + "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15", "Microsoft.DotNet.ProjectModel": { "target": "project" }, diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToCreateFileCollectionsFromJson.cs b/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToCreateFileCollectionsFromJson.cs index da368c0bb..7e44c138c 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToCreateFileCollectionsFromJson.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToCreateFileCollectionsFromJson.cs @@ -2,10 +2,8 @@ // 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.Text; -using Microsoft.DotNet.ProjectModel; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToLoadAProjectJsonFile.cs b/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToLoadAProjectJsonFile.cs index 86dfd56b9..fd9728e22 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToLoadAProjectJsonFile.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/GivenThatIWantToLoadAProjectJsonFile.cs @@ -1,19 +1,16 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Collections.Generic; using System.IO; using System.Text; using Xunit; -using Microsoft.DotNet.ProjectModel; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using FluentAssertions; using NuGet.Versioning; using System.Linq; -using NuGet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel.Tests { @@ -727,7 +724,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var dependency = project.Dependencies.First(); - dependency.VersionRange.Should().BeNull(); + dependency.LibraryRange.VersionRange.Should().BeNull(); } [Fact] @@ -742,8 +739,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests var dependency = project.Dependencies.First(); dependency.Name.Should().Be(DependencyName); - dependency.VersionRange.Should().Be(_versionRange); - dependency.Target.Should().Be(LibraryType.Unspecified); + dependency.LibraryRange.VersionRange.Should().Be(_versionRange); + dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All); dependency.Type.Should().Be(LibraryDependencyType.Default); dependency.SourceFilePath.Should().Be(ProjectFilePath); dependency.SourceLine.Should().Be(3); @@ -764,8 +761,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests var dependency = project.Dependencies.First(); dependency.Name.Should().Be(DependencyName); - dependency.VersionRange.Should().Be(_versionRange); - dependency.Target.Should().Be(LibraryType.Unspecified); + dependency.LibraryRange.VersionRange.Should().Be(_versionRange); + dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All); dependency.Type.Should().Be(LibraryDependencyType.Default); dependency.SourceFilePath.Should().Be(ProjectFilePath); dependency.SourceLine.Should().Be(3); @@ -801,7 +798,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var project = GetProject(json); var dependency = project.Dependencies.First(); - dependency.Target.Should().Be(LibraryType.Unspecified); + dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.None); } [Fact] @@ -817,7 +814,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var project = GetProject(json); var dependency = project.Dependencies.First(); - dependency.Target.Should().Be(LibraryType.Project); + dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.Project); } [Fact] @@ -889,7 +886,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var tool = project.Tools.First(); - tool.VersionRange.Should().BeNull(); + tool.LibraryRange.VersionRange.Should().BeNull(); } [Fact] @@ -904,8 +901,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests var tool = project.Tools.First(); tool.Name.Should().Be(ToolName); - tool.VersionRange.Should().Be(_versionRange); - tool.Target.Should().Be(LibraryType.Unspecified); + tool.LibraryRange.VersionRange.Should().Be(_versionRange); + tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All); tool.Type.Should().Be(LibraryDependencyType.Default); tool.SourceFilePath.Should().Be(ProjectFilePath); tool.SourceLine.Should().Be(3); @@ -926,8 +923,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests var tool = project.Tools.First(); tool.Name.Should().Be(ToolName); - tool.VersionRange.Should().Be(_versionRange); - tool.Target.Should().Be(LibraryType.Unspecified); + tool.LibraryRange.VersionRange.Should().Be(_versionRange); + tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All); tool.Type.Should().Be(LibraryDependencyType.Default); tool.SourceFilePath.Should().Be(ProjectFilePath); tool.SourceLine.Should().Be(3); @@ -963,7 +960,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var project = GetProject(json); var tool = project.Tools.First(); - tool.Target.Should().Be(LibraryType.Unspecified); + tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.None); } [Fact] @@ -979,7 +976,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var project = GetProject(json); var tool = project.Tools.First(); - tool.Target.Should().Be(LibraryType.Project); + tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.Project); } public Project GetProject(JObject json, ProjectReaderSettings settings = null) diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs index 879ea70ee..92b1fef67 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // 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; @@ -9,6 +8,8 @@ using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; using Microsoft.DotNet.Tools.Test.Utilities; +using NuGet.LibraryModel; +using NuGet.ProjectModel; using FluentAssertions; using Xunit; @@ -21,15 +22,15 @@ namespace Microsoft.DotNet.ProjectModel.Tests private PackageDescription CreateDescription( LockFileTargetLibrary target = null, - LockFilePackageLibrary package = null, + LockFileLibrary package = null, string hashPath = null) { return new PackageDescription( PackagePath, hashPath ?? HashPath, - package ?? new LockFilePackageLibrary(), + package ?? new LockFileLibrary(), target ?? new LockFileTargetLibrary(), - new List(), compatible: true, resolved: true); + new List(), compatible: true, resolved: true); } [Fact] @@ -40,7 +41,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests { NativeLibraries = new List() { - { new LockFileItem() { Path = "lib/Native.so" } } + { new LockFileItem("lib/Native.so") } } }); @@ -62,7 +63,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests { CompileTimeAssemblies = new List() { - { new LockFileItem() { Path = "ref/Native.dll" } } + { new LockFileItem("ref/Native.dll") } } }); @@ -84,7 +85,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests { RuntimeAssemblies = new List() { - { new LockFileItem() { Path = "ref/Native.dll" } } + { new LockFileItem("ref/Native.dll") } } }); @@ -135,13 +136,17 @@ namespace Microsoft.DotNet.ProjectModel.Tests [Fact] public void ExportsPackageResourceAssemblies() { + var enUsResource = new LockFileItem("resources/en-US/Res.dll"); + enUsResource.Properties.Add("locale", "en-US"); + var ruRuResource = new LockFileItem("resources/ru-RU/Res.dll"); + ruRuResource.Properties.Add("locale", "ru-RU"); var description = CreateDescription( new LockFileTargetLibrary() { ResourceAssemblies = new List() - { - new LockFileItem("resources/en-US/Res.dll", new Dictionary() { { "locale", "en-US"} }), - new LockFileItem("resources/ru-RU/Res.dll", new Dictionary() { { "locale", "ru-RU" } }), + { + enUsResource, + ruRuResource } }); @@ -163,14 +168,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests [Fact] public void ExportsSources() { - var description = CreateDescription( - package: new LockFilePackageLibrary() - { - Files = new List() - { - Path.Combine("shared", "file.cs") - } - }); + var lockFileLibrary = new LockFileLibrary(); + lockFileLibrary.Files.Add(Path.Combine("shared", "file.cs")); + var description = CreateDescription(package: lockFileLibrary); var result = ExportSingle(description); result.SourceReferences.Should().HaveCount(1); @@ -190,10 +190,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests { ContentFiles = new List() { - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.txt")) { CopyToOutput = true, - Path = Path.Combine("content", "file.txt"), OutputPath = Path.Combine("Out","Path.txt"), PPOutputPath = "something" } @@ -218,10 +217,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests { ContentFiles = new List() { - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.txt")) { BuildAction = BuildAction.EmbeddedResource, - Path = Path.Combine("content", "file.txt"), PPOutputPath = "something" } } @@ -244,10 +242,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests { ContentFiles = new List() { - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.cs")) { BuildAction = BuildAction.Compile, - Path = Path.Combine("content", "file.cs"), PPOutputPath = "something" } } @@ -272,24 +269,21 @@ namespace Microsoft.DotNet.ProjectModel.Tests { ContentFiles = new List() { - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.cs")) { BuildAction = BuildAction.Compile, - Path = Path.Combine("content", "file.cs"), PPOutputPath = "something", CodeLanguage = "cs" }, - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.vb")) { BuildAction = BuildAction.Compile, - Path = Path.Combine("content", "file.vb"), PPOutputPath = "something", CodeLanguage = "vb" }, - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.any")) { BuildAction = BuildAction.Compile, - Path = Path.Combine("content", "file.any"), PPOutputPath = "something", } } @@ -312,17 +306,15 @@ namespace Microsoft.DotNet.ProjectModel.Tests { ContentFiles = new List() { - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.vb")) { BuildAction = BuildAction.Compile, - Path = Path.Combine("content", "file.vb"), PPOutputPath = "something", CodeLanguage = "vb" }, - new LockFileContentFile() + new LockFileContentFile(Path.Combine("content", "file.any")) { BuildAction = BuildAction.Compile, - Path = Path.Combine("content", "file.any"), PPOutputPath = "something", } } @@ -351,7 +343,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var rootProjectDescription = new ProjectDescription( new LibraryRange(), rootProject, - new LibraryRange[] { }, + new ProjectLibraryDependency[] { }, new TargetFrameworkInformation(), true); diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs index 759be0dc2..652dd07f5 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs @@ -1,12 +1,10 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; using System.IO; using System.Linq; using FluentAssertions; using Xunit; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.ProjectModel; @@ -16,83 +14,14 @@ namespace Microsoft.DotNet.ProjectModel.Tests { private static string ExportFilesRoot=> Path.Combine(RepoRoot, "TestAssets", "LockFiles", "ExportFiles"); - - [Fact] - public void TestExportFileIsParsed() - { - var lockFilePath = GetLockFilePath("valid"); - var lockFile = LockFileReader.Read(lockFilePath, designTime: false); - - var exportFile = lockFile.ExportFile; - - exportFile.Should().NotBeNull(); - exportFile.Exports.Count.Should().Be(3); - exportFile.Exports.Should().OnlyHaveUniqueItems(); - - // check export structure - foreach (var export in exportFile.Exports) - { - export.TargetFramework.Should().NotBeNull(); - AssertTargetLibrary(export); - } - } - - [Fact] - public void TestLockFileIsPatchedWithExportData() - { - var lockFilePath = GetLockFilePath("valid"); - var lockFile = LockFileReader.Read(lockFilePath, designTime: false); - - // check lock file structure is similar to export structure - foreach (var target in lockFile.Targets) - { - target.Libraries.Count.Should().Be(3); - - foreach (var library in target.Libraries) - { - AssertTargetLibrary(library); - } - } - } - - [Fact] - public void TestFragmentExistsButNoHolesInLockFile() - { - var lockFilePath = GetLockFilePath("valid_staleFragment"); - var lockFile = LockFileReader.Read(lockFilePath, designTime: false); - - var exportFile = lockFile.ExportFile; - - exportFile.Should().BeNull(); - - lockFile.Targets.Count.Should().Be(1); - - lockFile.Targets[0].Libraries.Count.Should().Be(0); - } - - [Fact] - public void TestMissingExportFileThrows() - { - var lockFilePath = GetLockFilePath("invalid_nofragment"); - - Assert.Throws(() => LockFileReader.Read(lockFilePath, designTime: false)); - } - + [Fact] public void TestMissingExportUnderDesignTime() { var lockFilePath = GetLockFilePath("invalid_nofragment"); // not throw under design time scenario - Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true)); - } - - [Fact] - public void TestMissingExportsThrow() - { - var lockFilePath = GetLockFilePath("invalid_missing-exports"); - - Assert.Throws(() => LockFileReader.Read(lockFilePath, designTime: false)); + Assert.NotNull(new LockFileFormat().Read(lockFilePath)); } [Fact] @@ -101,43 +30,35 @@ namespace Microsoft.DotNet.ProjectModel.Tests var lockFilePath = GetLockFilePath("invalid_missing-exports"); // not throw under design time scenario - Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true)); + Assert.NotNull(new LockFileFormat().Read(lockFilePath)); } - - [Fact] - public void TestMissmatchingFileVersionsThrows() - { - var lockFilePath = GetLockFilePath("invalid_missmatching-versions"); - - Assert.Throws(() => LockFileReader.Read(lockFilePath, designTime: false)); - } - + [Fact] public void TestMissmatchingFileVersionsUnderDesignTime() { var lockFilePath = GetLockFilePath("invalid_missmatching-versions"); - Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true)); + Assert.NotNull(new LockFileFormat().Read(lockFilePath)); } [Fact] public void TestPackageFoldersLoadCorrectly() { var lockFilePath = GetLockFilePath("valid"); - var lockFile = LockFileReader.Read(lockFilePath, designTime: false); + var lockFile = new LockFileFormat().Read(lockFilePath); Assert.Equal(2, lockFile.PackageFolders.Count); Assert.Equal("/foo/packages", lockFile.PackageFolders[0].Path); Assert.Equal("/foo/packages2", lockFile.PackageFolders[1].Path); } - private static int LibraryNumberFromName(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library) + private static int LibraryNumberFromName(LockFileTargetLibrary library) { var libraryName = library.Name; return (int)char.GetNumericValue(libraryName[libraryName.Length - 1]); } - private static void AssertTargetLibrary(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library) + private static void AssertTargetLibrary(LockFileTargetLibrary library) { var libraryNumber = LibraryNumberFromName(library); diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/LockFileReaderTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/LockFileReaderTests.cs deleted file mode 100644 index 0d295063f..000000000 --- a/test/Microsoft.DotNet.ProjectModel.Tests/LockFileReaderTests.cs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.IO; -using System.Linq; -using System.Text; -using FluentAssertions; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.DotNet.Tools.Test.Utilities; -using Xunit; - -namespace Microsoft.DotNet.ProjectModel.Tests -{ - public class LockFileReaderTests : TestBase - { - [Fact] - public void ReadsAllLibraryPropertiesWhenPathIsPresent() - { - // Arrange - var lockFileJson = @" - { - ""libraries"": { - ""PackageA/1.0.1-Alpha"": { - ""sha512"": ""FAKE-HASH"", - ""type"": ""package"", - ""serviceable"": true, - ""files"": [ - ""a.txt"", - ""foo/b.txt"" - ], - ""path"": ""PackageA/1.0.1-beta-PATH"" - }, - ""ProjectA/1.0.2-Beta"": { - ""type"": ""project"", - ""path"": ""ProjectA-PATH"", - ""msbuildProject"": ""some-msbuild"" - } - } - }"; - - var lockFileStream = new MemoryStream(Encoding.UTF8.GetBytes(lockFileJson)); - var lockFileReader = new LockFileReader(); - - // Act - var lockFile = lockFileReader.ReadLockFile( - lockFilePath: null, - stream: lockFileStream, - designTime: true); - - // Assert - lockFile.PackageLibraries.Should().HaveCount(1); - var package = lockFile.PackageLibraries.First(); - package.Name.Should().Be("PackageA"); - package.Version.ToString().Should().Be("1.0.1-Alpha"); - package.Sha512.Should().Be("FAKE-HASH"); - package.IsServiceable.Should().BeTrue(); - package.Files.Should().HaveCount(2); - package.Files[0].Should().Be("a.txt"); - package.Files[1].Should().Be(Path.Combine("foo", "b.txt")); - package.Path.Should().Be("PackageA/1.0.1-beta-PATH"); - - lockFile.ProjectLibraries.Should().HaveCount(1); - var project = lockFile.ProjectLibraries.First(); - project.Name.Should().Be("ProjectA"); - project.Version.ToString().Should().Be("1.0.2-Beta"); - project.Path.Should().Be("ProjectA-PATH"); - } - - [Fact] - public void ReadsAllLibraryPropertiesWhenPathIsNotPresent() - { - // Arrange - var lockFileJson = @" - { - ""libraries"": { - ""PackageA/1.0.1-Alpha"": { - ""sha512"": ""FAKE-HASH"", - ""type"": ""package"", - ""serviceable"": true, - ""files"": [ - ""a.txt"", - ""foo/b.txt"" - ] - }, - ""ProjectA/1.0.2-Beta"": { - ""type"": ""project"", - ""msbuildProject"": ""some-msbuild"" - } - } - }"; - - var lockFileStream = new MemoryStream(Encoding.UTF8.GetBytes(lockFileJson)); - var lockFileReader = new LockFileReader(); - - // Act - var lockFile = lockFileReader.ReadLockFile( - lockFilePath: null, - stream: lockFileStream, - designTime: true); - - // Assert - lockFile.PackageLibraries.Should().HaveCount(1); - var package = lockFile.PackageLibraries.First(); - package.Name.Should().Be("PackageA"); - package.Version.ToString().Should().Be("1.0.1-Alpha"); - package.Sha512.Should().Be("FAKE-HASH"); - package.IsServiceable.Should().BeTrue(); - package.Files.Should().HaveCount(2); - package.Files[0].Should().Be("a.txt"); - package.Files[1].Should().Be(Path.Combine("foo", "b.txt")); - package.Path.Should().BeNull(); - - lockFile.ProjectLibraries.Should().HaveCount(1); - var project = lockFile.ProjectLibraries.First(); - project.Name.Should().Be("ProjectA"); - project.Version.ToString().Should().Be("1.0.2-Beta"); - project.Path.Should().BeNull(); - } - } -} diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs index 1f42e6019..1f857d8ef 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs @@ -2,12 +2,13 @@ using System; using System.IO; using System.Linq; using FluentAssertions; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Configuration; using NuGet.Frameworks; +using NuGet.LibraryModel; +using NuGet.ProjectModel; using NuGet.Versioning; using Xunit; @@ -22,7 +23,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var provider = new PackageDependencyProvider( NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); - var package = new LockFilePackageLibrary(); + var package = new LockFileLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0"); package.Files.Add("lib/dotnet/_._"); @@ -51,7 +52,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var provider = new PackageDependencyProvider( NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); - var package = new LockFilePackageLibrary(); + var package = new LockFileLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0-Beta"); package.Files.Add("lib/dotnet/_._"); @@ -80,7 +81,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var provider = new PackageDependencyProvider( NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); - var package = new LockFilePackageLibrary(); + var package = new LockFileLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0"); package.Files.Add("lib/dotnet/_._"); @@ -113,7 +114,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var provider = new PackageDependencyProvider( NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); - var package = new LockFilePackageLibrary(); + var package = new LockFileLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0"); package.Files.Add("lib/net46/_._"); @@ -143,7 +144,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests var provider = new PackageDependencyProvider( NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); - var package = new LockFilePackageLibrary(); + var package = new LockFileLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0"); diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/ProjectContextBuilderTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/ProjectContextBuilderTests.cs index f0f085643..7104ed44c 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/ProjectContextBuilderTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/ProjectContextBuilderTests.cs @@ -4,9 +4,9 @@ using System.IO; using System.Linq; using System.Reflection; using FluentAssertions; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Frameworks; +using NuGet.ProjectModel; using Xunit; namespace Microsoft.DotNet.ProjectModel.Tests @@ -36,7 +36,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests // Initialize a test instance that we're going to clone. Make sure all properties are initialized here. var initialBuilder = new ProjectContextBuilder() .WithProject(new Project()) - .WithLockFile(new LockFile("abc")) + .WithLockFile(new LockFile()) .WithTargetFramework(FrameworkConstants.CommonFrameworks.NetStandard10) .WithRuntimeIdentifiers(new[] { "win7-x64", "osx.10.10-x64" }) .WithRootDirectory("C:\\The\\Root") @@ -44,7 +44,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests .WithPackagesDirectory("D:\\My\\Awesome\\NuGet\\Packages") .WithReferenceAssembliesPath("/these/are/the/reference/assemblies") .WithProjectResolver(_ => new Project()) - .WithLockFileResolver(_ => new LockFile("def")) + .WithLockFileResolver(_ => new LockFile()) .WithProjectReaderSettings(new ProjectReaderSettings()); // Clone the builder diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/project.json b/test/Microsoft.DotNet.ProjectModel.Tests/project.json index 4a007dd23..fc6e86a8f 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/project.json +++ b/test/Microsoft.DotNet.ProjectModel.Tests/project.json @@ -21,7 +21,8 @@ "target": "project" }, "xunit": "2.2.0-beta3-build3330", - "dotnet-test-xunit": "1.0.0-rc2-350904-49" + "dotnet-test-xunit": "1.0.0-rc2-350904-49", + "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15" }, "frameworks": { "netcoreapp1.0": {