Skip to content

Commit db23fc9

Browse files
CopilotmarcpopMSFT
andcommitted
Add test for dotnet restore with -r, --os, and -a options
Co-authored-by: marcpopMSFT <[email protected]>
1 parent 8d6284c commit db23fc9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/dotnet.Tests/CommandTests/Restore/GivenThatIWantToRestoreApp.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.DotNet.Tools.Test.Utilities;
5+
using System.Runtime.InteropServices;
56

67
namespace Microsoft.DotNet.Restore.Test
78
{
@@ -167,6 +168,44 @@ public void ItAcceptsArgumentsAfterProperties()
167168
.Should()
168169
.Pass();
169170
}
171+
172+
/// <summary>
173+
/// Tests for RID-specific restore options: -r/--runtime, --os, and -a/--arch
174+
/// </summary>
175+
[Theory]
176+
[InlineData("-r", "linux-x64")]
177+
[InlineData("--runtime", "win-x64")]
178+
[InlineData("--os", "linux")]
179+
[InlineData("-a", "arm64")]
180+
[InlineData("--arch", "x64")]
181+
[InlineData("--os", "linux", "-a", "arm64")]
182+
public void ItRestoresWithRidSpecificOptions(params string[] ridOptions)
183+
{
184+
// Skip test for #24251
185+
var testProject = new TestProject()
186+
{
187+
Name = "RestoreWithRidOptions",
188+
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
189+
};
190+
191+
testProject.PackageReferences.Add(new TestPackageReference("Newtonsoft.Json", ToolsetInfo.GetNewtonsoftJsonPackageVersion()));
192+
193+
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: string.Join("_", ridOptions));
194+
195+
var rootPath = Path.Combine(testAsset.TestRoot, testProject.Name);
196+
197+
// Create the command with the RID-specific options
198+
var restoreCommand = new DotnetRestoreCommand(Log)
199+
.WithWorkingDirectory(rootPath)
200+
.Execute(ridOptions);
201+
202+
// Verify that the command runs successfully
203+
restoreCommand.Should().Pass();
204+
205+
// Verify that assets file was created
206+
var assetsFilePath = Path.Combine(rootPath, "obj", "project.assets.json");
207+
File.Exists(assetsFilePath).Should().BeTrue();
208+
}
170209

171210
private static string[] HandleStaticGraphEvaluation(bool useStaticGraphEvaluation, string[] args) =>
172211
useStaticGraphEvaluation ?

0 commit comments

Comments
 (0)