Fixing issues small issues found during build and tests.
This commit is contained in:
parent
6527cbc592
commit
f0a50c92ac
18 changed files with 122 additions and 293 deletions
src
Microsoft.DotNet.Compiler.Common
Microsoft.DotNet.ProjectModel
dotnet/commands
test
Microsoft.DotNet.Cli.Utils.Tests
Microsoft.DotNet.ProjectModel.Tests
|
@ -14,7 +14,7 @@
|
||||||
"Microsoft.DotNet.Files": {
|
"Microsoft.DotNet.Files": {
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.9"
|
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": {
|
"net451": {
|
||||||
|
|
|
@ -212,13 +212,16 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
|
||||||
|
|
||||||
var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage();
|
var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage();
|
||||||
var languageGroups = library.ContentFiles.GroupBy(file => file.CodeLanguage);
|
var languageGroups = library.ContentFiles.GroupBy(file => file.CodeLanguage);
|
||||||
|
|
||||||
var selectedGroup = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ??
|
var selectedGroup = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ??
|
||||||
|
languageGroups.FirstOrDefault(g => g.Key == "any") ??
|
||||||
languageGroups.FirstOrDefault(g => g.Key == null);
|
languageGroups.FirstOrDefault(g => g.Key == null);
|
||||||
if (selectedGroup != null)
|
if (selectedGroup != null)
|
||||||
{
|
{
|
||||||
foreach (var contentFile in selectedGroup)
|
foreach (var contentFile in selectedGroup)
|
||||||
{
|
{
|
||||||
if (contentFile.CodeLanguage != null &&
|
if (contentFile.CodeLanguage != null &&
|
||||||
|
contentFile.CodeLanguage != "any" &&
|
||||||
string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0)
|
string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
// The lock file should contain dependencies for each framework plus dependencies shared by all frameworks
|
// The lock file should contain dependencies for each framework plus dependencies shared by all frameworks
|
||||||
if (lockFile.ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1)
|
if (lockFile.ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"Different count; {lockFile.ProjectFileDependencyGroups.Count} != {actualTargetFrameworks.Count() + 1}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
var expectedDependencies = group.Dependencies.OrderBy(x => x);
|
var expectedDependencies = group.Dependencies.OrderBy(x => x);
|
||||||
|
|
||||||
// If the framework name is empty, the associated dependencies are shared by all frameworks
|
// 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
|
actualDependencies = project.Dependencies
|
||||||
.Select(d => d.LibraryRange.ToLockFileDependencyGroupString())
|
.Select(d => d.LibraryRange.ToLockFileDependencyGroupString())
|
||||||
|
@ -47,7 +48,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var framework = actualTargetFrameworks
|
var framework = actualTargetFrameworks
|
||||||
.FirstOrDefault(f => Equals(f.FrameworkName, group.FrameworkName));
|
.FirstOrDefault(f => Equals(f.FrameworkName.DotNetFrameworkName, group.FrameworkName));
|
||||||
if (framework == null)
|
if (framework == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -60,6 +61,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
|
|
||||||
if (!actualDependencies.SequenceEqual(expectedDependencies))
|
if (!actualDependencies.SequenceEqual(expectedDependencies))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"ActualDependencies don't match");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.DotNet.PlatformAbstractions;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
using NuGet.LibraryModel;
|
using NuGet.LibraryModel;
|
||||||
|
|
||||||
|
@ -33,7 +35,8 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
public LibraryIdentity Identity { get; }
|
public LibraryIdentity Identity { get; }
|
||||||
public string Hash { get; }
|
public string Hash { get; }
|
||||||
public HashSet<ProjectLibraryDependency> RequestedRanges { get; } = new HashSet<ProjectLibraryDependency>();
|
public HashSet<ProjectLibraryDependency> RequestedRanges { get; } =
|
||||||
|
new HashSet<ProjectLibraryDependency>(new LibraryRangeEqualityComparer());
|
||||||
public List<LibraryDescription> Parents { get; } = new List<LibraryDescription>();
|
public List<LibraryDescription> Parents { get; } = new List<LibraryDescription>();
|
||||||
public string Path { get; }
|
public string Path { get; }
|
||||||
public IEnumerable<ProjectLibraryDependency> Dependencies { get; }
|
public IEnumerable<ProjectLibraryDependency> Dependencies { get; }
|
||||||
|
@ -46,5 +49,29 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
{
|
{
|
||||||
return $"{Identity} ({Identity.Type}) = {Path}";
|
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<ProjectLibraryDependency>
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
var dependencyValue = dependency.Value;
|
var dependencyValue = dependency.Value;
|
||||||
var dependencyTypeValue = LibraryDependencyType.Default;
|
var dependencyTypeValue = LibraryDependencyType.Default;
|
||||||
var target = isGacOrFrameworkReference ? LibraryDependencyTarget.Reference: LibraryDependencyTarget.None;
|
var target = isGacOrFrameworkReference ? LibraryDependencyTarget.Reference : LibraryDependencyTarget.All;
|
||||||
string dependencyVersionAsString = null;
|
string dependencyVersionAsString = null;
|
||||||
|
|
||||||
if (dependencyValue.Type == JTokenType.Object)
|
if (dependencyValue.Type == JTokenType.Object)
|
||||||
|
@ -334,7 +334,10 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
dependency.Key,
|
dependency.Key,
|
||||||
dependencyVersionRange,
|
dependencyVersionRange,
|
||||||
target),
|
target),
|
||||||
Type = dependencyTypeValue
|
Type = dependencyTypeValue,
|
||||||
|
SourceFilePath = projectPath,
|
||||||
|
SourceLine = lineInfo.LineNumber,
|
||||||
|
SourceColumn = lineInfo.LinePosition
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
|
||||||
if (!dependencies.Any(dep => string.Equals(dep.Name, dependencyName, StringComparison.OrdinalIgnoreCase)))
|
if (!dependencies.Any(dep => string.Equals(dep.Name, dependencyName, StringComparison.OrdinalIgnoreCase)))
|
||||||
{
|
{
|
||||||
dependencies.Add(new ProjectLibraryDependency {
|
dependencies.Add(new ProjectLibraryDependency {
|
||||||
LibraryRange = new LibraryRange(dependencyName, LibraryDependencyTarget.All)
|
LibraryRange = new LibraryRange(dependencyName, LibraryDependencyTarget.Reference)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,10 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
if (Project.PackOptions.PackInclude != null)
|
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));
|
PackageBuilder.Files.AddRange(GetPackageFiles(files, packDiagnostics));
|
||||||
}
|
}
|
||||||
else if (Project.Files.PackInclude != null && Project.Files.PackInclude.Any())
|
else if (Project.Files.PackInclude != null && Project.Files.PackInclude.Any())
|
||||||
|
@ -302,7 +305,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Efficiency
|
// 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
|
// REVIEW: Can we get this far with unresolved dependencies
|
||||||
if (dependencyDescription == null || !dependencyDescription.Resolved)
|
if (dependencyDescription == null || !dependencyDescription.Resolved)
|
||||||
|
@ -318,7 +322,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
if (dependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference)
|
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()}");
|
Reporter.Verbose.WriteLine($"Adding framework assembly {dependency.Name.Yellow()}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,10 +54,10 @@ namespace Microsoft.DotNet.ProjectModel.Server.Helpers
|
||||||
return new DiagnosticMessage(
|
return new DiagnosticMessage(
|
||||||
ErrorCodes.NU1010,
|
ErrorCodes.NU1010,
|
||||||
$"The type of dependency {library.Identity.Name} was changed.",
|
$"The type of dependency {library.Identity.Name} was changed.",
|
||||||
string.Empty,
|
libraryRange.SourceFilePath,
|
||||||
DiagnosticMessageSeverity.Error,
|
DiagnosticMessageSeverity.Error,
|
||||||
0,
|
libraryRange.SourceLine,
|
||||||
0,
|
libraryRange.SourceColumn,
|
||||||
library);
|
library);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
|
||||||
using Microsoft.DotNet.TestFramework;
|
using Microsoft.DotNet.TestFramework;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
using NuGet.ProjectModel;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
@ -208,7 +207,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
new NuGetVersion("1.0.0"),
|
new NuGetVersion("1.0.0"),
|
||||||
s_toolPackageFramework);
|
s_toolPackageFramework);
|
||||||
|
|
||||||
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
|
var lockFile = new LockFileFormat().Read(lockFilePath);
|
||||||
|
|
||||||
var depsJsonFile = Path.Combine(
|
var depsJsonFile = Path.Combine(
|
||||||
Path.GetDirectoryName(lockFilePath),
|
Path.GetDirectoryName(lockFilePath),
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
},
|
},
|
||||||
"System.Diagnostics.TraceSource": "4.0.0",
|
"System.Diagnostics.TraceSource": "4.0.0",
|
||||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||||
"NuGet.Versioning": "3.6.0-beta.1.msbuild.4",
|
"NuGet.Versioning": "3.6.0-beta.1.msbuild.15",
|
||||||
"NuGet.Packaging": "3.6.0-beta.1.msbuild.4",
|
"NuGet.Packaging": "3.6.0-beta.1.msbuild.15",
|
||||||
"NuGet.Frameworks": "3.6.0-beta.1.msbuild.4",
|
"NuGet.Frameworks": "3.6.0-beta.1.msbuild.15",
|
||||||
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.4",
|
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15",
|
||||||
"Microsoft.DotNet.ProjectModel": {
|
"Microsoft.DotNet.ProjectModel": {
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// 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.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NuGet.ProjectModel;
|
using NuGet.LibraryModel;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.ProjectModel.Tests
|
namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
|
@ -727,7 +724,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
var dependency = project.Dependencies.First();
|
var dependency = project.Dependencies.First();
|
||||||
|
|
||||||
dependency.VersionRange.Should().BeNull();
|
dependency.LibraryRange.VersionRange.Should().BeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -742,8 +739,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
var dependency = project.Dependencies.First();
|
var dependency = project.Dependencies.First();
|
||||||
dependency.Name.Should().Be(DependencyName);
|
dependency.Name.Should().Be(DependencyName);
|
||||||
dependency.VersionRange.Should().Be(_versionRange);
|
dependency.LibraryRange.VersionRange.Should().Be(_versionRange);
|
||||||
dependency.Target.Should().Be(LibraryType.Unspecified);
|
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
|
||||||
dependency.Type.Should().Be(LibraryDependencyType.Default);
|
dependency.Type.Should().Be(LibraryDependencyType.Default);
|
||||||
dependency.SourceFilePath.Should().Be(ProjectFilePath);
|
dependency.SourceFilePath.Should().Be(ProjectFilePath);
|
||||||
dependency.SourceLine.Should().Be(3);
|
dependency.SourceLine.Should().Be(3);
|
||||||
|
@ -764,8 +761,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
var dependency = project.Dependencies.First();
|
var dependency = project.Dependencies.First();
|
||||||
dependency.Name.Should().Be(DependencyName);
|
dependency.Name.Should().Be(DependencyName);
|
||||||
dependency.VersionRange.Should().Be(_versionRange);
|
dependency.LibraryRange.VersionRange.Should().Be(_versionRange);
|
||||||
dependency.Target.Should().Be(LibraryType.Unspecified);
|
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
|
||||||
dependency.Type.Should().Be(LibraryDependencyType.Default);
|
dependency.Type.Should().Be(LibraryDependencyType.Default);
|
||||||
dependency.SourceFilePath.Should().Be(ProjectFilePath);
|
dependency.SourceFilePath.Should().Be(ProjectFilePath);
|
||||||
dependency.SourceLine.Should().Be(3);
|
dependency.SourceLine.Should().Be(3);
|
||||||
|
@ -801,7 +798,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var project = GetProject(json);
|
var project = GetProject(json);
|
||||||
|
|
||||||
var dependency = project.Dependencies.First();
|
var dependency = project.Dependencies.First();
|
||||||
dependency.Target.Should().Be(LibraryType.Unspecified);
|
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -817,7 +814,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var project = GetProject(json);
|
var project = GetProject(json);
|
||||||
|
|
||||||
var dependency = project.Dependencies.First();
|
var dependency = project.Dependencies.First();
|
||||||
dependency.Target.Should().Be(LibraryType.Project);
|
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.Project);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -889,7 +886,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
var tool = project.Tools.First();
|
var tool = project.Tools.First();
|
||||||
|
|
||||||
tool.VersionRange.Should().BeNull();
|
tool.LibraryRange.VersionRange.Should().BeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -904,8 +901,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
var tool = project.Tools.First();
|
var tool = project.Tools.First();
|
||||||
tool.Name.Should().Be(ToolName);
|
tool.Name.Should().Be(ToolName);
|
||||||
tool.VersionRange.Should().Be(_versionRange);
|
tool.LibraryRange.VersionRange.Should().Be(_versionRange);
|
||||||
tool.Target.Should().Be(LibraryType.Unspecified);
|
tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
|
||||||
tool.Type.Should().Be(LibraryDependencyType.Default);
|
tool.Type.Should().Be(LibraryDependencyType.Default);
|
||||||
tool.SourceFilePath.Should().Be(ProjectFilePath);
|
tool.SourceFilePath.Should().Be(ProjectFilePath);
|
||||||
tool.SourceLine.Should().Be(3);
|
tool.SourceLine.Should().Be(3);
|
||||||
|
@ -926,8 +923,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
var tool = project.Tools.First();
|
var tool = project.Tools.First();
|
||||||
tool.Name.Should().Be(ToolName);
|
tool.Name.Should().Be(ToolName);
|
||||||
tool.VersionRange.Should().Be(_versionRange);
|
tool.LibraryRange.VersionRange.Should().Be(_versionRange);
|
||||||
tool.Target.Should().Be(LibraryType.Unspecified);
|
tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
|
||||||
tool.Type.Should().Be(LibraryDependencyType.Default);
|
tool.Type.Should().Be(LibraryDependencyType.Default);
|
||||||
tool.SourceFilePath.Should().Be(ProjectFilePath);
|
tool.SourceFilePath.Should().Be(ProjectFilePath);
|
||||||
tool.SourceLine.Should().Be(3);
|
tool.SourceLine.Should().Be(3);
|
||||||
|
@ -963,7 +960,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var project = GetProject(json);
|
var project = GetProject(json);
|
||||||
|
|
||||||
var tool = project.Tools.First();
|
var tool = project.Tools.First();
|
||||||
tool.Target.Should().Be(LibraryType.Unspecified);
|
tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -979,7 +976,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var project = GetProject(json);
|
var project = GetProject(json);
|
||||||
|
|
||||||
var tool = project.Tools.First();
|
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)
|
public Project GetProject(JObject json, ProjectReaderSettings settings = null)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -9,6 +8,8 @@ using Microsoft.DotNet.ProjectModel.Compilation;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
using Microsoft.DotNet.ProjectModel.Resolution;
|
using Microsoft.DotNet.ProjectModel.Resolution;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
using NuGet.LibraryModel;
|
||||||
|
using NuGet.ProjectModel;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
@ -21,15 +22,15 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
private PackageDescription CreateDescription(
|
private PackageDescription CreateDescription(
|
||||||
LockFileTargetLibrary target = null,
|
LockFileTargetLibrary target = null,
|
||||||
LockFilePackageLibrary package = null,
|
LockFileLibrary package = null,
|
||||||
string hashPath = null)
|
string hashPath = null)
|
||||||
{
|
{
|
||||||
return new PackageDescription(
|
return new PackageDescription(
|
||||||
PackagePath,
|
PackagePath,
|
||||||
hashPath ?? HashPath,
|
hashPath ?? HashPath,
|
||||||
package ?? new LockFilePackageLibrary(),
|
package ?? new LockFileLibrary(),
|
||||||
target ?? new LockFileTargetLibrary(),
|
target ?? new LockFileTargetLibrary(),
|
||||||
new List<LibraryRange>(), compatible: true, resolved: true);
|
new List<ProjectLibraryDependency>(), compatible: true, resolved: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -40,7 +41,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
NativeLibraries = new List<LockFileItem>()
|
NativeLibraries = new List<LockFileItem>()
|
||||||
{
|
{
|
||||||
{ new LockFileItem() { Path = "lib/Native.so" } }
|
{ new LockFileItem("lib/Native.so") }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
CompileTimeAssemblies = new List<LockFileItem>()
|
CompileTimeAssemblies = new List<LockFileItem>()
|
||||||
{
|
{
|
||||||
{ new LockFileItem() { Path = "ref/Native.dll" } }
|
{ new LockFileItem("ref/Native.dll") }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
RuntimeAssemblies = new List<LockFileItem>()
|
RuntimeAssemblies = new List<LockFileItem>()
|
||||||
{
|
{
|
||||||
{ new LockFileItem() { Path = "ref/Native.dll" } }
|
{ new LockFileItem("ref/Native.dll") }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -135,13 +136,17 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ExportsPackageResourceAssemblies()
|
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(
|
var description = CreateDescription(
|
||||||
new LockFileTargetLibrary()
|
new LockFileTargetLibrary()
|
||||||
{
|
{
|
||||||
ResourceAssemblies = new List<LockFileItem>()
|
ResourceAssemblies = new List<LockFileItem>()
|
||||||
{
|
{
|
||||||
new LockFileItem("resources/en-US/Res.dll", new Dictionary<string, string>() { { "locale", "en-US"} }),
|
enUsResource,
|
||||||
new LockFileItem("resources/ru-RU/Res.dll", new Dictionary<string, string>() { { "locale", "ru-RU" } }),
|
ruRuResource
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -163,14 +168,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ExportsSources()
|
public void ExportsSources()
|
||||||
{
|
{
|
||||||
var description = CreateDescription(
|
var lockFileLibrary = new LockFileLibrary();
|
||||||
package: new LockFilePackageLibrary()
|
lockFileLibrary.Files.Add(Path.Combine("shared", "file.cs"));
|
||||||
{
|
var description = CreateDescription(package: lockFileLibrary);
|
||||||
Files = new List<string>()
|
|
||||||
{
|
|
||||||
Path.Combine("shared", "file.cs")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = ExportSingle(description);
|
var result = ExportSingle(description);
|
||||||
result.SourceReferences.Should().HaveCount(1);
|
result.SourceReferences.Should().HaveCount(1);
|
||||||
|
@ -190,10 +190,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
ContentFiles = new List<LockFileContentFile>()
|
ContentFiles = new List<LockFileContentFile>()
|
||||||
{
|
{
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.txt"))
|
||||||
{
|
{
|
||||||
CopyToOutput = true,
|
CopyToOutput = true,
|
||||||
Path = Path.Combine("content", "file.txt"),
|
|
||||||
OutputPath = Path.Combine("Out","Path.txt"),
|
OutputPath = Path.Combine("Out","Path.txt"),
|
||||||
PPOutputPath = "something"
|
PPOutputPath = "something"
|
||||||
}
|
}
|
||||||
|
@ -218,10 +217,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
ContentFiles = new List<LockFileContentFile>()
|
ContentFiles = new List<LockFileContentFile>()
|
||||||
{
|
{
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.txt"))
|
||||||
{
|
{
|
||||||
BuildAction = BuildAction.EmbeddedResource,
|
BuildAction = BuildAction.EmbeddedResource,
|
||||||
Path = Path.Combine("content", "file.txt"),
|
|
||||||
PPOutputPath = "something"
|
PPOutputPath = "something"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,10 +242,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
ContentFiles = new List<LockFileContentFile>()
|
ContentFiles = new List<LockFileContentFile>()
|
||||||
{
|
{
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.cs"))
|
||||||
{
|
{
|
||||||
BuildAction = BuildAction.Compile,
|
BuildAction = BuildAction.Compile,
|
||||||
Path = Path.Combine("content", "file.cs"),
|
|
||||||
PPOutputPath = "something"
|
PPOutputPath = "something"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,24 +269,21 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
ContentFiles = new List<LockFileContentFile>()
|
ContentFiles = new List<LockFileContentFile>()
|
||||||
{
|
{
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.cs"))
|
||||||
{
|
{
|
||||||
BuildAction = BuildAction.Compile,
|
BuildAction = BuildAction.Compile,
|
||||||
Path = Path.Combine("content", "file.cs"),
|
|
||||||
PPOutputPath = "something",
|
PPOutputPath = "something",
|
||||||
CodeLanguage = "cs"
|
CodeLanguage = "cs"
|
||||||
},
|
},
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.vb"))
|
||||||
{
|
{
|
||||||
BuildAction = BuildAction.Compile,
|
BuildAction = BuildAction.Compile,
|
||||||
Path = Path.Combine("content", "file.vb"),
|
|
||||||
PPOutputPath = "something",
|
PPOutputPath = "something",
|
||||||
CodeLanguage = "vb"
|
CodeLanguage = "vb"
|
||||||
},
|
},
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.any"))
|
||||||
{
|
{
|
||||||
BuildAction = BuildAction.Compile,
|
BuildAction = BuildAction.Compile,
|
||||||
Path = Path.Combine("content", "file.any"),
|
|
||||||
PPOutputPath = "something",
|
PPOutputPath = "something",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,17 +306,15 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
ContentFiles = new List<LockFileContentFile>()
|
ContentFiles = new List<LockFileContentFile>()
|
||||||
{
|
{
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.vb"))
|
||||||
{
|
{
|
||||||
BuildAction = BuildAction.Compile,
|
BuildAction = BuildAction.Compile,
|
||||||
Path = Path.Combine("content", "file.vb"),
|
|
||||||
PPOutputPath = "something",
|
PPOutputPath = "something",
|
||||||
CodeLanguage = "vb"
|
CodeLanguage = "vb"
|
||||||
},
|
},
|
||||||
new LockFileContentFile()
|
new LockFileContentFile(Path.Combine("content", "file.any"))
|
||||||
{
|
{
|
||||||
BuildAction = BuildAction.Compile,
|
BuildAction = BuildAction.Compile,
|
||||||
Path = Path.Combine("content", "file.any"),
|
|
||||||
PPOutputPath = "something",
|
PPOutputPath = "something",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +343,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var rootProjectDescription = new ProjectDescription(
|
var rootProjectDescription = new ProjectDescription(
|
||||||
new LibraryRange(),
|
new LibraryRange(),
|
||||||
rootProject,
|
rootProject,
|
||||||
new LibraryRange[] { },
|
new ProjectLibraryDependency[] { },
|
||||||
new TargetFrameworkInformation(),
|
new TargetFrameworkInformation(),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using NuGet.ProjectModel;
|
using NuGet.ProjectModel;
|
||||||
|
|
||||||
|
@ -17,82 +15,13 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
|
|
||||||
private static string ExportFilesRoot=> Path.Combine(RepoRoot, "TestAssets", "LockFiles", "ExportFiles");
|
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<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestMissingExportUnderDesignTime()
|
public void TestMissingExportUnderDesignTime()
|
||||||
{
|
{
|
||||||
var lockFilePath = GetLockFilePath("invalid_nofragment");
|
var lockFilePath = GetLockFilePath("invalid_nofragment");
|
||||||
|
|
||||||
// not throw under design time scenario
|
// not throw under design time scenario
|
||||||
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
|
Assert.NotNull(new LockFileFormat().Read(lockFilePath));
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestMissingExportsThrow()
|
|
||||||
{
|
|
||||||
var lockFilePath = GetLockFilePath("invalid_missing-exports");
|
|
||||||
|
|
||||||
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -101,15 +30,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var lockFilePath = GetLockFilePath("invalid_missing-exports");
|
var lockFilePath = GetLockFilePath("invalid_missing-exports");
|
||||||
|
|
||||||
// not throw under design time scenario
|
// 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<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -117,27 +38,27 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
{
|
{
|
||||||
var lockFilePath = GetLockFilePath("invalid_missmatching-versions");
|
var lockFilePath = GetLockFilePath("invalid_missmatching-versions");
|
||||||
|
|
||||||
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
|
Assert.NotNull(new LockFileFormat().Read(lockFilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestPackageFoldersLoadCorrectly()
|
public void TestPackageFoldersLoadCorrectly()
|
||||||
{
|
{
|
||||||
var lockFilePath = GetLockFilePath("valid");
|
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(2, lockFile.PackageFolders.Count);
|
||||||
Assert.Equal("/foo/packages", lockFile.PackageFolders[0].Path);
|
Assert.Equal("/foo/packages", lockFile.PackageFolders[0].Path);
|
||||||
Assert.Equal("/foo/packages2", lockFile.PackageFolders[1].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;
|
var libraryName = library.Name;
|
||||||
return (int)char.GetNumericValue(libraryName[libraryName.Length - 1]);
|
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);
|
var libraryNumber = LibraryNumberFromName(library);
|
||||||
|
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,12 +2,13 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
|
||||||
using Microsoft.DotNet.ProjectModel.Resolution;
|
using Microsoft.DotNet.ProjectModel.Resolution;
|
||||||
using Microsoft.DotNet.TestFramework;
|
using Microsoft.DotNet.TestFramework;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using NuGet.Configuration;
|
using NuGet.Configuration;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
using NuGet.LibraryModel;
|
||||||
|
using NuGet.ProjectModel;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var provider = new PackageDependencyProvider(
|
var provider = new PackageDependencyProvider(
|
||||||
NuGetPathContext.Create("/foo/packages"),
|
NuGetPathContext.Create("/foo/packages"),
|
||||||
new FrameworkReferenceResolver("/foo/references"));
|
new FrameworkReferenceResolver("/foo/references"));
|
||||||
var package = new LockFilePackageLibrary();
|
var package = new LockFileLibrary();
|
||||||
package.Name = "Something";
|
package.Name = "Something";
|
||||||
package.Version = NuGetVersion.Parse("1.0.0");
|
package.Version = NuGetVersion.Parse("1.0.0");
|
||||||
package.Files.Add("lib/dotnet/_._");
|
package.Files.Add("lib/dotnet/_._");
|
||||||
|
@ -51,7 +52,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var provider = new PackageDependencyProvider(
|
var provider = new PackageDependencyProvider(
|
||||||
NuGetPathContext.Create("/foo/packages"),
|
NuGetPathContext.Create("/foo/packages"),
|
||||||
new FrameworkReferenceResolver("/foo/references"));
|
new FrameworkReferenceResolver("/foo/references"));
|
||||||
var package = new LockFilePackageLibrary();
|
var package = new LockFileLibrary();
|
||||||
package.Name = "Something";
|
package.Name = "Something";
|
||||||
package.Version = NuGetVersion.Parse("1.0.0-Beta");
|
package.Version = NuGetVersion.Parse("1.0.0-Beta");
|
||||||
package.Files.Add("lib/dotnet/_._");
|
package.Files.Add("lib/dotnet/_._");
|
||||||
|
@ -80,7 +81,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var provider = new PackageDependencyProvider(
|
var provider = new PackageDependencyProvider(
|
||||||
NuGetPathContext.Create("/foo/packages"),
|
NuGetPathContext.Create("/foo/packages"),
|
||||||
new FrameworkReferenceResolver("/foo/references"));
|
new FrameworkReferenceResolver("/foo/references"));
|
||||||
var package = new LockFilePackageLibrary();
|
var package = new LockFileLibrary();
|
||||||
package.Name = "Something";
|
package.Name = "Something";
|
||||||
package.Version = NuGetVersion.Parse("1.0.0");
|
package.Version = NuGetVersion.Parse("1.0.0");
|
||||||
package.Files.Add("lib/dotnet/_._");
|
package.Files.Add("lib/dotnet/_._");
|
||||||
|
@ -113,7 +114,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var provider = new PackageDependencyProvider(
|
var provider = new PackageDependencyProvider(
|
||||||
NuGetPathContext.Create("/foo/packages"),
|
NuGetPathContext.Create("/foo/packages"),
|
||||||
new FrameworkReferenceResolver("/foo/references"));
|
new FrameworkReferenceResolver("/foo/references"));
|
||||||
var package = new LockFilePackageLibrary();
|
var package = new LockFileLibrary();
|
||||||
package.Name = "Something";
|
package.Name = "Something";
|
||||||
package.Version = NuGetVersion.Parse("1.0.0");
|
package.Version = NuGetVersion.Parse("1.0.0");
|
||||||
package.Files.Add("lib/net46/_._");
|
package.Files.Add("lib/net46/_._");
|
||||||
|
@ -143,7 +144,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
var provider = new PackageDependencyProvider(
|
var provider = new PackageDependencyProvider(
|
||||||
NuGetPathContext.Create("/foo/packages"),
|
NuGetPathContext.Create("/foo/packages"),
|
||||||
new FrameworkReferenceResolver("/foo/references"));
|
new FrameworkReferenceResolver("/foo/references"));
|
||||||
var package = new LockFilePackageLibrary();
|
var package = new LockFileLibrary();
|
||||||
package.Name = "Something";
|
package.Name = "Something";
|
||||||
package.Version = NuGetVersion.Parse("1.0.0");
|
package.Version = NuGetVersion.Parse("1.0.0");
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
using NuGet.ProjectModel;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.ProjectModel.Tests
|
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.
|
// Initialize a test instance that we're going to clone. Make sure all properties are initialized here.
|
||||||
var initialBuilder = new ProjectContextBuilder()
|
var initialBuilder = new ProjectContextBuilder()
|
||||||
.WithProject(new Project())
|
.WithProject(new Project())
|
||||||
.WithLockFile(new LockFile("abc"))
|
.WithLockFile(new LockFile())
|
||||||
.WithTargetFramework(FrameworkConstants.CommonFrameworks.NetStandard10)
|
.WithTargetFramework(FrameworkConstants.CommonFrameworks.NetStandard10)
|
||||||
.WithRuntimeIdentifiers(new[] { "win7-x64", "osx.10.10-x64" })
|
.WithRuntimeIdentifiers(new[] { "win7-x64", "osx.10.10-x64" })
|
||||||
.WithRootDirectory("C:\\The\\Root")
|
.WithRootDirectory("C:\\The\\Root")
|
||||||
|
@ -44,7 +44,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
||||||
.WithPackagesDirectory("D:\\My\\Awesome\\NuGet\\Packages")
|
.WithPackagesDirectory("D:\\My\\Awesome\\NuGet\\Packages")
|
||||||
.WithReferenceAssembliesPath("/these/are/the/reference/assemblies")
|
.WithReferenceAssembliesPath("/these/are/the/reference/assemblies")
|
||||||
.WithProjectResolver(_ => new Project())
|
.WithProjectResolver(_ => new Project())
|
||||||
.WithLockFileResolver(_ => new LockFile("def"))
|
.WithLockFileResolver(_ => new LockFile())
|
||||||
.WithProjectReaderSettings(new ProjectReaderSettings());
|
.WithProjectReaderSettings(new ProjectReaderSettings());
|
||||||
|
|
||||||
// Clone the builder
|
// Clone the builder
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
"xunit": "2.2.0-beta3-build3330",
|
"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": {
|
"frameworks": {
|
||||||
"netcoreapp1.0": {
|
"netcoreapp1.0": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue