Add support for accepting directories to add and remove reference commands.

This commit adds support for specifying directories containing a single
project to both the `add reference` and `remove reference` commands.

Fixes issue #7343.
This commit is contained in:
Peter Huene 2017-12-07 17:19:51 -08:00
parent bcf13b93cc
commit 1ddf5c87c7
No known key found for this signature in database
GPG key ID: E1D265D820213D6A
19 changed files with 125 additions and 76 deletions

View file

@ -559,7 +559,7 @@ Commands:
.WithProject(lib.CsProjName)
.Execute("\"IDoNotExist.csproj\"");
cmd.Should().Fail();
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.ReferenceDoesNotExist, "IDoNotExist.csproj"));
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindProjectOrDirectory, "IDoNotExist.csproj"));
lib.CsProjContent().Should().BeEquivalentTo(contentBefore);
}
@ -575,7 +575,7 @@ Commands:
.WithProject(lib.CsProjPath)
.Execute($"\"{setup.ValidRefCsprojPath}\" \"IDoNotExist.csproj\"");
cmd.Should().Fail();
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.ReferenceDoesNotExist, "IDoNotExist.csproj"));
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindProjectOrDirectory, "IDoNotExist.csproj"));
lib.CsProjContent().Should().BeEquivalentTo(contentBefore);
}
@ -693,5 +693,55 @@ Commands:
cmd.StdErr.Should().MatchRegex(" - net45");
net45lib.CsProjContent().Should().BeEquivalentTo(csProjContent);
}
[Fact]
public void WhenDirectoryContainingProjectIsGivenReferenceIsAdded()
{
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
var result = new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
.WithProject(lib.CsProjPath)
.Execute($"\"{Path.GetDirectoryName(setup.ValidRefCsprojPath)}\"");
result.Should().Pass();
result.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @"ValidRef\ValidRef.csproj"));
result.StdErr.Should().BeEmpty();
}
[Fact]
public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation()
{
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
var reference = "Empty";
var result = new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
.WithProject(lib.CsProjPath)
.Execute(reference);
result.Should().Fail();
result.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
result.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindAnyProjectInDirectory, reference));
}
[Fact]
public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation()
{
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
var reference = "MoreThanOne";
var result = new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
.WithProject(lib.CsProjPath)
.Execute(reference);
result.Should().Fail();
result.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
result.StdErr.Should().Be(string.Format(CommonLocalizableStrings.MoreThanOneProjectInDirectory, reference));
}
}
}