diff --git a/src/Microsoft.DotNet.InternalAbstractions/DirectoryWrapper.cs b/src/Microsoft.DotNet.InternalAbstractions/DirectoryWrapper.cs index 6db8156db..591462989 100644 --- a/src/Microsoft.DotNet.InternalAbstractions/DirectoryWrapper.cs +++ b/src/Microsoft.DotNet.InternalAbstractions/DirectoryWrapper.cs @@ -23,5 +23,24 @@ namespace Microsoft.Extensions.EnvironmentAbstractions { 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; + } } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.InternalAbstractions/IDirectory.cs b/src/Microsoft.DotNet.InternalAbstractions/IDirectory.cs index 162a9dd42..95464df21 100644 --- a/src/Microsoft.DotNet.InternalAbstractions/IDirectory.cs +++ b/src/Microsoft.DotNet.InternalAbstractions/IDirectory.cs @@ -12,5 +12,7 @@ namespace Microsoft.Extensions.EnvironmentAbstractions ITemporaryDirectory CreateTemporaryDirectory(); IEnumerable GetFiles(string path, string searchPattern); + + string GetDirectoryFullName(string path); } } \ No newline at end of file diff --git a/src/dotnet-test-console/TestCommand.cs b/src/dotnet-test-console/TestCommand.cs index eda766f1e..8d40829a0 100644 --- a/src/dotnet-test-console/TestCommand.cs +++ b/src/dotnet-test-console/TestCommand.cs @@ -58,6 +58,7 @@ namespace Microsoft.DotNet.Tools.Test } catch (Exception ex) when (!(ex is GracefulException)) { + Console.WriteLine(ex.ToString()); TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return -2; } diff --git a/src/dotnet-test-console/TestRunners/AssemblyTestRunnerResolver.cs b/src/dotnet-test-console/TestRunners/AssemblyTestRunnerResolver.cs index 99a741de3..853914158 100644 --- a/src/dotnet-test-console/TestRunners/AssemblyTestRunnerResolver.cs +++ b/src/dotnet-test-console/TestRunners/AssemblyTestRunnerResolver.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Test internal AssemblyTestRunnerResolver(string assemblyUnderTest, IDirectory directory) { - _directoryOfAssemblyUnderTest = new FileInfo(assemblyUnderTest).Directory.FullName; + _directoryOfAssemblyUnderTest = directory.GetDirectoryFullName(assemblyUnderTest); _directory = directory; } diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs index 3a92bad95..b2e354e30 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var resolvers = defaultCommandResolver.OrderedCommandResolvers; - resolvers.Should().HaveCount(6); + resolvers.Should().HaveCount(7); resolvers.Select(r => r.GetType()) .Should() @@ -28,7 +28,8 @@ namespace Microsoft.DotNet.Cli.Utils.Tests typeof(ProjectToolsCommandResolver), typeof(AppBaseDllCommandResolver), typeof(AppBaseCommandResolver), - typeof(PathCommandResolver) + typeof(PathCommandResolver), + typeof(PublishedPathCommandResolver) }); } } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Mock/FileSystemMockBuilder.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Mock/FileSystemMockBuilder.cs index 4fc2a158a..9176cc2d8 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Mock/FileSystemMockBuilder.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Mock/FileSystemMockBuilder.cs @@ -123,6 +123,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests throw new NotImplementedException(); } + public string GetDirectoryFullName(string path) + { + throw new NotImplementedException(); + } + public bool Exists(string path) { return _files.Keys.Any(k => k.StartsWith(path)); diff --git a/test/dotnet-test.UnitTests/GivenATestCommand.cs b/test/dotnet-test.UnitTests/GivenATestCommand.cs index 3a1c7598a..5a0df6743 100644 --- a/test/dotnet-test.UnitTests/GivenATestCommand.cs +++ b/test/dotnet-test.UnitTests/GivenATestCommand.cs @@ -21,19 +21,21 @@ namespace Microsoft.Dotnet.Tools.Test.Tests "NetCoreAppOnlyProject", "project.json"); - private TestCommand _testCommand; - private Mock _dotnetTestRunnerFactoryMock; - private Mock _dotnetTestRunnerMock; + private readonly TestCommand _testCommand; + private readonly Mock _dotnetTestRunnerFactoryMock; + private readonly Mock _dotnetTestRunnerMock; public GivenATestCommand() { _dotnetTestRunnerMock = new Mock(); _dotnetTestRunnerMock - .Setup(d => d.RunTests(It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(d => d.RunTests(It.IsAny())) .Returns(0); _dotnetTestRunnerFactoryMock = new Mock(); - _dotnetTestRunnerFactoryMock.Setup(d => d.Create(null)).Returns(_dotnetTestRunnerMock.Object); + _dotnetTestRunnerFactoryMock + .Setup(d => d.Create(It.IsAny())) + .Returns(_dotnetTestRunnerMock.Object); _testCommand = new TestCommand(_dotnetTestRunnerFactoryMock.Object); } @@ -44,7 +46,8 @@ namespace Microsoft.Dotnet.Tools.Test.Tests var result = _testCommand.DoRun(new[] {"--help"}); result.Should().Be(0); - _dotnetTestRunnerFactoryMock.Verify(d => d.Create(It.IsAny()), Times.Never); + _dotnetTestRunnerFactoryMock + .Verify(d => d.Create(It.IsAny()), Times.Never); } [Fact] @@ -53,7 +56,8 @@ namespace Microsoft.Dotnet.Tools.Test.Tests var result = _testCommand.DoRun(new[] { ProjectJsonPath, "-f", "netcoreapp1.0" }); result.Should().Be(0); - _dotnetTestRunnerFactoryMock.Verify(d => d.Create(It.IsAny()), Times.Once); + _dotnetTestRunnerFactoryMock + .Verify(d => d.Create(It.IsAny()), Times.Once); } [Fact] @@ -62,7 +66,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests var result = _testCommand.DoRun(new[] { ProjectJsonPath, "-f", "netcoreapp1.0" }); _dotnetTestRunnerMock.Verify( - d => d.RunTests(It.IsAny(), It.IsAny(), It.IsAny()), + d => d.RunTests(It.IsAny()), Times.Once); } } diff --git a/test/dotnet-test.UnitTests/GivenAnAssemblyTestRunnerResolver.cs b/test/dotnet-test.UnitTests/GivenAnAssemblyTestRunnerResolver.cs index 9fdbe5e55..d56b6f2d4 100644 --- a/test/dotnet-test.UnitTests/GivenAnAssemblyTestRunnerResolver.cs +++ b/test/dotnet-test.UnitTests/GivenAnAssemblyTestRunnerResolver.cs @@ -84,6 +84,11 @@ namespace Microsoft.Dotnet.Tools.Test.Tests 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) { _files.Add($"{path}/{fileName}");