|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using System.Xml.Linq; |
| 7 | +using FluentAssertions; |
| 8 | +using Microsoft.NET.TestFramework; |
| 9 | +using Microsoft.NET.TestFramework.Assertions; |
| 10 | +using Microsoft.NET.TestFramework.Commands; |
| 11 | +using Microsoft.NET.TestFramework.ProjectConstruction; |
| 12 | +using Xunit; |
| 13 | +using Xunit.Abstractions; |
| 14 | + |
| 15 | +namespace Microsoft.NET.Build.Tests |
| 16 | +{ |
| 17 | + public class KnownRuntimePackTests : SdkTest |
| 18 | + { |
| 19 | + public KnownRuntimePackTests(ITestOutputHelper log) : base(log) |
| 20 | + { |
| 21 | + } |
| 22 | + |
| 23 | + [Fact] |
| 24 | + public void BuildSucceedsWithRuntimePackWithDifferentLabel() |
| 25 | + { |
| 26 | + var testProject = new TestProject() |
| 27 | + { |
| 28 | + TargetFrameworks = "net5.0", |
| 29 | + IsSdkProject = true, |
| 30 | + IsExe = true, |
| 31 | + RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid() |
| 32 | + }; |
| 33 | + |
| 34 | + var testAsset = _testAssetsManager.CreateTestProject(testProject); |
| 35 | + |
| 36 | + var knownRuntimePack = CreateTestKnownRuntimePack(); |
| 37 | + |
| 38 | + AddItem(testAsset, knownRuntimePack); |
| 39 | + |
| 40 | + var buildCommand = new BuildCommand(testAsset); |
| 41 | + |
| 42 | + buildCommand |
| 43 | + .Execute() |
| 44 | + .Should() |
| 45 | + .Pass(); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public void DuplicateRuntimePackCausesFailure() |
| 50 | + { |
| 51 | + var testProject = new TestProject() |
| 52 | + { |
| 53 | + TargetFrameworks = "net5.0", |
| 54 | + IsSdkProject = true, |
| 55 | + IsExe = true, |
| 56 | + RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid() |
| 57 | + }; |
| 58 | + |
| 59 | + var testAsset = _testAssetsManager.CreateTestProject(testProject); |
| 60 | + |
| 61 | + var knownRuntimePack = CreateTestKnownRuntimePack(); |
| 62 | + knownRuntimePack.Attribute("RuntimePackLabels").Value = ""; |
| 63 | + |
| 64 | + AddItem(testAsset, knownRuntimePack); |
| 65 | + |
| 66 | + var buildCommand = new BuildCommand(testAsset); |
| 67 | + |
| 68 | + buildCommand |
| 69 | + .Execute() |
| 70 | + .Should() |
| 71 | + .Fail() |
| 72 | + .And |
| 73 | + .HaveStdOutContaining("NETSDK1133"); |
| 74 | + } |
| 75 | + |
| 76 | + [Fact] |
| 77 | + public void RuntimePackWithLabelIsSelected() |
| 78 | + { |
| 79 | + var testProject = new TestProject() |
| 80 | + { |
| 81 | + TargetFrameworks = "net5.0", |
| 82 | + IsSdkProject = true, |
| 83 | + IsExe = true, |
| 84 | + RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid() |
| 85 | + }; |
| 86 | + |
| 87 | + var testAsset = _testAssetsManager.CreateTestProject(testProject); |
| 88 | + |
| 89 | + var knownRuntimePack = CreateTestKnownRuntimePack(); |
| 90 | + |
| 91 | + AddItem(testAsset, knownRuntimePack); |
| 92 | + |
| 93 | + var frameworkReferenceUpdate = new XElement("FrameworkReference", |
| 94 | + new XAttribute("Update", "Microsoft.NETCore.App"), |
| 95 | + new XAttribute("RuntimePackLabels", "Mono")); |
| 96 | + |
| 97 | + AddItem(testAsset, frameworkReferenceUpdate); |
| 98 | + |
| 99 | + var getValuesCommand = new GetValuesCommand(testAsset, "RuntimePack", GetValuesCommand.ValueType.Item) |
| 100 | + { |
| 101 | + DependsOnTargets = "ProcessFrameworkReferences", |
| 102 | + ShouldRestore = false |
| 103 | + }; |
| 104 | + |
| 105 | + getValuesCommand |
| 106 | + .Execute() |
| 107 | + .Should() |
| 108 | + .Pass(); |
| 109 | + |
| 110 | + // StartsWith instead of exact match because current RID is likely to be more specific than the runtime pack RID |
| 111 | + getValuesCommand.GetValues().Should().Contain(rp => rp.StartsWith("Microsoft.NETCore.App.Runtime.Mono.")); |
| 112 | + |
| 113 | + } |
| 114 | + |
| 115 | + private XElement CreateTestKnownRuntimePack() |
| 116 | + { |
| 117 | + var knownRuntimePack = new XElement("KnownRuntimePack", |
| 118 | + new XAttribute("Include", "Microsoft.NETCore.App"), |
| 119 | + new XAttribute("TargetFramework", "net5.0"), |
| 120 | + new XAttribute("RuntimeFrameworkName", "Microsoft.NETCore.App"), |
| 121 | + new XAttribute("DefaultRuntimeFrameworkVersion", "5.0.0-preview1"), |
| 122 | + new XAttribute("LatestRuntimeFrameworkVersion", "5.0.0-preview1.1"), |
| 123 | + new XAttribute("RuntimePackNamePatterns", "Microsoft.NETCore.App.Runtime.Mono.**RID**"), |
| 124 | + new XAttribute("RuntimePackRuntimeIdentifiers", "linux-arm;linux-arm64;linux-musl-arm64;linux-musl-x64;linux-x64;osx-x64;rhel.6-x64;tizen.4.0.0-armel;tizen.5.0.0-armel;win-arm;win-arm64;win-x64;win-x86;ios-arm64;ios-arm;ios-x64;ios-x86;tvos-arm64;tvos-x64;android-arm64;android-arm;android-x64;android-x86;browser-wasm"), |
| 125 | + new XAttribute("IsTrimmable", "true"), |
| 126 | + new XAttribute("RuntimePackLabels", "Mono")); |
| 127 | + |
| 128 | + return knownRuntimePack; |
| 129 | + } |
| 130 | + |
| 131 | + private void AddItem(TestAsset testAsset, XElement item) |
| 132 | + { |
| 133 | + testAsset.WithProjectChanges(project => |
| 134 | + { |
| 135 | + var ns = project.Root.Name.Namespace; |
| 136 | + |
| 137 | + var itemGroup = new XElement(ns + "ItemGroup"); |
| 138 | + project.Root.Add(itemGroup); |
| 139 | + itemGroup.Add(item); |
| 140 | + }); |
| 141 | + } |
| 142 | + } |
| 143 | +} |
0 commit comments