More work and tests
This commit is contained in:
parent
9bd9ca1512
commit
dcaea8c7ca
13 changed files with 389 additions and 69 deletions
|
@ -109,9 +109,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
},
|
||||
""libraries"":{
|
||||
""MyApp/1.0.1"": {
|
||||
""type"": ""project"",
|
||||
""serviceable"": true,
|
||||
""sha512"": ""HASH-MyApp""
|
||||
""type"": ""project""
|
||||
},
|
||||
""System.Banana/1.0.0"": {
|
||||
""type"": ""package"",
|
||||
|
@ -124,11 +122,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
var project = context.CompileLibraries.Should().Contain(l => l.PackageName == "MyApp").Subject;
|
||||
project.Version.Should().Be("1.0.1");
|
||||
project.Assemblies.Should().BeEquivalentTo("MyApp.dll");
|
||||
project.Hash.Should().Be("HASH-MyApp");
|
||||
project.LibraryType.Should().Be("project");
|
||||
project.Serviceable.Should().Be(true);
|
||||
project.Hash.Should().BeEquivalentTo("HASH-MyApp");
|
||||
|
||||
|
||||
var package = context.CompileLibraries.Should().Contain(l => l.PackageName == "System.Banana").Subject;
|
||||
package.Version.Should().Be("1.0.0");
|
||||
|
@ -137,5 +131,71 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
package.LibraryType.Should().Be("package");
|
||||
package.Serviceable.Should().Be(false);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ReadsRuntimeLibrariesWithSubtargetsFromMainTargetForPortable()
|
||||
{
|
||||
var context = Read(
|
||||
@"{
|
||||
""runtimeTarget"": {
|
||||
""portable"": true,
|
||||
""name"": "".NETStandardApp,Version=v1.5"",
|
||||
},
|
||||
""targets"": {
|
||||
"".NETStandardApp,Version=v1.5"": {
|
||||
""MyApp/1.0.1"": {
|
||||
""dependencies"": {
|
||||
""AspNet.Mvc"": ""1.0.0""
|
||||
},
|
||||
""runtime"": {
|
||||
""MyApp.dll"": { }
|
||||
}
|
||||
},
|
||||
""System.Banana/1.0.0"": {
|
||||
""dependencies"": {
|
||||
""System.Foo"": ""1.0.0""
|
||||
},
|
||||
""runtime"": {
|
||||
""lib/dotnet5.4/System.Banana.dll"": { }
|
||||
},
|
||||
""runtimeTargets"": {
|
||||
""lib/win7/System.Banana.dll"": { ""assetType"": ""runtime"", ""rid"": ""win7-x64""},
|
||||
""lib/win7/Banana.dll"": { ""assetType"": ""native"", ""rid"": ""win7-x64""}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
""libraries"":{
|
||||
""MyApp/1.0.1"": {
|
||||
""type"": ""project"",
|
||||
},
|
||||
""System.Banana/1.0.0"": {
|
||||
""type"": ""package"",
|
||||
""serviceable"": false,
|
||||
""sha512"": ""HASH-System.Banana""
|
||||
},
|
||||
}
|
||||
}");
|
||||
context.CompileLibraries.Should().HaveCount(2);
|
||||
var project = context.RuntimeLibraries.Should().Contain(l => l.PackageName == "MyApp").Subject;
|
||||
project.Version.Should().Be("1.0.1");
|
||||
project.Assemblies.Should().Contain(a => a.Path == "MyApp.dll");
|
||||
project.LibraryType.Should().Be("project");
|
||||
|
||||
|
||||
var package = context.RuntimeLibraries.Should().Contain(l => l.PackageName == "System.Banana").Subject;
|
||||
package.Version.Should().Be("1.0.0");
|
||||
package.Hash.Should().Be("HASH-System.Banana");
|
||||
package.LibraryType.Should().Be("package");
|
||||
package.Serviceable.Should().Be(false);
|
||||
package.Assemblies.Should().Contain(a => a.Path == "lib/dotnet5.4/System.Banana.dll");
|
||||
|
||||
var target = package.SubTargets.Should().Contain(t => t.Runtime == "win7-x64").Subject;
|
||||
target.Assemblies.Should().Contain(a => a.Path == "lib/win7/System.Banana.dll");
|
||||
target.NativeLibraries.Should().Contain("lib/win7/Banana.dll");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,17 +30,33 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public DependencyContext Create(
|
||||
string target = null,
|
||||
string runtime = null,
|
||||
bool? isPortable = null,
|
||||
CompilationOptions compilationOptions = null,
|
||||
CompilationLibrary[] compileLibraries = null,
|
||||
RuntimeLibrary[] runtimeLibraries = null,
|
||||
IReadOnlyList<KeyValuePair<string, string[]>> runtimeGraph = null)
|
||||
{
|
||||
return new DependencyContext(
|
||||
target,
|
||||
runtime,
|
||||
isPortable ?? false,
|
||||
compilationOptions ?? CompilationOptions.Default,
|
||||
compileLibraries ?? new CompilationLibrary[0],
|
||||
runtimeLibraries ?? new RuntimeLibrary[0],
|
||||
runtimeGraph ?? new KeyValuePair<string, string[]>[0]
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SavesRuntimeGraph()
|
||||
{
|
||||
var result = Save(new DependencyContext(
|
||||
var result = Save(Create(
|
||||
"Target",
|
||||
"Target/runtime",
|
||||
false,
|
||||
CompilationOptions.Default,
|
||||
new CompilationLibrary[0],
|
||||
new RuntimeLibrary[0],
|
||||
new[]
|
||||
runtimeGraph: new[]
|
||||
{
|
||||
new KeyValuePair<string, string[]>("win7-x64", new [] { "win6", "win5"}),
|
||||
new KeyValuePair<string, string[]>("win8-x64", new [] { "win7-x64"}),
|
||||
|
@ -64,14 +80,10 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
[Fact]
|
||||
public void WritesRuntimeTargetPropertyIfNotPortable()
|
||||
{
|
||||
var result = Save(new DependencyContext(
|
||||
var result = Save(Create(
|
||||
"Target",
|
||||
"runtime",
|
||||
false,
|
||||
CompilationOptions.Default,
|
||||
new CompilationLibrary[0],
|
||||
new RuntimeLibrary[0],
|
||||
new KeyValuePair<string, string[]>[0])
|
||||
false)
|
||||
);
|
||||
|
||||
var runtimeTarget = result.Should().HaveProperty("runtimeTarget")
|
||||
|
@ -83,20 +95,118 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
runtimeTarget.Should().HaveProperty("portable")
|
||||
.Subject.Value<bool>().Should().Be(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DoesNotWritesRuntimeTargetPropertyIfPortable()
|
||||
public void WritesMainTargetNameToRuntimeTargetIfPortable()
|
||||
{
|
||||
var result = Save(new DependencyContext(
|
||||
var result = Save(Create(
|
||||
"Target",
|
||||
"runtime",
|
||||
false,
|
||||
CompilationOptions.Default,
|
||||
new CompilationLibrary[0],
|
||||
new RuntimeLibrary[0],
|
||||
new KeyValuePair<string, string[]>[0])
|
||||
true)
|
||||
);
|
||||
var runtimeTarget = result.Should().HaveProperty("runtimeTarget")
|
||||
.Subject.Should().BeOfType<JObject>().Subject;
|
||||
|
||||
result.Should().NotHaveProperty("runtimeTarget");
|
||||
runtimeTarget.Should().HaveProperty("name")
|
||||
.Subject.Value<string>().Should().Be("Target");
|
||||
|
||||
runtimeTarget.Should().HaveProperty("portable")
|
||||
.Subject.Value<bool>().Should().Be(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WritesCompilationLibraries()
|
||||
{
|
||||
var result = Save(Create(
|
||||
"Target",
|
||||
"runtime",
|
||||
true,
|
||||
compileLibraries: new[]
|
||||
{
|
||||
new CompilationLibrary(
|
||||
"package",
|
||||
"PackageName",
|
||||
"1.2.3",
|
||||
"HASH",
|
||||
new [] {"Banana.dll"},
|
||||
new [] {
|
||||
new Dependency("Fruits.Abstract.dll","2.0.0")
|
||||
},
|
||||
true
|
||||
)
|
||||
}));
|
||||
|
||||
// targets
|
||||
var targets = result.Should().HavePropertyAsObject("targets").Subject;
|
||||
var target = targets.Should().HavePropertyAsObject("Target").Subject;
|
||||
var library = target.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
|
||||
var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject;
|
||||
dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0");
|
||||
library.Should().HavePropertyAsObject("compile")
|
||||
.Subject.Should().HaveProperty("Banana.dll");
|
||||
|
||||
//libraries
|
||||
var libraries = result.Should().HavePropertyAsObject("libraries").Subject;
|
||||
library = libraries.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
|
||||
library.Should().HavePropertyValue("sha512", "HASH");
|
||||
library.Should().HavePropertyValue("type", "package");
|
||||
library.Should().HavePropertyValue("serviceable", true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WritesRuntimeLibrariesToRuntimeTarget()
|
||||
{
|
||||
var result = Save(Create(
|
||||
"Target",
|
||||
"runtime",
|
||||
true,
|
||||
runtimeLibraries: new[]
|
||||
{
|
||||
new RuntimeLibrary(
|
||||
"package",
|
||||
"PackageName",
|
||||
"1.2.3",
|
||||
"HASH",
|
||||
new [] { RuntimeAssembly.Create("Banana.dll")},
|
||||
new []
|
||||
{
|
||||
new RuntimeTarget("win7-x64",
|
||||
new [] { RuntimeAssembly.Create("Banana.Win7-x64.dll") },
|
||||
new [] { "Banana.Win7-x64.so" }
|
||||
)
|
||||
},
|
||||
new [] {
|
||||
new Dependency("Fruits.Abstract.dll","2.0.0")
|
||||
},
|
||||
true
|
||||
),
|
||||
}));
|
||||
|
||||
// targets
|
||||
var targets = result.Should().HavePropertyAsObject("targets").Subject;
|
||||
var target = targets.Should().HavePropertyAsObject("Target").Subject;
|
||||
var library = target.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
|
||||
var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject;
|
||||
dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0");
|
||||
library.Should().HavePropertyAsObject("runtime")
|
||||
.Subject.Should().HaveProperty("Banana.dll");
|
||||
|
||||
var runtimeTargets = library.Should().HavePropertyAsObject("target").Subject;
|
||||
|
||||
var runtimeAssembly = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.dll").Subject;
|
||||
runtimeAssembly.Should().HavePropertyValue("rid", "win7-x64");
|
||||
runtimeAssembly.Should().HavePropertyValue("assetType", "runtime");
|
||||
|
||||
var nativeLibrary = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.so").Subject;
|
||||
nativeLibrary.Should().HavePropertyValue("rid", "win7-x64");
|
||||
nativeLibrary.Should().HavePropertyValue("assetType", "native");
|
||||
|
||||
//libraries
|
||||
var libraries = result.Should().HavePropertyAsObject("libraries").Subject;
|
||||
library = libraries.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
|
||||
library.Should().HavePropertyValue("sha512", "HASH");
|
||||
library.Should().HavePropertyValue("type", "package");
|
||||
library.Should().HavePropertyValue("serviceable", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,5 +45,15 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
|
||||
return new AndConstraint<JsonAssetions>(this);
|
||||
}
|
||||
|
||||
public AndWhichConstraint<JsonAssetions, JObject> HavePropertyAsObject(string expected)
|
||||
{
|
||||
return HaveProperty(expected).Subject.Should().BeOfType<JObject>();
|
||||
}
|
||||
|
||||
public AndConstraint<ObjectAssertions> HavePropertyValue<T>(string expected, T value)
|
||||
{
|
||||
return HaveProperty(expected).Subject.Value<T>().Should().Be(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue