Skip to content

Commit 7f9e329

Browse files
committed
Fix tests' edge cases
1 parent 2c9a4e9 commit 7f9e329

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public override int Execute()
5757
{
5858
throw new GracefulException(CommonLocalizableStrings.InvalidSolutionFormatString, solutionFileFullPath, ex.Message);
5959
}
60+
// TODO: Check
61+
if (ex.InnerException is GracefulException)
62+
{
63+
throw ex.InnerException;
64+
}
6065
throw new GracefulException(ex.Message, ex);
6166
}
6267
}
@@ -81,7 +86,6 @@ private async Task RemoveProjectsAsync(string solutionFileFullPath, IEnumerable<
8186
if (project != null)
8287
{
8388
solution.RemoveProject(project);
84-
8589
Reporter.Output.WriteLine(CommonLocalizableStrings.ProjectRemovedFromTheSolution, projectPath);
8690
}
8791
else
@@ -91,6 +95,18 @@ private async Task RemoveProjectsAsync(string solutionFileFullPath, IEnumerable<
9195
}
9296

9397
// TODO: Remove empty solution folders
98+
HashSet<SolutionFolderModel> emptySolutionFolders = solution.SolutionFolders.ToHashSet();
99+
foreach (var item in solution.SolutionItems)
100+
{
101+
if (item.Parent != null)
102+
{
103+
emptySolutionFolders.Remove(item.Parent);
104+
}
105+
}
106+
foreach (var emptySolutionFolder in emptySolutionFolders)
107+
{
108+
solution.RemoveFolder(emptySolutionFolder);
109+
}
94110

95111
await serializer.SaveAsync(solutionFileFullPath, solution, cancellationToken);
96112
}

test/dotnet-sln.Tests/GivenDotnetSlnRemove.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ dotnet solution <SLN_FILE> remove [<PROJECT_PATH>...] [options]
6464
VisualStudioVersion = 15.0.26006.2
6565
MinimumVisualStudioVersion = 10.0.40219.1
6666
Global
67+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
68+
Debug|Any CPU = Debug|Any CPU
69+
Debug|x64 = Debug|x64
70+
Debug|x86 = Debug|x86
71+
Release|Any CPU = Release|Any CPU
72+
Release|x64 = Release|x64
73+
Release|x86 = Release|x86
74+
EndGlobalSection
75+
GlobalSection(SolutionProperties) = preSolution
76+
HideSolutionNode = FALSE
77+
EndGlobalSection
6778
EndGlobal
6879
";
6980

@@ -317,7 +328,7 @@ public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage(string solutionComm
317328
.WithWorkingDirectory(projectDirectory)
318329
.Execute(solutionCommand, "InvalidSolution.sln", "remove", projectToRemove);
319330
cmd.Should().Fail();
320-
cmd.StdErr.Should().Match(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", "*"));
331+
cmd.StdErr.Should().Match(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, Path.Combine(projectDirectory, "InvalidSolution.sln"), "*"));
321332
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized("");
322333
}
323334

@@ -474,7 +485,7 @@ public void WhenSolutionItemsExistInFolderParentFoldersAreNotRemoved(string solu
474485
.BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemoveProjectInSolutionWithNestedSolutionItems);
475486
}
476487

477-
[Theory]
488+
[Theory(Skip = "vs-solutionpersistence does not allow duplicate references.")]
478489
[InlineData("sln")]
479490
[InlineData("solution")]
480491
public void WhenDuplicateReferencesArePresentItRemovesThemAll(string solutionCommand)

0 commit comments

Comments
 (0)