Add lock file patching tests
This commit is contained in:
parent
90240a431b
commit
b2aae7546a
14 changed files with 529 additions and 3 deletions
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"version": 2,
|
||||
"exports": {
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.6",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary2.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary2.dll": {}
|
||||
}
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.6",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary3.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary3.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"net46": {
|
||||
"dependencies": {
|
||||
"ClassLibrary1": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary2": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary3": {
|
||||
"target": "project"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"locked": false,
|
||||
"version": 2,
|
||||
"targets": {
|
||||
".NETFramework,Version=v4.6": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x64": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x86": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary1/ClassLibrary1.csproj"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary2/ClassLibrary2.csproj"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary3/ClassLibrary3.csproj"
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"": [],
|
||||
".NETFramework,Version=v4.6": [
|
||||
"ClassLibrary1",
|
||||
"ClassLibrary2",
|
||||
"ClassLibrary3"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"version": 3,
|
||||
"exports": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.5.2",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary1.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary1.dll": {}
|
||||
}
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.6",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary2.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary2.dll": {}
|
||||
}
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.6",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary3.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary3.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"net46": {
|
||||
"dependencies": {
|
||||
"ClassLibrary1": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary2": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary3": {
|
||||
"target": "project"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"locked": false,
|
||||
"version": 2,
|
||||
"targets": {
|
||||
".NETFramework,Version=v4.6": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x64": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x86": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary1/ClassLibrary1.csproj"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary2/ClassLibrary2.csproj"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary3/ClassLibrary3.csproj"
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"": [],
|
||||
".NETFramework,Version=v4.6": [
|
||||
"ClassLibrary1",
|
||||
"ClassLibrary2",
|
||||
"ClassLibrary3"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"net46": {
|
||||
"dependencies": {
|
||||
"ClassLibrary1": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary2": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary3": {
|
||||
"target": "project"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"locked": false,
|
||||
"version": 2,
|
||||
"targets": {
|
||||
".NETFramework,Version=v4.6": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x64": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x86": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary1/ClassLibrary1.csproj"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary2/ClassLibrary2.csproj"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary3/ClassLibrary3.csproj"
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"": [],
|
||||
".NETFramework,Version=v4.6": [
|
||||
"ClassLibrary1",
|
||||
"ClassLibrary2",
|
||||
"ClassLibrary3"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"version": 2,
|
||||
"exports": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.5.2",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary1.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary1.dll": {}
|
||||
}
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.6",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary2.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary2.dll": {}
|
||||
}
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.6",
|
||||
"compile": {
|
||||
"bin/Debug/ClassLibrary3.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/Debug/ClassLibrary3.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"net46": {
|
||||
"dependencies": {
|
||||
"ClassLibrary1": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary2": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary3": {
|
||||
"target": "project"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"locked": false,
|
||||
"version": 2,
|
||||
"targets": {
|
||||
".NETFramework,Version=v4.6": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x64": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
},
|
||||
".NETFramework,Version=v4.6/win7-x86": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project"
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"ClassLibrary1/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary1/ClassLibrary1.csproj"
|
||||
},
|
||||
"ClassLibrary2/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary2/ClassLibrary2.csproj"
|
||||
},
|
||||
"ClassLibrary3/1.0.0": {
|
||||
"type": "project",
|
||||
"msbuildProject": "../../ClassLibrary3/ClassLibrary3.csproj"
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"": [],
|
||||
".NETFramework,Version=v4.6": [
|
||||
"ClassLibrary1",
|
||||
"ClassLibrary2",
|
||||
"ClassLibrary3"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -84,8 +84,6 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
|||
libraryToPatch.RuntimeAssemblies = export.RuntimeAssemblies;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static IList<LockFileTargetLibrary> GetTargetsForLibrary(LockFile lockFile, LockFileProjectLibrary library)
|
||||
{
|
||||
return lockFile.Targets
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
|||
|
||||
return lockFile;
|
||||
}
|
||||
catch (LockFilePatchingException exception)
|
||||
catch (LockFilePatchingException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
// 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 FluentAssertions;
|
||||
using Xunit;
|
||||
using Microsoft.DotNet.ProjectModel.Graph;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel.Tests
|
||||
{
|
||||
public class LockFilePatchingTests : TestBase
|
||||
{
|
||||
|
||||
private string ExportFilesRoot=> Path.Combine(RepoRoot, "TestAssets", "LockFileSamples", "ExportFileSamples");
|
||||
|
||||
[Fact]
|
||||
public void TestValidPatching()
|
||||
{
|
||||
var lockFilePath = GetLockFilePath("valid");
|
||||
var lockFile = LockFileReader.Read(lockFilePath);
|
||||
|
||||
var exportFile = lockFile.ExportFile;
|
||||
|
||||
exportFile.Should().NotBeNull();
|
||||
exportFile.Exports.Count.Should().Be(3);
|
||||
exportFile.Exports.Should().OnlyHaveUniqueItems();
|
||||
|
||||
// check export structure
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var export = exportFile.Exports.ToList().ElementAt(i);
|
||||
|
||||
export.TargetFramework.Should().NotBeNull();
|
||||
|
||||
AssertTargetLibrary(i + 1, export);
|
||||
}
|
||||
|
||||
lockFile.Targets.Count.Should().Be(3);
|
||||
|
||||
// check lock file structure is similar to export structure
|
||||
foreach (var target in lockFile.Targets)
|
||||
{
|
||||
target.Libraries.Count.Should().Be(3);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var targetLibrary = target.Libraries.ElementAt(i);
|
||||
AssertTargetLibrary(i + 1, targetLibrary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMissingExportFileThrows()
|
||||
{
|
||||
var lockFilePath = GetLockFilePath("invalid_nofragment");
|
||||
|
||||
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMissingExportsThrow()
|
||||
{
|
||||
var lockFilePath = GetLockFilePath("invalid_missing-exports");
|
||||
|
||||
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMissmatchingFileVersionsThrows()
|
||||
{
|
||||
var lockFilePath = GetLockFilePath("invalid_missmatching-versions");
|
||||
|
||||
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath));
|
||||
}
|
||||
|
||||
private static void AssertTargetLibrary(int i, LockFileTargetLibrary export)
|
||||
{
|
||||
export.Type.Should().Be("project");
|
||||
|
||||
export.Name.Should().Be("ClassLibrary" + i);
|
||||
export.Version.ToNormalizedString().Should().Be("1.0.0");
|
||||
|
||||
var dll = $"bin/Debug/ClassLibrary{i}.dll";
|
||||
dll = dll.Replace('/', Path.DirectorySeparatorChar);
|
||||
|
||||
export.CompileTimeAssemblies.Count.Should().Be(1);
|
||||
export.CompileTimeAssemblies.ElementAt(0).Path.Should().Be(dll);
|
||||
|
||||
export.RuntimeAssemblies.Count.Should().Be(1);
|
||||
export.RuntimeAssemblies.ElementAt(0).Path.Should().Be(dll);
|
||||
}
|
||||
|
||||
private string GetLockFilePath(string exportSample)
|
||||
{
|
||||
return Path.Combine(ExportFilesRoot, exportSample, "project.lock.json");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue