Address PR feedback

Add new tests to invokde executable dependency via a tool command.
This commit is contained in:
Sridhar Periyasamy 2016-04-25 10:56:05 -07:00
parent c1fbf18059
commit beb27a28fc
8 changed files with 142 additions and 74 deletions

View file

@ -4,7 +4,6 @@
<!--To inherit the global NuGet package sources remove the <clear/> line below --> <!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear /> <clear />
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" /> <add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
<add key="coreclr-xunit" value="https://www.myget.org/F/coreclr-xunit/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" /> <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources> </packageSources>
</configuration> </configuration>

View file

@ -14,5 +14,14 @@
}, },
"frameworks": { "frameworks": {
"net451": {} "net451": {}
},
"tools": {
"dotnet-dependency-tool-invoker": {
"version": "1.0.0-*",
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
} }
} }

View file

@ -14,5 +14,14 @@
}, },
"frameworks": { "frameworks": {
"net451": {} "net451": {}
},
"tools": {
"dotnet-dependency-tool-invoker": {
"version": "1.0.0-*",
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
} }
} }

View file

@ -0,0 +1,30 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.DotNet.Cli.Utils;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class DependencyToolInvokerCommand : TestCommand
{
public DependencyToolInvokerCommand()
: base("dotnet")
{
}
public CommandResult Execute(string commandName, string framework, string additionalArgs)
{
var args = $"dependency-tool-invoker {commandName} --framework {framework} {additionalArgs}";
return base.Execute(args);
}
public CommandResult ExecuteWithCapturedOutput(string commandName, string framework, string additionalArgs)
{
var args = $"dependency-tool-invoker {commandName} --framework {framework} {additionalArgs}";
return base.ExecuteWithCapturedOutput(args);
}
}
}

View file

