Skip to content

Commit 47218e8

Browse files
committed
Fix tests' edge cases
1 parent 2c9a4e9 commit 47218e8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Cli/dotnet/commands/dotnet-sln/remove/Program.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ private async Task RemoveProjectsAsync(string solutionFileFullPath, IEnumerable<
8181
if (project != null)
8282
{
8383
solution.RemoveProject(project);
84-
8584
Reporter.Output.WriteLine(CommonLocalizableStrings.ProjectRemovedFromTheSolution, projectPath);
8685
}
8786
else
@@ -91,6 +90,18 @@ private async Task RemoveProjectsAsync(string solutionFileFullPath, IEnumerable<
9190
}
9291

9392
// TODO: Remove empty solution folders
93+
HashSet<SolutionFolderModel> emptySolutionFolders = solution.SolutionFolders.ToHashSet();
94+
foreach (var item in solution.SolutionItems)
95+
{
96+
if (item.Parent != null)
97+
{
98+
emptySolutionFolders.Remove(item.Parent);
99+
}
100+
}
101+
foreach (var emptySolutionFolder in emptySolutionFolders)
102+
{
103+
solution.RemoveFolder(emptySolutionFolder);
104+
}
94105

95106
await serializer.SaveAsync(solutionFileFullPath, solution, cancellationToken);
96107
}

test/dotnet-sln.Tests/GivenDotnetSlnRemove.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage(string solutionComm
317317
.WithWorkingDirectory(projectDirectory)
318318
.Execute(solutionCommand, "InvalidSolution.sln", "remove", projectToRemove);
319319
cmd.Should().Fail();
320-
cmd.StdErr.Should().Match(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", "*"));
320+
cmd.StdErr.Should().Match(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, Path.Combine(projectDirectory, "InvalidSolution.sln"), "*"));
321321
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized("");
322322
}
323323

0 commit comments

Comments
 (0)