complete tests
This commit is contained in:
parent
23b46490a3
commit
0349aed9a7
5 changed files with 313 additions and 13 deletions
|
@ -0,0 +1,3 @@
|
|||
public class WithDoubledRef
|
||||
{
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
<EmbeddedResource Include="**\*.resx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Sdk">
|
||||
<Version>1.0.0-alpha-20161104-2</Version>
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
|
||||
<PackageReference Include="Microsoft.NETCore.App">
|
||||
<Version>1.0.1</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lib\Lib.csproj" />
|
||||
<ProjectReference Include="..\Lib\Lib.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -57,7 +57,8 @@ namespace Msbuild.Tests.Utilities
|
|||
string itemType,
|
||||
string includePattern)
|
||||
{
|
||||
return root.Items.Where((it) => it.ItemType == itemType && it.Include.Contains(includePattern));
|
||||
return root.Items.Where((it) => it.ItemType == itemType && it.Include.Contains(includePattern)
|
||||
&& it.ConditionChain().Count() == 0);
|
||||
}
|
||||
|
||||
public static int NumberOfProjectReferencesWithIncludeContaining(
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Msbuild.Tests.Utilities
|
|||
public string TestRoot { get; private set; }
|
||||
|
||||
private const string ValidRef = "ValidRef";
|
||||
public string ValidRefDir => Path.Combine(TestRoot, ValidRef);
|
||||
public string ValidRefCsprojName => $"{ValidRef}.csproj";
|
||||
public string ValidRefCsprojRelPath => Path.Combine(ValidRef, ValidRefCsprojName);
|
||||
public string ValidRefCsprojPath => Path.Combine(TestRoot, ValidRefCsprojRelPath);
|
||||
|
|
|
@ -52,6 +52,35 @@ namespace Microsoft.DotNet.Cli.Remove.P2P.Tests
|
|||
return dir;
|
||||
}
|
||||
|
||||
private ProjDir GetLibRef(TestSetup setup)
|
||||
{
|
||||
return new ProjDir(setup.LibDir);
|
||||
}
|
||||
|
||||
private ProjDir AddLibRef(TestSetup setup, ProjDir proj, string additionalArgs = "")
|
||||
{
|
||||
var ret = GetLibRef(setup);
|
||||
new AddP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(proj.CsProjPath)
|
||||
.Execute($"{additionalArgs} \"{ret.CsProjPath}\"")
|
||||
.Should().Pass();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private ProjDir AddValidRef(TestSetup setup, ProjDir proj, string frameworkArg = "")
|
||||
{
|
||||
var ret = new ProjDir(setup.ValidRefDir);
|
||||
new AddP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(proj.CsProjPath)
|
||||
.Execute($"{frameworkArg} \"{ret.CsProjPath}\"")
|
||||
.Should().Pass();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("--help")]
|
||||
[InlineData("-h")]
|
||||
|
@ -122,49 +151,288 @@ namespace Microsoft.DotNet.Cli.Remove.P2P.Tests
|
|||
[Fact]
|
||||
public void ItRemovesRefWithoutCondAndPrintsStatus()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var libref = AddLibRef(setup, lib);
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{libref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItRemovesRefWithConAndPrintsStatus()
|
||||
public void ItRemovesRefWithCondAndPrintsStatus()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var libref = AddLibRef(setup, lib, FrameworkNet451Arg);
|
||||
|
||||
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"{FrameworkNet451Arg} \"{libref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(libref.Name, ConditionFrameworkNet451).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenTwoRefsArePresentItDoesNotRemoveBoth()
|
||||
public void WhenTwoDifferentRefsArePresentItDoesNotRemoveBoth()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var libref = AddLibRef(setup, lib);
|
||||
var validref = AddValidRef(setup, lib);
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{libref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
cmd.StdOut.Should().NotContain(validref.Name);
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenRefWithoutCondIsNotThereItPrintsMessage()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var libref = GetLibRef(setup);
|
||||
|
||||
string csprojContetntBefore = lib.CsProjContent();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{libref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().Contain("could not be found");
|
||||
lib.CsProjContent().Should().BeEquivalentTo(csprojContetntBefore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenRefWithCondIsNotThereItPrintsMessage()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var libref = GetLibRef(setup);
|
||||
|
||||
string csprojContetntBefore = lib.CsProjContent();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"{FrameworkNet451Arg} \"{libref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().Contain("could not be found");
|
||||
lib.CsProjContent().Should().BeEquivalentTo(csprojContetntBefore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenRefWithCondIsPresentAndRemovingNoCondItDoesNotRemoveIt()
|
||||
public void WhenRefWithAndWithoutCondArePresentAndRemovingNoCondItDoesNotRemoveOther()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg);
|
||||
var librefNoCond = AddLibRef(setup, lib);
|
||||
|
||||
var csprojBefore = lib.CsProj();
|
||||
int noCondBefore = csprojBefore.NumberOfItemGroupsWithoutCondition();
|
||||
int condBefore = csprojBefore.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{librefNoCond.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(0);
|
||||
|
||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore);
|
||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(librefCond.Name, ConditionFrameworkNet451).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenRefWithoutCondIsPresentAndRemovingRefWithCondItDoesNotRemoveIt()
|
||||
public void WhenRefWithAndWithoutCondArePresentAndRemovingCondItDoesNotRemoveOther()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg);
|
||||
var librefNoCond = AddLibRef(setup, lib);
|
||||
|
||||
var csprojBefore = lib.CsProj();
|
||||
int noCondBefore = csprojBefore.NumberOfItemGroupsWithoutCondition();
|
||||
int condBefore = csprojBefore.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"{FrameworkNet451Arg} \"{librefCond.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(1);
|
||||
|
||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(librefCond.Name, ConditionFrameworkNet451).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenRefWithDifferentCondIsPresentItDoesNotRemoveIt()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var librefCondNet451 = AddLibRef(setup, lib, FrameworkNet451Arg);
|
||||
var librefCondNetCoreApp10 = AddLibRef(setup, lib, FrameworkNetCoreApp10Arg);
|
||||
|
||||
var csprojBefore = lib.CsProj();
|
||||
int condNet451Before = csprojBefore.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||
int condNetCoreApp10Before = csprojBefore.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNetCoreApp10);
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"{FrameworkNet451Arg} \"{librefCondNet451.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condNet451Before - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(librefCondNet451.Name, ConditionFrameworkNet451).Should().Be(0);
|
||||
|
||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNetCoreApp10).Should().Be(condNetCoreApp10Before);
|
||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(librefCondNetCoreApp10.Name, ConditionFrameworkNetCoreApp10).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenDuplicateReferencesArePresentItRemovesThemAll()
|
||||
{
|
||||
var setup = Setup();
|
||||
var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithDoubledRef"));
|
||||
var libref = GetLibRef(setup);
|
||||
|
||||
int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(proj.CsProjPath)
|
||||
.Execute($"\"{libref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
|
||||
var csproj = proj.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenPassingRefWithRelPathItRemovesRefWithAbsolutePath()
|
||||
{
|
||||
var setup = Setup();
|
||||
var lib = GetLibRef(setup);
|
||||
var libref = AddValidRef(setup, lib, "--force");
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(lib.Path)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenPassingRefWithRelPathToProjectItRemovesRefWithPathRelToProject()
|
||||
{
|
||||
var setup = Setup();
|
||||
var lib = GetLibRef(setup);
|
||||
var libref = AddValidRef(setup, lib);
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenPassingRefWithAbsolutePathItRemovesRefWithRelPath()
|
||||
{
|
||||
var setup = Setup();
|
||||
var lib = GetLibRef(setup);
|
||||
var libref = AddValidRef(setup, lib);
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenPassingMultipleReferencesItRemovesThemAll()
|
||||
{
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var libref = AddLibRef(setup, lib);
|
||||
var validref = AddValidRef(setup, lib);
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{libref.CsProjPath}\" \"{validref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(validref.Name).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenPassingMultipleReferencesAndOneOfThemDoesNotExistItRemovesOne()
|
||||
{
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
var libref = GetLibRef(setup);
|
||||
var validref = AddValidRef(setup, lib);
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new RemoveP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute($"\"{libref.CsProjPath}\" \"{validref.CsProjPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");
|
||||
cmd.StdOut.Should().Contain("could not be found");
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(validref.Name).Should().Be(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue