Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expand-references command #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion DotNetPlease.Tests/Commands/ChangeNamespaceTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using DotNetPlease.TestUtils;
/*
* Morgan Stanley makes this available to you under the Apache License,
* Version 2.0 (the "License"). You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Unless required by applicable law or agreed
* to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

using DotNetPlease.TestUtils;
using FluentAssertions;
using System.Collections.Generic;
using System.Linq;
Expand Down
128 changes: 128 additions & 0 deletions DotNetPlease.Tests/Commands/ExpandReferencesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Morgan Stanley makes this available to you under the Apache License,
* Version 2.0 (the "License"). You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Unless required by applicable law or agreed
* to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

using FluentAssertions;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using static DotNetPlease.Helpers.DotNetCliHelper;
using static DotNetPlease.Helpers.MSBuildHelper;

namespace DotNetPlease.Commands;

public class ExpandReferencesTests : TestFixtureBase
{
[Theory, CombinatorialData]
public async Task It_replaces_PackageReference_with_ProjectReference(bool stage)
{
var (sourceSlnPath, sourceProjectPath) = CreateSolutionWithSingleProject("Source", "Package1");
var (targetSlnPath, targetProjectPath) = CreateSolutionWithSingleProject("Target", "Project1");
AddPackageReference(targetProjectPath, "Package1", "1.0.0");

if (stage) CreateSnapshot();

await RunAndAssertSuccess("expand-references", "Source/Source.sln", "Target/Target.sln", StageOption(stage));

if (stage)
{
VerifySnapshot();
return;
}

var projectReference = FindProjectReference(targetProjectPath, sourceProjectPath);
projectReference.Should().NotBeNull();

var packageReference = FindPackageReference(targetProjectPath, "Package1");
packageReference.Should().BeNull();
}

[Theory, CombinatorialData]
public async Task It_adds_the_project_from_PackageReference_to_the_solution(bool stage)
{
var (sourceSlnPath, sourceProjectPath) = CreateSolutionWithSingleProject("Source", "Package1");
var (targetSlnPath, targetProjectPath) = CreateSolutionWithSingleProject("Target", "Project1");
AddPackageReference(targetProjectPath, "Package1", "1.0.0");

if (stage) CreateSnapshot();

await RunAndAssertSuccess("expand-references", "Source/Source.sln", "Target/Target.sln", StageOption(stage));

if (stage)
{
VerifySnapshot();
return;
}

var projectsInSolution = GetProjectsFromSolution(targetSlnPath);
projectsInSolution.Should().Contain(sourceProjectPath);
}

[Theory, CombinatorialData]
public async Task It_replaces_Reference_with_ProjectReference(bool stage)
{
var (sourceSlnPath, sourceProjectPath) = CreateSolutionWithSingleProject("Source", "ClassLib1");
var (targetSlnPath, targetProjectPath) = CreateSolutionWithSingleProject("Target", "Project1");
AddAssemblyReference(targetProjectPath, "ClassLib1");

if (stage) CreateSnapshot();

await RunAndAssertSuccess("expand-references", "Source/Source.sln", "Target/Target.sln", StageOption(stage));

if (stage)
{
VerifySnapshot();
return;
}

var projectReference = FindProjectReference(targetProjectPath, sourceProjectPath);
projectReference.Should().NotBeNull();

var assemblyReference = FindAssemblyReference(targetProjectPath, "ClassLib1");
assemblyReference.Should().BeNull();
}

[Theory, CombinatorialData]
public async Task It_adds_the_project_from_Reference_to_the_solution(bool stage)
{
var (sourceSlnPath, sourceProjectPath) = CreateSolutionWithSingleProject("Source", "ClassLib1");
var (targetSlnPath, targetProjectPath) = CreateSolutionWithSingleProject("Target", "Project1");
AddAssemblyReference(targetProjectPath, "ClassLib1");

if (stage) CreateSnapshot();

await RunAndAssertSuccess("expand-references", "Source/Source.sln", "Target/Target.sln", StageOption(stage));

if (stage)
{
VerifySnapshot();
return;
}

var projectsInSolution = GetProjectsFromSolution(targetSlnPath);
projectsInSolution.Should().Contain(sourceProjectPath);
}

public ExpandReferencesTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }

private (string solutionPath, string projectPath) CreateSolutionWithSingleProject(string solutionName, string projectName)
{
var solutionPath = GetFullPath($"{solutionName}/{solutionName}.sln");
var projectPath = GetFullPath($"{solutionName}/{projectName}/{projectName}.csproj");
CreateProject(projectPath);
CreateSolution(solutionPath);
AddProjectToSolution(projectPath, solutionPath);

return (solutionPath, projectPath);
}
}
2 changes: 1 addition & 1 deletion DotNetPlease.Tests/DotNetPlease.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
<ProjectReference Include="..\DotNetPlease\DotNetPlease.csproj" />
</ItemGroup>

</Project>
</Project>
Loading
Loading