Fixing broken tests after my changes to the CommandResolvers.

This commit is contained in:
Livar Cunha 2016-08-25 22:53:04 -07:00
parent 55c00a7e45
commit e8f2dabcdb
8 changed files with 48 additions and 11 deletions

View file

@ -23,5 +23,24 @@ namespace Microsoft.Extensions.EnvironmentAbstractions
{ {
return Directory.GetFiles(path, searchPattern); return Directory.GetFiles(path, searchPattern);
} }
public string GetDirectoryFullName(string path)
{
var directoryFullName = string.Empty;
if (Exists(path))
{
directoryFullName = new DirectoryInfo(path).FullName;
}
else
{
var fileInfo = new FileInfo(path);
if (fileInfo.Directory != null)
{
directoryFullName = fileInfo.Directory.FullName;
}
}
return directoryFullName;
}
} }
} }

View file

@ -12,5 +12,7 @@ namespace Microsoft.Extensions.EnvironmentAbstractions
ITemporaryDirectory CreateTemporaryDirectory(); ITemporaryDirectory CreateTemporaryDirectory();
IEnumerable<string> GetFiles(string path, string searchPattern); IEnumerable<string> GetFiles(string path, string searchPattern);
string GetDirectoryFullName(string path);
} }
} }

View file

@ -58,6 +58,7 @@ namespace Microsoft.DotNet.Tools.Test
} }
catch (Exception ex) when (!(ex is GracefulException)) catch (Exception ex) when (!(ex is GracefulException))
{ {
Console.WriteLine(ex.ToString());
TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
return -2; return -2;
} }

View file

@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Test
internal AssemblyTestRunnerResolver(string assemblyUnderTest, IDirectory directory) internal AssemblyTestRunnerResolver(string assemblyUnderTest, IDirectory directory)
{ {
_directoryOfAssemblyUnderTest = new FileInfo(assemblyUnderTest).Directory.FullName; _directoryOfAssemblyUnderTest = directory.GetDirectoryFullName(assemblyUnderTest);
_directory = directory; _directory = directory;
} }

View file

@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var resolvers = defaultCommandResolver.OrderedCommandResolvers; var resolvers = defaultCommandResolver.OrderedCommandResolvers;
resolvers.Should().HaveCount(6); resolvers.Should().HaveCount(7);
resolvers.Select(r => r.GetType()) resolvers.Select(r => r.GetType())
.Should() .Should()
@ -28,7 +28,8 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
typeof(ProjectToolsCommandResolver), typeof(ProjectToolsCommandResolver),
typeof(AppBaseDllCommandResolver), typeof(AppBaseDllCommandResolver),
typeof(AppBaseCommandResolver), typeof(AppBaseCommandResolver),
typeof(PathCommandResolver) typeof(PathCommandResolver),
typeof(PublishedPathCommandResolver)
}); });
} }
} }

View file

@ -123,6 +123,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests
throw new NotImplementedException(); throw new NotImplementedException();
} }
public string GetDirectoryFullName(string path)
{
throw new NotImplementedException();
}
public bool Exists(string path) public bool Exists(string path)
{ {
return _files.Keys.Any(k => k.StartsWith(path)); return _files.Keys.Any(k => k.StartsWith(path));

View file

@ -21,19 +21,21 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
"NetCoreAppOnlyProject", "NetCoreAppOnlyProject",
"project.json"); "project.json");
private TestCommand _testCommand; private readonly TestCommand _testCommand;
private Mock<IDotnetTestRunnerFactory> _dotnetTestRunnerFactoryMock; private readonly Mock<IDotnetTestRunnerFactory> _dotnetTestRunnerFactoryMock;
private Mock<IDotnetTestRunner> _dotnetTestRunnerMock; private readonly Mock<IDotnetTestRunner> _dotnetTestRunnerMock;
public GivenATestCommand() public GivenATestCommand()
{ {
_dotnetTestRunnerMock = new Mock<IDotnetTestRunner>(); _dotnetTestRunnerMock = new Mock<IDotnetTestRunner>();
_dotnetTestRunnerMock _dotnetTestRunnerMock
.Setup(d => d.RunTests(It.IsAny<ProjectContext>(), It.IsAny<DotnetTestParams>(), It.IsAny<BuildWorkspace>())) .Setup(d => d.RunTests(It.IsAny<DotnetTestParams>()))
.Returns(0); .Returns(0);
_dotnetTestRunnerFactoryMock = new Mock<IDotnetTestRunnerFactory>(); _dotnetTestRunnerFactoryMock = new Mock<IDotnetTestRunnerFactory>();
_dotnetTestRunnerFactoryMock.Setup(d => d.Create(null)).Returns(_dotnetTestRunnerMock.Object); _dotnetTestRunnerFactoryMock
.Setup(d => d.Create(It.IsAny<DotnetTestParams>()))
.Returns(_dotnetTestRunnerMock.Object);
_testCommand = new TestCommand(_dotnetTestRunnerFactoryMock.Object); _testCommand = new TestCommand(_dotnetTestRunnerFactoryMock.Object);
} }
@ -44,7 +46,8 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
var result = _testCommand.DoRun(new[] {"--help"}); var result = _testCommand.DoRun(new[] {"--help"});
result.Should().Be(0); result.Should().Be(0);
_dotnetTestRunnerFactoryMock.Verify(d => d.Create(It.IsAny<int?>()), Times.Never); _dotnetTestRunnerFactoryMock
.Verify(d => d.Create(It.IsAny<DotnetTestParams>()), Times.Never);
} }
[Fact] [Fact]
@ -53,7 +56,8 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
var result = _testCommand.DoRun(new[] { ProjectJsonPath, "-f", "netcoreapp1.0" }); var result = _testCommand.DoRun(new[] { ProjectJsonPath, "-f", "netcoreapp1.0" });
result.Should().Be(0); result.Should().Be(0);
_dotnetTestRunnerFactoryMock.Verify(d => d.Create(It.IsAny<int?>()), Times.Once); _dotnetTestRunnerFactoryMock
.Verify(d => d.Create(It.IsAny<DotnetTestParams>()), Times.Once);
} }
[Fact] [Fact]
@ -62,7 +66,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
var result = _testCommand.DoRun(new[] { ProjectJsonPath, "-f", "netcoreapp1.0" }); var result = _testCommand.DoRun(new[] { ProjectJsonPath, "-f", "netcoreapp1.0" });
_dotnetTestRunnerMock.Verify( _dotnetTestRunnerMock.Verify(
d => d.RunTests(It.IsAny<ProjectContext>(), It.IsAny<DotnetTestParams>(), It.IsAny<BuildWorkspace>()), d => d.RunTests(It.IsAny<DotnetTestParams>()),
Times.Once); Times.Once);
} }
} }

View file

@ -84,6 +84,11 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
return _files.Where(f => f.StartsWith(path) && searchPatternRegex.IsMatch(f)); return _files.Where(f => f.StartsWith(path) && searchPatternRegex.IsMatch(f));
} }
public string GetDirectoryFullName(string path)
{
return Path.GetDirectoryName(path);
}
public void AddFile(string path, string fileName) public void AddFile(string path, string fileName)
{ {
_files.Add($"{path}/{fileName}"); _files.Add($"{path}/{fileName}");