Skip to content

Commit

Permalink
Working directory fix (#346)
Browse files Browse the repository at this point in the history
* Fixed the working directory for the dotnet.exe to source directory.

* Adding the acceptance test for the working directory fix.
  • Loading branch information
singhsarab authored and Arun Mahapatra committed Jan 20, 2017
1 parent efecbb3 commit b554ca7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
// G:\tmp\netcore-test\bin\Debug\netcoreapp1.0\netcore-test.dll
startInfo.Arguments = args;
startInfo.EnvironmentVariables = environmentVariables ?? new Dictionary<string, string>();
startInfo.WorkingDirectory = Directory.GetCurrentDirectory();
startInfo.WorkingDirectory = sourceDirectory;

return startInfo;
}
Expand Down
15 changes: 15 additions & 0 deletions test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,20 @@ public void RunMultipleTestAssembliesInParallel(string runnerFramework, string t
$"Number of {testhostProcessName} process created, expected: {expectedNumOfProcessCreated} actual: {numOfProcessCreatedTask.Result}");
this.ValidateSummaryStatus(2, 2, 2);
}

[CustomDataTestMethod]
[NET46TargetFramework]
[NETCORETargetFramework]
public void WorkingDirectoryIsSourceDirectory(string runnerFramework, string targetFramework, string targetRuntime)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime);

var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject3.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue);
arguments = string.Concat(arguments, " /tests:WorkingDirectoryTest");
this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ public void GetTestHostProcessStartInfoShouldThrowExceptionWhenDotnetIsNotInstal
}

[TestMethod]
public void GetTestHostProcessStartInfoShouldIncludeCurrentDirectoryAsWorkingDirectory()
public void GetTestHostProcessStartInfoShouldIncludeSourceDirectoryAsWorkingDirectory()
{
// Absolute path to the source directory
var sourcePath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "test.dll");
this.mockFileHelper.Setup(ph => ph.Exists(@"\tmp\testhost.dll")).Returns(true);
var startInfo = this.dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, this.defaultConnectionInfo);

Assert.AreEqual(Directory.GetCurrentDirectory(), startInfo.WorkingDirectory);
Assert.AreEqual($"{Path.DirectorySeparatorChar}tmp", startInfo.WorkingDirectory);
}

[TestMethod]
Expand Down
10 changes: 1 addition & 9 deletions test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;net46;netcoreapp1.1</TargetFrameworks>
<AssemblyName>SimpleTestProject3</AssemblyName>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' Or '$(TargetFramework)' == 'netcoreapp1.1' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
<OutputType Condition=" '$(TargetFramework)' == 'netcoreapp1.0' Or '$(TargetFramework)' == 'netcoreapp1.1' ">Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.resx" />
Expand Down Expand Up @@ -41,13 +39,7 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' Or '$(TargetFramework)' == 'netcoreapp1.1' ">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net46'">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
</Project>
</Project>
23 changes: 4 additions & 19 deletions test/TestAssets/SimpleTestProject3/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,16 @@
namespace SampleUnitTestProject3
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Reflection;

[TestClass]
public class UnitTest1
{
[TestMethod]
public void PassingTest()
{
Assert.AreEqual(2, 2);
}

[TestMethod]
public async Task AsyncTestMethod()
{
await Task.CompletedTask;
}
}

public class Class1
{
public void OverLoadededMethod()
{
}

public void OverLoadededMethod(string name)
public void WorkingDirectoryTest()
{
Assert.AreEqual(Path.GetDirectoryName(typeof(UnitTest1).GetTypeInfo().Assembly.Location), Directory.GetCurrentDirectory());
}
}
}

0 comments on commit b554ca7

Please sign in to comment.