@ -17,62 +17,13 @@ using FluentAssertions;
namespace Microsoft.DotNet.Tests namespace Microsoft.DotNet.Tests
{ {
public class TestSetupFixture : TestBase
{
private const string Framework = "net451";
private const string Config = "Debug";
private const string AppWithConfig = "AppWithRedirectsAndConfig";
private const string AppWithoutConfig = "AppWithRedirectsNoConfig";
private string _Runtime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
private string _desktopProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects");
private string _buildRelativePath;
private string _appWithConfigBuildDir;
private string _appWithConfigPublishDir;
private string _appWithoutConfigBuildDir;
private string _appWithoutConfigPublishDir;
private TestInstance _testInstance;
public string AppWithConfigBuildOutput { get; }
public string AppWithConfigPublishOutput { get; }
public string AppWithoutConfigBuildOutput { get; }
public string AppWithoutConfigPublishOutput { get; }
public TestSetupFixture()
{
_buildRelativePath = Path.Combine("bin", Config, Framework, _Runtime);
var testAssetsMgr = new TestAssetsManager(_desktopProjectsRoot);
_testInstance = testAssetsMgr.CreateTestInstance("BindingRedirectSample")
.WithLockFiles();
Setup(AppWithConfig, ref _appWithConfigBuildDir, ref _appWithConfigPublishDir);
Setup(AppWithoutConfig, ref _appWithoutConfigBuildDir, ref _appWithoutConfigPublishDir);
AppWithConfigBuildOutput = Path.Combine(_appWithConfigBuildDir, AppWithConfig + ".exe");
AppWithConfigPublishOutput = Path.Combine(_appWithConfigPublishDir, AppWithConfig + ".exe");
AppWithoutConfigBuildOutput = Path.Combine(_appWithoutConfigBuildDir, AppWithoutConfig + ".exe");
AppWithoutConfigPublishOutput = Path.Combine(_appWithoutConfigPublishDir, AppWithoutConfig + ".exe");
}
private void Setup(string project, ref string buildDir, ref string publishDir)
{
string projectRoot = Path.Combine(_testInstance.TestRoot, project);
buildDir = Path.Combine(projectRoot, _buildRelativePath);
publishDir = Path.Combine(projectRoot, "publish");
var buildCommand = new BuildCommand(projectRoot, framework: Framework, runtime: _Runtime);
buildCommand.Execute().Should().Pass();
var publishCommand = new PublishCommand(projectRoot, output: publishDir, framework: Framework, runtime: _Runtime);
publishCommand.Execute().Should().Pass();
}
}
public class GivenAnAppWithRedirectsAndExecutableDependency : TestBase, IClassFixture<TestSetupFixture> public class GivenAnAppWithRedirectsAndExecutableDependency : TestBase, IClassFixture<TestSetupFixture>
{ {
private const string ExecutableDependency = "dotnet-desktop-binding-redirects.exe"; private const string ExecutableDependency = "dotnet-desktop-binding-redirects.exe";
private const string ExecutableDependencyCommand = "desktop-binding-redirects";
private TestSetupFixture _testSetup; private TestSetupFixture _testSetup;
public string _appWithConfigProjectRoot;
public string _appWithoutConfigProjectRoot;
private string _appWithConfigBuildOutput; private string _appWithConfigBuildOutput;
private string _appWithoutConfigBuildOutput; private string _appWithoutConfigBuildOutput;
private string _appWithConfigPublishOutput; private string _appWithConfigPublishOutput;
@ -83,8 +34,10 @@ namespace Microsoft.DotNet.Tests
public GivenAnAppWithRedirectsAndExecutableDependency(TestSetupFixture testSetup) public GivenAnAppWithRedirectsAndExecutableDependency(TestSetupFixture testSetup)
{ {
_testSetup = testSetup; _testSetup = testSetup;
_appWithConfigProjectRoot = _testSetup.AppWithConfigProjectRoot;
_appWithConfigBuildOutput = _testSetup.AppWithConfigBuildOutput; _appWithConfigBuildOutput = _testSetup.AppWithConfigBuildOutput;
_appWithConfigPublishOutput = _testSetup.AppWithConfigPublishOutput; _appWithConfigPublishOutput = _testSetup.AppWithConfigPublishOutput;
_appWithoutConfigProjectRoot = _testSetup.AppWithoutConfigProjectRoot;
_appWithoutConfigBuildOutput = _testSetup.AppWithoutConfigBuildOutput; _appWithoutConfigBuildOutput = _testSetup.AppWithoutConfigBuildOutput;
_appWithoutConfigPublishOutput = _testSetup.AppWithoutConfigPublishOutput; _appWithoutConfigPublishOutput = _testSetup.AppWithoutConfigPublishOutput;
_executableDependencyBuildOutput = Path.Combine(Path.GetDirectoryName(_appWithConfigBuildOutput), ExecutableDependency); _executableDependencyBuildOutput = Path.Combine(Path.GetDirectoryName(_appWithConfigBuildOutput), ExecutableDependency);
@ -283,5 +236,22 @@ namespace Microsoft.DotNet.Tests
.Execute(); .Execute();
commandResult.Should().Pass(); commandResult.Should().Pass();
} }
[Fact]
public void Tool_Command_Runs_Executable_Dependency_For_App_With_Config()
{
var commandResult = new DependencyToolInvokerCommand { WorkingDirectory = _appWithConfigProjectRoot }
.Execute("desktop-binding-redirects", "net451", "");
commandResult.Should().Pass();
}
[Fact]
public void Tool_Command_Runs_Executable_Dependency_For_App_Without_Config()
{
var appDirectory = Path.GetDirectoryName(_appWithoutConfigProjectRoot);
var commandResult = new DependencyToolInvokerCommand { WorkingDirectory = _appWithoutConfigProjectRoot }
.Execute("desktop-binding-redirects", "net451", "");
commandResult.Should().Pass();
}
} }
} }

View file

