Skip to content

Commit 2effe62

Browse files
committed
Add unit test for GetAllRuntimeIdentifiers
1 parent 11ebca3 commit 2effe62

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildACrossTargetedLibrary.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
using Microsoft.NET.TestFramework.Commands;
99
using Xunit;
1010
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
11+
using System.Xml.Linq;
12+
using System.Linq;
13+
using FluentAssertions;
1114

1215
namespace Microsoft.NET.Build.Tests
1316
{
@@ -79,5 +82,55 @@ public void It_builds_desktop_library_successfully_on_windows()
7982
"netstandard1.5/DesktopAndNetStandard.deps.json"
8083
});
8184
}
85+
86+
[Theory]
87+
[InlineData("1", "win7-x86", "win7-x86;win7-x64", "win10-arm", "win7-x86;linux;WIN7-X86;unix", "osx-10.12", "win8-arm;win8-arm-aot",
88+
"win7-x86;win7-x64;win10-arm;linux;unix;osx-10.12;win8-arm;win8-arm-aot")]
89+
public void It_combines_inner_rids_for_restore(
90+
string identifier,
91+
string outerRid,
92+
string outerRids,
93+
string firstFrameworkRid,
94+
string firstFrameworkRids,
95+
string secondFrameworkRid,
96+
string secondFrameworkRids,
97+
string expectedCombination)
98+
{
99+
100+
if (UsingFullFrameworkMSBuild)
101+
{
102+
// Remove when Jenkins has desktop msbuild without import of Microsoft.NuGet.targets
103+
// https://github.com/dotnet/sdk/issues/874
104+
expectedCombination += ";win;win-x86;win-x64";
105+
}
106+
107+
var testAsset = _testAssetsManager
108+
.CopyTestAsset(Path.Combine("CrossTargeting", "NetStandardAndNetCoreApp"), identifier: identifier)
109+
.WithSource()
110+
.WithProjectChanges(project =>
111+
{
112+
var ns = project.Root.Name.Namespace;
113+
var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
114+
115+
propertyGroup.Add(
116+
new XElement(ns + "RuntimeIdentifier", outerRid),
117+
new XElement(ns + "RuntimeIdentifiers", outerRids));
118+
119+
propertyGroup.AddAfterSelf(
120+
new XElement(ns + "PropertyGroup",
121+
new XAttribute(ns + "Condition", "'$(TargetFramework)' == 'netstandard1.5'"),
122+
new XElement(ns + "RuntimeIdentifier", firstFrameworkRid),
123+
new XElement(ns + "RuntimeIdentifiers", firstFrameworkRids)),
124+
new XElement(ns + "PropertyGroup",
125+
new XAttribute(ns + "Condition", "'$(TargetFramework)' == 'netcoreapp1.0'"),
126+
new XElement(ns + "RuntimeIdentifier", secondFrameworkRid),
127+
new XElement(ns + "RuntimeIdentifiers", secondFrameworkRids)));
128+
});
129+
130+
var command = new GetValuesCommand(Stage0MSBuild, testAsset.TestRoot, "", valueName: "RuntimeIdentifiers");
131+
command.DependsOnTargets = "GetAllRuntimeIdentifiers";
132+
command.Execute().Should().Pass();
133+
command.GetValues().Should().BeEquivalentTo(expectedCombination.Split(';'));
134+
}
82135
}
83136
}

test/Microsoft.NET.TestFramework/Commands/GetValuesCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public enum ValueType
2424

2525
public bool ShouldCompile { get; set; } = true;
2626

27+
public string DependsOnTargets { get; set; } = "Compile";
28+
2729
public string Configuration { get; set; }
2830

2931
public GetValuesCommand(MSBuildTest msbuild, string projectPath, string targetFramework,
@@ -58,7 +60,7 @@ public override CommandResult Execute(params string[] args)
5860
<PropertyGroup>
5961
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
6062
</PropertyGroup>
61-
<Target Name=`WriteValuesToFile` " + (ShouldCompile ? "DependsOnTargets=`Compile`" : "") + $@">
63+
<Target Name=`WriteValuesToFile` " + (ShouldCompile ? $"DependsOnTargets=`{DependsOnTargets}`" : "") + $@">
6264
<WriteLinesToFile
6365
File=`bin\$(Configuration)\$(TargetFramework)\{_valueName}Values.txt`
6466
{linesAttribute}

0 commit comments

Comments
 (0)