Lock on spec - all tests passing on Windows
This commit is contained in:
parent
19dde128ba
commit
58fe57e315
4 changed files with 120 additions and 79 deletions
|
@ -11,43 +11,6 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
|||
{
|
||||
internal static class Extensions
|
||||
{
|
||||
//public static int CountOccurrances(this string s, string pattern)
|
||||
//{
|
||||
// int ret = 0;
|
||||
// for (int i = s.IndexOf(pattern); i != -1; i = s.IndexOf(pattern, i + 1))
|
||||
// {
|
||||
// ret++;
|
||||
// }
|
||||
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
//public static int NumberOfLinesWith(this string s, params string[] patterns)
|
||||
//{
|
||||
// int ret = 0;
|
||||
// string[] lines = s.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
// foreach (var line in lines)
|
||||
// {
|
||||
// bool shouldCount = true;
|
||||
|
||||
// foreach (var p in patterns)
|
||||
// {
|
||||
// if (!line.Contains(p))
|
||||
// {
|
||||
// shouldCount = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (shouldCount)
|
||||
// {
|
||||
// ret++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
public static int NumberOfItemGroupsWithConditionContaining(this ProjectRootElement root, string patternInCondition)
|
||||
{
|
||||
return root.ItemGroups.Count((ig) => ig.Condition.Contains(patternInCondition));
|
||||
|
|
|
@ -64,7 +64,6 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
|||
[InlineData("ihave?inv@lid/char\\acters")]
|
||||
public void WhenNonExistingProjectIsPassedItPrintsErrorAndUsage(string projName)
|
||||
{
|
||||
string testRoot = NewDir().Path;
|
||||
var setup = Setup();
|
||||
|
||||
var cmd = new AddP2PCommand()
|
||||
|
@ -99,7 +98,7 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
|||
|
||||
var cmd = new AddP2PCommand()
|
||||
.WithWorkingDirectory(Path.Combine(setup.TestRoot, "MoreThanOne"))
|
||||
.Execute($"\"{setup.ValidRefCsprojRelPath}\"");
|
||||
.Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\"");
|
||||
cmd.ExitCode.Should().NotBe(0);
|
||||
cmd.StdErr.Should().Contain("more than one");
|
||||
cmd.StdOut.Should().Contain("Usage");
|
||||
|
@ -550,28 +549,80 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
|||
lib.CsProjContent().Should().BeEquivalentTo(contentBefore);
|
||||
}
|
||||
|
||||
[Fact(Skip = "Not finished")]
|
||||
[Fact]
|
||||
public void WhenPassedReferenceDoesNotExistAndForceSwitchIsPassedItAddsIt()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
const string nonExisting = "IDoNotExist.csproj";
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new AddP2PCommand()
|
||||
.WithWorkingDirectory(lib.Path)
|
||||
.WithProject(lib.CsProjName)
|
||||
.Execute($"--force \"{nonExisting}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().Contain("added to the project");
|
||||
cmd.StdErr.Should().BeEmpty();
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(nonExisting).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact(Skip = "Not finished")]
|
||||
[Fact]
|
||||
public void WhenPassedReferenceIsUsingSlashesItNormalizesItToBackslashes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var lib = NewLib();
|
||||
var setup = Setup();
|
||||
|
||||
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new AddP2PCommand()
|
||||
.WithWorkingDirectory(lib.Path)
|
||||
.WithProject(lib.CsProjName)
|
||||
.Execute($"--force \"{setup.ValidRefCsprojPath.Replace('\\', '/')}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().Contain("added to the project");
|
||||
cmd.StdErr.Should().BeEmpty();
|
||||
var csproj = lib.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojPath.Replace('/', '\\')).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact(Skip = "Not finished")]
|
||||
public void WhenPassedRefIsUsingBackslashesItDoesntNormalizeIt()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[Fact(Skip = "Not finished")]
|
||||
[Fact]
|
||||
public void WhenReferenceIsRelativeAndProjectIsNotInCurrentDirectoryReferencePathIsFixed()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var setup = Setup();
|
||||
var proj = new ProjDir(setup.LibDir);
|
||||
|
||||
int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new AddP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(setup.LibCsprojPath)
|
||||
.Execute($"\"{setup.ValidRefCsprojRelPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().Contain("added to the project");
|
||||
cmd.StdErr.Should().BeEmpty();
|
||||
var csproj = proj.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojRelToOtherProjPath).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenReferenceIsRelativeAndProjectIsNotInCurrentDirectoryAndForceSwitchIsPassedItDoesNotChangeIt()
|
||||
{
|
||||
var setup = Setup();
|
||||
var proj = new ProjDir(setup.LibDir);
|
||||
|
||||
int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||
var cmd = new AddP2PCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(setup.LibCsprojPath)
|
||||
.Execute($"--force \"{setup.ValidRefCsprojRelPath}\"");
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().Contain("added to the project");
|
||||
cmd.StdErr.Should().BeEmpty();
|
||||
var csproj = proj.CsProj();
|
||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojRelPath).Should().Be(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,20 +14,18 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
|||
|
||||
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);
|
||||
|
||||
public string ValidRefCsprojRelPath => Path.Combine(ValidRef, ValidRefCsprojName);
|
||||
public string ValidRefCsprojPath => Path.Combine(TestRoot, ValidRefCsprojRelPath);
|
||||
public string ValidRefCsprojRelToOtherProjPath => Path.Combine("..", ValidRefCsprojRelPath);
|
||||
|
||||
private const string Lib = "Lib";
|
||||
public string LibDir => Path.Combine(TestRoot, 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