@ -0,0 +1,71 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.TestFramework;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
namespace Microsoft.DotNet.Tests
{
public class TestSetupFixture : TestBase
{
private const string Framework = "net451";
private const string Config = "Debug";
private const string AppWithConfig = "AppWithRedirectsAndConfig";
private const string AppWithoutConfig = "AppWithRedirectsNoConfig";
private string _Runtime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
private string _desktopProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects");
private string _buildRelativePath;
private string _appWithConfigProjectRoot;
private string _appWithConfigBuildDir;
private string _appWithConfigPublishDir;
private string _appWithoutConfigProjectRoot;
private string _appWithoutConfigBuildDir;
private string _appWithoutConfigPublishDir;
private TestInstance _testInstance;
public string AppWithConfigProjectRoot { get { return _appWithConfigProjectRoot; } }
public string AppWithConfigBuildOutput { get; }
public string AppWithConfigPublishOutput { get; }
public string AppWithoutConfigProjectRoot { get { return _appWithoutConfigProjectRoot; } }
public string AppWithoutConfigBuildOutput { get; }
public string AppWithoutConfigPublishOutput { get; }
public TestSetupFixture()
{
_buildRelativePath = Path.Combine("bin", Config, Framework, _Runtime);
var testAssetsMgr = new TestAssetsManager(_desktopProjectsRoot);
_testInstance = testAssetsMgr.CreateTestInstance("BindingRedirectSample")
.WithLockFiles();
Setup(AppWithConfig, ref _appWithConfigProjectRoot, ref _appWithConfigBuildDir, ref _appWithConfigPublishDir);
Setup(AppWithoutConfig, ref _appWithoutConfigProjectRoot, ref _appWithoutConfigBuildDir, ref _appWithoutConfigPublishDir);
AppWithConfigBuildOutput = Path.Combine(_appWithConfigBuildDir, AppWithConfig + ".exe");
AppWithConfigPublishOutput = Path.Combine(_appWithConfigPublishDir, AppWithConfig + ".exe");
AppWithoutConfigBuildOutput = Path.Combine(_appWithoutConfigBuildDir, AppWithoutConfig + ".exe");
AppWithoutConfigPublishOutput = Path.Combine(_appWithoutConfigPublishDir, AppWithoutConfig + ".exe");
}
private void Setup(string project, ref string projectDir, ref string buildDir, ref string publishDir)
{
projectDir = Path.Combine(_testInstance.TestRoot, project);
buildDir = Path.Combine(projectDir, _buildRelativePath);
publishDir = Path.Combine(projectDir, "publish");
var buildCommand = new BuildCommand(projectDir, framework: Framework, runtime: _Runtime);
buildCommand.Execute().Should().Pass();
var publishCommand = new PublishCommand(projectDir, output: publishDir, framework: Framework, runtime: _Runtime);
publishCommand.Execute().Should().Pass();
}
}
}

View file

@ -2,7 +2,7 @@
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"xunit": "2.1.0", "xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-157751-46", "dotnet-test-xunit": "1.0.0-rc2-162081-13",
"Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.NETCore.Platforms": "1.0.1-*",
"Microsoft.DotNet.Tools.Tests.Utilities": { "Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project" "target": "project"

View file

@ -242,25 +242,5 @@ namespace Microsoft.DotNet.Tests
return base.ExecuteWithCapturedOutput(args); return base.ExecuteWithCapturedOutput(args);
} }
} }
class DependencyToolInvokerCommand : TestCommand
{
public DependencyToolInvokerCommand()
: base("dotnet")
{
}
public CommandResult Execute(string commandName, string framework, string additionalArgs)
{
var args = $"dependency-tool-invoker {commandName} --framework {framework} {additionalArgs}";
return base.Execute(args);
}
public CommandResult ExecuteWithCapturedOutput(string commandName, string framework, string additionalArgs)
{
var args = $"dependency-tool-invoker {commandName} --framework {framework} {additionalArgs}";
return base.ExecuteWithCapturedOutput(args);
}
}
} }
} }