Fix tests
This commit is contained in:
parent
1d7cff48d4
commit
1658a40806
4 changed files with 42 additions and 53 deletions
|
@ -30,8 +30,10 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
{
|
{
|
||||||
var runtime = string.Empty;
|
var runtime = string.Empty;
|
||||||
var target = string.Empty;
|
var target = string.Empty;
|
||||||
|
var isPortable = true;
|
||||||
|
|
||||||
|
var runtimeTargetName = root[DependencyContextStrings.RuntimeTargetPropertyName]?.Value<string>();
|
||||||
|
|
||||||
var runtimeTargetInfo = ReadRuntimeTargetInfo(root);
|
|
||||||
var libraryStubs = ReadLibraryStubs((JObject) root[DependencyContextStrings.LibrariesPropertyName]);
|
var libraryStubs = ReadLibraryStubs((JObject) root[DependencyContextStrings.LibrariesPropertyName]);
|
||||||
var targetsObject = (JObject) root[DependencyContextStrings.TargetsPropertyName];
|
var targetsObject = (JObject) root[DependencyContextStrings.TargetsPropertyName];
|
||||||
|
|
||||||
|
@ -45,18 +47,19 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
compileTarget = (JObject)compileTargetProperty.Value;
|
compileTarget = (JObject)compileTargetProperty.Value;
|
||||||
target = compileTargetProperty.Name;
|
target = compileTargetProperty.Name;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(runtimeTargetInfo.Name))
|
if (!string.IsNullOrEmpty(runtimeTargetName))
|
||||||
{
|
{
|
||||||
runtimeTarget = (JObject) targetsObject[runtimeTargetInfo.Name];
|
runtimeTarget = (JObject) targetsObject[runtimeTargetName];
|
||||||
if (runtimeTarget == null)
|
if (runtimeTarget == null)
|
||||||
{
|
{
|
||||||
throw new FormatException($"Target with name {runtimeTargetInfo.Name} not found");
|
throw new FormatException($"Target with name {runtimeTargetName} not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
var seperatorIndex = runtimeTargetInfo.Name.IndexOf(DependencyContextStrings.VersionSeperator);
|
var seperatorIndex = runtimeTargetName.IndexOf(DependencyContextStrings.VersionSeperator);
|
||||||
if (seperatorIndex > -1 && seperatorIndex < runtimeTargetInfo.Name.Length)
|
if (seperatorIndex > -1 && seperatorIndex < runtimeTargetName.Length)
|
||||||
{
|
{
|
||||||
runtime = runtimeTargetInfo.Name.Substring(seperatorIndex + 1);
|
runtime = runtimeTargetName.Substring(seperatorIndex + 1);
|
||||||
|
isPortable = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -68,7 +71,7 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
return new DependencyContext(
|
return new DependencyContext(
|
||||||
target,
|
target,
|
||||||
runtime,
|
runtime,
|
||||||
runtimeTargetInfo.Portable,
|
isPortable,
|
||||||
ReadCompilationOptions((JObject)root[DependencyContextStrings.CompilationOptionsPropertName]),
|
ReadCompilationOptions((JObject)root[DependencyContextStrings.CompilationOptionsPropertName]),
|
||||||
ReadLibraries(compileTarget, false, libraryStubs).Cast<CompilationLibrary>().ToArray(),
|
ReadLibraries(compileTarget, false, libraryStubs).Cast<CompilationLibrary>().ToArray(),
|
||||||
ReadLibraries(runtimeTarget, true, libraryStubs).Cast<RuntimeLibrary>().ToArray(),
|
ReadLibraries(runtimeTarget, true, libraryStubs).Cast<RuntimeLibrary>().ToArray(),
|
||||||
|
@ -91,24 +94,6 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RuntimeTargetInfo ReadRuntimeTargetInfo(JObject root)
|
|
||||||
{
|
|
||||||
|
|
||||||
var runtimeTarget = (JObject)root[DependencyContextStrings.RuntimeTargetPropertyName];
|
|
||||||
if (runtimeTarget != null)
|
|
||||||
{
|
|
||||||
return new RuntimeTargetInfo()
|
|
||||||
{
|
|
||||||
Name = runtimeTarget[DependencyContextStrings.RuntimeTargetNamePropertyName]?.Value<string>(),
|
|
||||||
Portable = runtimeTarget[DependencyContextStrings.PortablePropertyName]?.Value<bool>() == true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return new RuntimeTargetInfo()
|
|
||||||
{
|
|
||||||
Portable = true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private CompilationOptions ReadCompilationOptions(JObject compilationOptionsObject)
|
private CompilationOptions ReadCompilationOptions(JObject compilationOptionsObject)
|
||||||
{
|
{
|
||||||
if (compilationOptionsObject == null)
|
if (compilationOptionsObject == null)
|
||||||
|
@ -268,13 +253,6 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
public string Rid;
|
public string Rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct RuntimeTargetInfo
|
|
||||||
{
|
|
||||||
public string Name;
|
|
||||||
|
|
||||||
public bool Portable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private struct LibraryStub
|
private struct LibraryStub
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
|
|
|
@ -36,16 +36,11 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JObject WriteRuntimeTargetInfo(DependencyContext context)
|
private string WriteRuntimeTargetInfo(DependencyContext context)
|
||||||
{
|
{
|
||||||
var target = context.IsPortable?
|
return context.IsPortable?
|
||||||
context.TargetFramework :
|
context.TargetFramework :
|
||||||
context.TargetFramework + DependencyContextStrings.VersionSeperator + context.Runtime;
|
context.TargetFramework + DependencyContextStrings.VersionSeperator + context.Runtime;
|
||||||
|
|
||||||
return new JObject(
|
|
||||||
new JProperty(DependencyContextStrings.RuntimeTargetNamePropertyName, target),
|
|
||||||
new JProperty(DependencyContextStrings.PortablePropertyName, context.IsPortable)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JObject WriteRuntimeGraph(DependencyContext context)
|
private JObject WriteRuntimeGraph(DependencyContext context)
|
||||||
|
|
|
@ -24,10 +24,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
{
|
{
|
||||||
var context = Read(
|
var context = Read(
|
||||||
@"{
|
@"{
|
||||||
""runtimeTarget"": {
|
""runtimeTarget"": "".NETStandardApp,Version=v1.5/osx.10.10-x64"",
|
||||||
""portable"": false,
|
|
||||||
""name"": "".NETStandardApp,Version=v1.5/osx.10.10-x64"",
|
|
||||||
},
|
|
||||||
""targets"": {
|
""targets"": {
|
||||||
"".NETStandardApp,Version=v1.5"": {},
|
"".NETStandardApp,Version=v1.5"": {},
|
||||||
"".NETStandardApp,Version=v1.5/osx.10.10-x64"": {},
|
"".NETStandardApp,Version=v1.5/osx.10.10-x64"": {},
|
||||||
|
@ -47,6 +44,32 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
context.IsPortable.Should().BeTrue();
|
context.IsPortable.Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetsPortableIfRuntimeTargetHasNoRid()
|
||||||
|
{
|
||||||
|
var context = Read(
|
||||||
|
@"{
|
||||||
|
""runtimeTarget"": "".NETStandardApp,Version=v1.5"",
|
||||||
|
""targets"": {
|
||||||
|
"".NETStandardApp,Version=v1.5"": {}
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
context.IsPortable.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetsNotPortableIfRuntimeTargetHasRid()
|
||||||
|
{
|
||||||
|
var context = Read(
|
||||||
|
@"{
|
||||||
|
""runtimeTarget"": "".NETStandardApp,Version=v1.5/osx.10.10-x64""
|
||||||
|
""targets"": {
|
||||||
|
"".NETStandardApp,Version=v1.5/osx.10.10-x64"": {}
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
context.IsPortable.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ReadsMainTarget()
|
public void ReadsMainTarget()
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,14 +86,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
false)
|
false)
|
||||||
);
|
);
|
||||||
|
|
||||||
var runtimeTarget = result.Should().HaveProperty("runtimeTarget")
|
result.Should().HavePropertyValue("runtimeTarget", "Target/runtime");
|
||||||
.Subject.Should().BeOfType<JObject>().Subject;
|
|
||||||
|
|
||||||
runtimeTarget.Should().HaveProperty("name")
|
|
||||||
.Subject.Value<string>().Should().Be("Target/runtime");
|
|
||||||
|
|
||||||
runtimeTarget.Should().HaveProperty("portable")
|
|
||||||
.Subject.Value<bool>().Should().Be(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -169,7 +162,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
"HASH",
|
"HASH",
|
||||||
new [] { RuntimeAssembly.Create("Banana.dll")},
|
new [] { RuntimeAssembly.Create("Banana.dll")},
|
||||||
new []
|
new []
|
||||||
{Lock
|
{
|
||||||
new RuntimeTarget("win7-x64",
|
new RuntimeTarget("win7-x64",
|
||||||
new [] { RuntimeAssembly.Create("Banana.Win7-x64.dll") },
|
new [] { RuntimeAssembly.Create("Banana.Win7-x64.dll") },
|
||||||
new [] { "Banana.Win7-x64.so" }
|
new [] { "Banana.Win7-x64.so" }
|
||||||
|
|
Loading…
Add table
Reference in a new issue