detect non-existing references and tiny refactor of tests
This commit is contained in:
parent
8e5ffaf176
commit
19dde128ba
3 changed files with 231 additions and 146 deletions
|
@ -29,11 +29,21 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
|
||||||
|
|
||||||
app.HelpOption("-h|--help");
|
app.HelpOption("-h|--help");
|
||||||
|
|
||||||
CommandArgument projectArgument = app.Argument("<PROJECT>",
|
CommandArgument projectArgument = app.Argument(
|
||||||
|
"<PROJECT>",
|
||||||
"The project file to modify. If a project file is not specified," +
|
"The project file to modify. If a project file is not specified," +
|
||||||
" it searches the current working directory for an MSBuild file that has a file extension that ends in `proj` and uses that file.");
|
" it searches the current working directory for an MSBuild file that has" +
|
||||||
|
" a file extension that ends in `proj` and uses that file.");
|
||||||
|
|
||||||
CommandOption frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Add reference only when targetting a specific framework", CommandOptionType.SingleValue);
|
CommandOption frameworkOption = app.Option(
|
||||||
|
"-f|--framework <FRAMEWORK>",
|
||||||
|
"Add reference only when targetting a specific framework",
|
||||||
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
|
CommandOption forceOption = app.Option(
|
||||||
|
"--force",
|
||||||
|
"Add reference even if it does not exist",
|
||||||
|
CommandOptionType.NoValue);
|
||||||
|
|
||||||
app.OnExecute(() => {
|
app.OnExecute(() => {
|
||||||
if (projectArgument.Value == null)
|
if (projectArgument.Value == null)
|
||||||
|
@ -50,10 +60,31 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
|
||||||
throw new GracefulException("You must specify at least one reference to add.");
|
throw new GracefulException("You must specify at least one reference to add.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<string> references = app.RemainingArguments;
|
||||||
|
if (!forceOption.HasValue())
|
||||||
|
{
|
||||||
|
var notExisting = new List<string>();
|
||||||
|
foreach (var r in references)
|
||||||
|
{
|
||||||
|
if (!File.Exists(r))
|
||||||
|
{
|
||||||
|
notExisting.Add(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notExisting.Count > 0)
|
||||||
|
{
|
||||||
|
throw new GracefulException(
|
||||||
|
string.Join(
|
||||||
|
Environment.NewLine,
|
||||||
|
notExisting.Select((ne) => $"Reference `{ne}` does not exist.")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int numberOfAddedReferences = AddProjectToProjectReference(
|
int numberOfAddedReferences = AddProjectToProjectReference(
|
||||||
project,
|
project,
|
||||||
frameworkOption.Value(),
|
frameworkOption.Value(),
|
||||||
app.RemainingArguments);
|
references);
|
||||||
|
|
||||||
if (numberOfAddedReferences != 0)
|
if (numberOfAddedReferences != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,25 +16,13 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
const string ConditionFrameworkNet451 = "== 'net451'";
|
const string ConditionFrameworkNet451 = "== 'net451'";
|
||||||
const string FrameworkNetCoreApp10Arg = "-f netcoreapp1.0";
|
const string FrameworkNetCoreApp10Arg = "-f netcoreapp1.0";
|
||||||
const string ConditionFrameworkNetCoreApp10 = "== 'netcoreapp1.0'";
|
const string ConditionFrameworkNetCoreApp10 = "== 'netcoreapp1.0'";
|
||||||
private static readonly string ValidRef = "ValidRef";
|
|
||||||
private static readonly string ValidRefCsproj = $"{ValidRef}.csproj";
|
|
||||||
private static readonly string ValidRefPath = Path.Combine("..", ValidRef, ValidRefCsproj);
|
|
||||||
|
|
||||||
private static readonly string LibRef = "Lib";
|
private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "")
|
||||||
private static readonly string LibRefCsproj = $"{LibRef}.csproj";
|
|
||||||
private static readonly string LibRefPath = Path.Combine("..", LibRef, LibRefCsproj);
|
|
||||||
|
|
||||||
private static readonly string AppPath = Path.Combine("App", "App.csproj");
|
|
||||||
private static readonly string Lib1Path = Path.Combine("Lib1", "Lib1.csproj");
|
|
||||||
private static readonly string Lib2Path = Path.Combine("Lib2", "Lib2.csproj");
|
|
||||||
private static readonly string Lib3Path = Path.Combine("Lib3", "Lib3.csproj");
|
|
||||||
private static readonly string Lib4Path = Path.Combine("Lib4", "Lib4.csproj");
|
|
||||||
|
|
||||||
private string Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "")
|
|
||||||
{
|
{
|
||||||
const string TestGroup = "NonRestoredTestProjects";
|
return new TestSetup(
|
||||||
const string ProjectName = "DotnetAddP2PProjects";
|
GetTestGroupTestAssetsManager(TestSetup.TestGroup)
|
||||||
return GetTestGroupTestAssetsManager(TestGroup).CreateTestInstance(ProjectName, callingMethod: callingMethod, identifier: identifier).Path;
|
.CreateTestInstance(TestSetup.ProjectName, callingMethod: callingMethod, identifier: identifier)
|
||||||
|
.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
||||||
|
@ -55,7 +43,7 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
}
|
}
|
||||||
catch (System.ComponentModel.Win32Exception e)
|
catch (System.ComponentModel.Win32Exception e)
|
||||||
{
|
{
|
||||||
throw new Exception($"DIDIDIDIDOIDIR: {dir.Path}\n{e}");
|
throw new Exception($"Intermittent error in `dotnet new` occurred when running it in dir `{dir.Path}`\nException:\n{e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir;
|
return dir;
|
||||||
|
@ -77,10 +65,12 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
public void WhenNonExistingProjectIsPassedItPrintsErrorAndUsage(string projName)
|
public void WhenNonExistingProjectIsPassedItPrintsErrorAndUsage(string projName)
|
||||||
{
|
{
|
||||||
string testRoot = NewDir().Path;
|
string testRoot = NewDir().Path;
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(testRoot)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(projName)
|
.WithProject(projName)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.ExitCode.Should().NotBe(0);
|
cmd.ExitCode.Should().NotBe(0);
|
||||||
cmd.StdErr.Should().Contain("Could not find");
|
cmd.StdErr.Should().Contain("Could not find");
|
||||||
cmd.StdOut.Should().Contain("Usage");
|
cmd.StdOut.Should().Contain("Usage");
|
||||||
|
@ -91,11 +81,12 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
public void WhenBrokenProjectIsPassedItPrintsErrorAndUsage()
|
public void WhenBrokenProjectIsPassedItPrintsErrorAndUsage()
|
||||||
{
|
{
|
||||||
string projName = "Broken/Broken.csproj";
|
string projName = "Broken/Broken.csproj";
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(testRoot)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(projName)
|
.WithProject(projName)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.ExitCode.Should().NotBe(0);
|
cmd.ExitCode.Should().NotBe(0);
|
||||||
cmd.StdErr.Should().Contain("Invalid project");
|
cmd.StdErr.Should().Contain("Invalid project");
|
||||||
cmd.StdOut.Should().Contain("Usage");
|
cmd.StdOut.Should().Contain("Usage");
|
||||||
|
@ -104,10 +95,11 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenMoreThanOneProjectExistsInTheDirectoryItPrintsErrorAndUsage()
|
public void WhenMoreThanOneProjectExistsInTheDirectoryItPrintsErrorAndUsage()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(Path.Combine(testRoot, "MoreThanOne"))
|
.WithWorkingDirectory(Path.Combine(setup.TestRoot, "MoreThanOne"))
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojRelPath}\"");
|
||||||
cmd.ExitCode.Should().NotBe(0);
|
cmd.ExitCode.Should().NotBe(0);
|
||||||
cmd.StdErr.Should().Contain("more than one");
|
cmd.StdErr.Should().Contain("more than one");
|
||||||
cmd.StdOut.Should().Contain("Usage");
|
cmd.StdOut.Should().Contain("Usage");
|
||||||
|
@ -116,10 +108,11 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenNoProjectsExistsInTheDirectoryItPrintsErrorAndUsage()
|
public void WhenNoProjectsExistsInTheDirectoryItPrintsErrorAndUsage()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(testRoot)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.ExitCode.Should().NotBe(0);
|
cmd.ExitCode.Should().NotBe(0);
|
||||||
cmd.StdErr.Should().Contain("not find any");
|
cmd.StdErr.Should().Contain("not find any");
|
||||||
cmd.StdOut.Should().Contain("Usage");
|
cmd.StdOut.Should().Contain("Usage");
|
||||||
|
@ -129,187 +122,194 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
public void ItAddsRefWithoutCondAndPrintsStatus()
|
public void ItAddsRefWithoutCondAndPrintsStatus()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
cmd.StdErr.Should().BeEmpty();
|
cmd.StdErr.Should().BeEmpty();
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefCsproj).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItAddsRefWithCondAndPrintsStatus()
|
public void ItAddsRefWithCondAndPrintsStatus()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{ValidRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
cmd.StdErr.Should().BeEmpty();
|
cmd.StdErr.Should().BeEmpty();
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
|
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(ValidRefCsproj, ConditionFrameworkNet451).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithoutCondIsPresentItAddsDifferentRefWithoutCond()
|
public void WhenRefWithoutCondIsPresentItAddsDifferentRefWithoutCond()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
new AddP2PCommand()
|
new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"\"{LibRefPath}\"")
|
.Execute($"\"{setup.LibCsprojPath}\"")
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(lib.Path)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjName)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefCsproj).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithCondIsPresentItAddsDifferentRefWithCond()
|
public void WhenRefWithCondIsPresentItAddsDifferentRefWithCond()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
new AddP2PCommand()
|
new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{LibRefPath}\"")
|
.Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojPath}\"")
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{ValidRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore);
|
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(ValidRefCsproj, ConditionFrameworkNet451).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithCondIsPresentItAddsRefWithDifferentCond()
|
public void WhenRefWithCondIsPresentItAddsRefWithDifferentCond()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
new AddP2PCommand()
|
new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNetCoreApp10Arg} \"{ValidRefPath}\"")
|
.Execute($"{FrameworkNetCoreApp10Arg} \"{setup.ValidRefCsprojPath}\"")
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{ValidRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
|
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(ValidRefCsproj, ConditionFrameworkNet451).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithConditionIsPresentItAddsDifferentRefWithoutCond()
|
public void WhenRefWithConditionIsPresentItAddsDifferentRefWithoutCond()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
new AddP2PCommand()
|
new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{LibRefPath}\"")
|
.Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojPath}\"")
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
|
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefCsproj).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithNoCondAlreadyExistsItDoesntDuplicate()
|
public void WhenRefWithNoCondAlreadyExistsItDoesntDuplicate()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
new AddP2PCommand()
|
new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"\"{ValidRefPath}\"")
|
.Execute($"\"{setup.ValidRefCsprojPath}\"")
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(lib.Path)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjName)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("already has a reference");
|
cmd.StdOut.Should().Contain("already has a reference");
|
||||||
|
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefCsproj).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithCondOnItemAlreadyExistsItDoesntDuplicate()
|
public void WhenRefWithCondOnItemAlreadyExistsItDoesntDuplicate()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithExistingRefCondOnItem"));
|
||||||
|
|
||||||
string projDir = Path.Combine(testRoot, "WithExistingRefCondOnItem");
|
string contentBefore = proj.CsProjContent();
|
||||||
string projName = Path.Combine(projDir, "WithExistingRefCondOnItem.csproj");
|
|
||||||
string contentBefore = File.ReadAllText(projName);
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(projDir)
|
.WithWorkingDirectory(proj.Path)
|
||||||
.WithProject(projName)
|
.WithProject(proj.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{LibRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojRelPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("already has a reference");
|
cmd.StdOut.Should().Contain("already has a reference");
|
||||||
File.ReadAllText(projName).Should().BeEquivalentTo(contentBefore);
|
proj.CsProjContent().Should().BeEquivalentTo(contentBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithCondOnItemGroupAlreadyExistsItDoesntDuplicate()
|
public void WhenRefWithCondOnItemGroupAlreadyExistsItDoesntDuplicate()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
new AddP2PCommand()
|
new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{ValidRefPath}\"")
|
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"")
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
var csprojContentBefore = lib.CsProjContent();
|
var csprojContentBefore = lib.CsProjContent();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{ValidRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("already has a reference");
|
cmd.StdOut.Should().Contain("already has a reference");
|
||||||
lib.CsProjContent().Should().BeEquivalentTo(csprojContentBefore);
|
lib.CsProjContent().Should().BeEquivalentTo(csprojContentBefore);
|
||||||
|
@ -318,173 +318,171 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithCondWithWhitespaceOnItemGroupExistsItDoesntDuplicate()
|
public void WhenRefWithCondWithWhitespaceOnItemGroupExistsItDoesntDuplicate()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithExistingRefCondWhitespaces"));
|
||||||
|
|
||||||
string projDir = Path.Combine(testRoot, "WithExistingRefCondWhitespaces");
|
string contentBefore = proj.CsProjContent();
|
||||||
string projName = Path.Combine(projDir, "WithExistingRefCondWhitespaces.csproj");
|
|
||||||
string contentBefore = File.ReadAllText(projName);
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(projDir)
|
.WithWorkingDirectory(proj.Path)
|
||||||
.WithProject(projName)
|
.WithProject(proj.CsProjName)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{LibRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojRelPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("already has a reference");
|
cmd.StdOut.Should().Contain("already has a reference");
|
||||||
File.ReadAllText(projName).Should().BeEquivalentTo(contentBefore);
|
proj.CsProjContent().Should().BeEquivalentTo(contentBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithoutCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate()
|
public void WhenRefWithoutCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithRefNoCondNonUniform"));
|
||||||
|
|
||||||
string projDir = Path.Combine(testRoot, "WithRefNoCondNonUniform");
|
string contentBefore = proj.CsProjContent();
|
||||||
string projName = Path.Combine(projDir, "WithRefNoCondNonUniform.csproj");
|
|
||||||
string contentBefore = File.ReadAllText(projName);
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(projDir)
|
.WithWorkingDirectory(proj.Path)
|
||||||
.WithProject(projName)
|
.WithProject(proj.CsProjName)
|
||||||
.Execute($"\"{LibRefPath}\"");
|
.Execute($"\"{setup.LibCsprojRelPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("already has a reference");
|
cmd.StdOut.Should().Contain("already has a reference");
|
||||||
File.ReadAllText(projName).Should().BeEquivalentTo(contentBefore);
|
proj.CsProjContent().Should().BeEquivalentTo(contentBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithoutCondAlreadyExistsInNonUniformItemGroupItAddsDifferentRefInDifferentGroup()
|
public void WhenRefWithoutCondAlreadyExistsInNonUniformItemGroupItAddsDifferentRefInDifferentGroup()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithRefNoCondNonUniform"));
|
||||||
var proj = new ProjDir(Path.Combine(testRoot, "WithRefNoCondNonUniform"));
|
|
||||||
|
|
||||||
int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(proj.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(proj.CsProjPath)
|
.WithProject(proj.CsProjPath)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
var csproj = proj.CsProj();
|
var csproj = proj.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefPath).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate()
|
public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithRefCondNonUniform"));
|
||||||
|
|
||||||
string projDir = Path.Combine(testRoot, "WithRefCondNonUniform");
|
string contentBefore = proj.CsProjContent();
|
||||||
string projName = Path.Combine(projDir, "WithRefCondNonUniform.csproj");
|
|
||||||
string contentBefore = File.ReadAllText(projName);
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(projDir)
|
.WithWorkingDirectory(proj.Path)
|
||||||
.WithProject(projName)
|
.WithProject(proj.CsProjName)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{LibRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojRelPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("already has a reference");
|
cmd.StdOut.Should().Contain("already has a reference");
|
||||||
File.ReadAllText(projName).Should().BeEquivalentTo(contentBefore);
|
proj.CsProjContent().Should().BeEquivalentTo(contentBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItAddsDifferentRefInDifferentGroup()
|
public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItAddsDifferentRefInDifferentGroup()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithRefCondNonUniform"));
|
||||||
var proj = new ProjDir(Path.Combine(testRoot, "WithRefCondNonUniform"));
|
|
||||||
|
|
||||||
int condBefore = proj.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
int condBefore = proj.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(proj.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(proj.CsProjPath)
|
.WithProject(proj.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{ValidRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
var csproj = proj.CsProj();
|
var csproj = proj.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
|
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(ValidRefPath, ConditionFrameworkNet451).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenEmptyItemGroupPresentItAddsRefInIt()
|
public void WhenEmptyItemGroupPresentItAddsRefInIt()
|
||||||
{
|
{
|
||||||
string testRoot = Setup();
|
var setup = Setup();
|
||||||
|
var proj = new ProjDir(Path.Combine(setup.TestRoot, "EmptyItemGroup"));
|
||||||
var proj = new ProjDir(Path.Combine(testRoot, "EmptyItemGroup"));
|
|
||||||
|
|
||||||
int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(proj.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(proj.CsProjPath)
|
.WithProject(proj.CsProjPath)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
var csproj = proj.CsProj();
|
var csproj = proj.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefPath).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItAddsMultipleRefsNoCondToTheSameItemGroup()
|
public void ItAddsMultipleRefsNoCondToTheSameItemGroup()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"\"{LibRefPath}\" \"{ValidRefPath}\"");
|
.Execute($"\"{setup.LibCsprojPath}\" \"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project").And.NotContain("already has a reference");
|
cmd.StdOut.Should().Contain("added to the project").And.NotContain("already has a reference");
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefCsproj).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(LibRefPath).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.LibCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItAddsMultipleRefsWithCondToTheSameItemGroup()
|
public void ItAddsMultipleRefsWithCondToTheSameItemGroup()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjPath)
|
||||||
.Execute($"{FrameworkNet451Arg} \"{LibRefPath}\" \"{ValidRefPath}\"");
|
.Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojPath}\" \"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project").And.NotContain("already has a reference");
|
cmd.StdOut.Should().Contain("added to the project").And.NotContain("already has a reference");
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(noCondBefore + 1);
|
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(noCondBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(ValidRefCsproj, ConditionFrameworkNet451).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(LibRefPath, ConditionFrameworkNet451).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.LibCsprojName, ConditionFrameworkNet451).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenProjectNameIsNotPassedItFindsItAndAddsReference()
|
public void WhenProjectNameIsNotPassedItFindsItAndAddsReference()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(lib.Path)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
cmd.StdErr.Should().BeEmpty();
|
cmd.StdErr.Should().BeEmpty();
|
||||||
var csproj = lib.CsProj();
|
var csproj = lib.CsProj();
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefCsproj).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItAddsRefBetweenImports()
|
public void ItAddsRefBetweenImports()
|
||||||
{
|
{
|
||||||
var lib = NewLib();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
var cmd = new AddP2PCommand()
|
var cmd = new AddP2PCommand()
|
||||||
.WithWorkingDirectory(lib.Path)
|
.WithWorkingDirectory(lib.Path)
|
||||||
.WithProject(lib.CsProjName)
|
.WithProject(lib.CsProjName)
|
||||||
.Execute($"\"{ValidRefPath}\"");
|
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||||
cmd.Should().Pass();
|
cmd.Should().Pass();
|
||||||
cmd.StdOut.Should().Contain("added to the project");
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
cmd.StdErr.Should().BeEmpty();
|
cmd.StdErr.Should().BeEmpty();
|
||||||
|
@ -503,7 +501,7 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (projRef != null && projRef.ItemType == "ProjectReference" && projRef.Include.Contains(ValidRefCsproj))
|
if (projRef != null && projRef.ItemType == "ProjectReference" && projRef.Include.Contains(setup.ValidRefCsprojName))
|
||||||
{
|
{
|
||||||
state++;
|
state++;
|
||||||
}
|
}
|
||||||
|
@ -520,16 +518,36 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
state.Should().Be(3);
|
state.Should().Be(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Skip = "Not finished")]
|
[Fact]
|
||||||
public void WhenPassedReferenceDoesNotExistItShowsAnError()
|
public void WhenPassedReferenceDoesNotExistItShowsAnError()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var lib = NewLib();
|
||||||
|
|
||||||
|
var contentBefore = lib.CsProjContent();
|
||||||
|
var cmd = new AddP2PCommand()
|
||||||
|
.WithWorkingDirectory(lib.Path)
|
||||||
|
.WithProject(lib.CsProjName)
|
||||||
|
.Execute("\"IDoNotExist.csproj\"");
|
||||||
|
cmd.Should().Fail();
|
||||||
|
cmd.StdErr.Should().Contain("does not exist");
|
||||||
|
lib.CsProjContent().Should().BeEquivalentTo(contentBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Skip = "Not finished")]
|
[Fact]
|
||||||
public void WhenPassedMultipleRefsAndOneOfthemDoesNotExistItCancelsWholeOperation()
|
public void WhenPassedMultipleRefsAndOneOfthemDoesNotExistItCancelsWholeOperation()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var lib = NewLib();
|
||||||
|
var setup = Setup();
|
||||||
|
|
||||||
|
var contentBefore = lib.CsProjContent();
|
||||||
|
var cmd = new AddP2PCommand()
|
||||||
|
.WithWorkingDirectory(setup.TestRoot)
|
||||||
|
.WithProject(lib.CsProjPath)
|
||||||
|
.Execute($"\"{setup.ValidRefCsprojPath}\" \"IDoNotExist.csproj\"");
|
||||||
|
cmd.Should().Fail();
|
||||||
|
cmd.StdErr.Should().Contain("does not exist");
|
||||||
|
cmd.StdErr.Should().NotMatchRegex("(.*does not exist.*){2,}");
|
||||||
|
lib.CsProjContent().Should().BeEquivalentTo(contentBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Skip = "Not finished")]
|
[Fact(Skip = "Not finished")]
|
||||||
|
|
36
test/dotnet-add-p2p.Tests/TestSetup.cs
Normal file
36
test/dotnet-add-p2p.Tests/TestSetup.cs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
using Microsoft.DotNet.TestFramework;
|
||||||
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
|
{
|
||||||
|
internal class TestSetup
|
||||||
|
{
|
||||||
|
public const string TestGroup = "NonRestoredTestProjects";
|
||||||
|
public const string ProjectName = "DotnetAddP2PProjects";
|
||||||
|
|
||||||
|
public string TestRoot { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
private const string ValidRef = "ValidRef";
|
||||||
|
public string ValidRefCsprojName => $"{ValidRef}.csproj";
|
||||||
|
public string ValidRefCsprojPath => Path.Combine(TestRoot, ValidRef, ValidRefCsprojName);
|
||||||
|
public string ValidRefCsprojRelPath => Path.Combine("..", ValidRef, ValidRefCsprojName);
|
||||||
|
|
||||||
|
|
||||||
|
private const string Lib = "Lib";
|
||||||
|
public string LibCsprojName => $"{Lib}.csproj";
|
||||||
|
public string LibCsprojPath => Path.Combine(TestRoot, Lib, LibCsprojName);
|
||||||
|
public string LibCsprojRelPath => Path.Combine("..", Lib, LibCsprojName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public TestSetup(string testRoot)
|
||||||
|
{
|
||||||
|
TestRoot = testRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue