Skip to content

Commit d6d0778

Browse files
committed
Add tests from dotnet#49314
1 parent f548112 commit d6d0778

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
5+
namespace Microsoft.DotNet.Cli.Package.Remove.Tests;
6+
7+
public sealed class GivenDotnetPackageRemove(ITestOutputHelper log) : SdkTest(log)
8+
{
9+
[Fact]
10+
public void WhenPackageIsRemovedWithoutProjectArgument()
11+
{
12+
var projectDirectory = _testAssetsManager
13+
.CopyTestAsset("TestAppSimple")
14+
.WithSource().Path;
15+
16+
const string packageName = "Newtonsoft.Json";
17+
new DotnetCommand(Log)
18+
.WithWorkingDirectory(projectDirectory)
19+
.Execute("add", "package", packageName)
20+
.Should().Pass();
21+
22+
// Test the new 'dotnet package remove' command without specifying project
23+
new DotnetCommand(Log)
24+
.WithWorkingDirectory(projectDirectory)
25+
.Execute("package", "remove", packageName)
26+
.Should().Pass()
27+
.And.HaveStdOutContaining($"Removing PackageReference for package '{packageName}' from project '{projectDirectory + Path.DirectorySeparatorChar}TestAppSimple.csproj'.")
28+
.And.NotHaveStdErr();
29+
}
30+
31+
[Fact]
32+
public void WhenPackageIsRemovedWithProjectOption()
33+
{
34+
var projectDirectory = _testAssetsManager
35+
.CopyTestAsset("TestAppSimple")
36+
.WithSource().Path;
37+
38+
const string packageName = "Newtonsoft.Json";
39+
new DotnetCommand(Log)
40+
.WithWorkingDirectory(projectDirectory)
41+
.Execute("add", "package", packageName)
42+
.Should().Pass();
43+
44+
// Test the new 'dotnet package remove' command with --project option
45+
new DotnetCommand(Log)
46+
.WithWorkingDirectory(projectDirectory)
47+
.Execute("package", "remove", packageName, "--project", "TestAppSimple.csproj")
48+
.Should().Pass()
49+
.And.HaveStdOutContaining($"Removing PackageReference for package '{packageName}' from project 'TestAppSimple.csproj'.")
50+
.And.NotHaveStdErr();
51+
}
52+
53+
[Fact]
54+
public void WhenNoPackageIsPassedCommandFails()
55+
{
56+
var projectDirectory = _testAssetsManager
57+
.CopyTestAsset("TestAppSimple")
58+
.WithSource()
59+
.Path;
60+
61+
new DotnetCommand(Log)
62+
.WithWorkingDirectory(projectDirectory)
63+
.Execute("package", "remove")
64+
.Should()
65+
.Fail();
66+
}
67+
68+
[Fact]
69+
public void WhenMultiplePackagesArePassedCommandFails()
70+
{
71+
var projectDirectory = _testAssetsManager
72+
.CopyTestAsset("TestAppSimple")
73+
.WithSource()
74+
.Path;
75+
76+
new DotnetCommand(Log)
77+
.WithWorkingDirectory(projectDirectory)
78+
.Execute("package", "remove", "package1", "package2")
79+
.Should()
80+
.Fail();
81+
}
82+
}

0 commit comments

Comments
 (0)