Skip to content

Commit 4e9565d

Browse files
authored
Add test case for adding projects outside solution dir descendants (#46835)
1 parent c82cd2e commit 4e9565d

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26006.2
5+
MinimumVisualStudioVersion = 10.0.40219.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Solution />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard1.4</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
namespace Lib
7+
{
8+
public class Library
9+
{
10+
public static string GetMessage()
11+
{
12+
return "Message from Lib";
13+
}
14+
}
15+
}

test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,29 @@ public void WhenSolutionFolderIsPassedWithDirectorySeparatorFolderStructureIsCor
10961096
.Should().BeVisuallyEquivalentTo(expectedSlnContents);
10971097
}
10981098

1099+
[Theory]
1100+
[InlineData("sln", ".sln")]
1101+
[InlineData("sln", ".slnx")]
1102+
[InlineData("solution", ".sln")]
1103+
[InlineData("solution", ".slnx")]
1104+
public async Task WhenAddingProjectOutsideDirectoryItShouldNotAddSolutionFolders(string solutionCommand, string solutionExtension)
1105+
{
1106+
var projectDirectory = _testAssetsManager
1107+
.CopyTestAsset("TestAppWithSlnAndCsprojInParentDir", identifier: $"GivenDotnetSlnAdd-{solutionCommand}{solutionExtension}")
1108+
.WithSource()
1109+
.Path;
1110+
var projectToAdd = Path.Combine("..", "Lib", "Lib.csproj");
1111+
var cmd = new DotnetCommand(Log)
1112+
.WithWorkingDirectory(Path.Join(projectDirectory, "Dir"))
1113+
.Execute(solutionCommand, $"App{solutionExtension}", "add", projectToAdd);
1114+
cmd.Should().Pass();
1115+
// Should have no solution folders
1116+
ISolutionSerializer serializer = SolutionSerializers.GetSerializerByMoniker(Path.Join(projectDirectory, "Dir", $"App{solutionExtension}"));
1117+
SolutionModel solution = await serializer.OpenAsync(Path.Join(projectDirectory, "Dir", $"App{solutionExtension}"), CancellationToken.None);
1118+
solution.SolutionProjects.Count.Should().Be(1);
1119+
solution.SolutionFolders.Count.Should().Be(0);
1120+
}
1121+
10991122
private string GetExpectedSlnContents(
11001123
string slnPath,
11011124
string slnTemplateName,

0 commit comments

Comments
 (0)