From beb27a28fc781e46f88480dc0ed614048021c091 Mon Sep 17 00:00:00 2001 From: Sridhar Periyasamy Date: Mon, 25 Apr 2016 10:56:05 -0700 Subject: [PATCH] Address PR feedback Add new tests to invokde executable dependency via a tool command. --- NuGet.Config | 1 - .../AppWithRedirectsAndConfig/project.json | 9 +++ .../AppWithRedirectsNoConfig/project.json | 9 +++ .../Commands/DependencyToolInvokerCommand.cs | 30 ++++++++ .../BindingRedirectTests.cs | 74 ++++++------------- .../TestSetupFixture.cs | 71 ++++++++++++++++++ test/binding-redirects.Tests/project.json | 2 +- test/dotnet.Tests/PackagedCommandTests.cs | 20 ----- 8 files changed, 142 insertions(+), 74 deletions(-) create mode 100644 test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs create mode 100644 test/binding-redirects.Tests/TestSetupFixture.cs diff --git a/NuGet.Config b/NuGet.Config index 18d3d4945..fd5ce235a 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -4,7 +4,6 @@ - diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json index a4ec663cf..22dbbc77a 100644 --- a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json +++ b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json @@ -14,5 +14,14 @@ }, "frameworks": { "net451": {} + }, + "tools": { + "dotnet-dependency-tool-invoker": { + "version": "1.0.0-*", + "imports": [ + "dnxcore50", + "portable-net45+win8" + ] + } } } diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json index a4ec663cf..22dbbc77a 100644 --- a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json +++ b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json @@ -14,5 +14,14 @@ }, "frameworks": { "net451": {} + }, + "tools": { + "dotnet-dependency-tool-invoker": { + "version": "1.0.0-*", + "imports": [ + "dnxcore50", + "portable-net45+win8" + ] + } } } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs new file mode 100644 index 000000000..b11281f95 --- /dev/null +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs @@ -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); + } + } +} diff --git a/test/binding-redirects.Tests/BindingRedirectTests.cs b/test/binding-redirects.Tests/BindingRedirectTests.cs index ae630bd3f..57cdf99f7 100644 --- a/test/binding-redirects.Tests/BindingRedirectTests.cs +++ b/test/binding-redirects.Tests/BindingRedirectTests.cs @@ -17,62 +17,13 @@ using FluentAssertions; 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 { private const string ExecutableDependency = "dotnet-desktop-binding-redirects.exe"; + private const string ExecutableDependencyCommand = "desktop-binding-redirects"; private TestSetupFixture _testSetup; + public string _appWithConfigProjectRoot; + public string _appWithoutConfigProjectRoot; private string _appWithConfigBuildOutput; private string _appWithoutConfigBuildOutput; private string _appWithConfigPublishOutput; @@ -83,8 +34,10 @@ namespace Microsoft.DotNet.Tests public GivenAnAppWithRedirectsAndExecutableDependency(TestSetupFixture testSetup) { _testSetup = testSetup; + _appWithConfigProjectRoot = _testSetup.AppWithConfigProjectRoot; _appWithConfigBuildOutput = _testSetup.AppWithConfigBuildOutput; _appWithConfigPublishOutput = _testSetup.AppWithConfigPublishOutput; + _appWithoutConfigProjectRoot = _testSetup.AppWithoutConfigProjectRoot; _appWithoutConfigBuildOutput = _testSetup.AppWithoutConfigBuildOutput; _appWithoutConfigPublishOutput = _testSetup.AppWithoutConfigPublishOutput; _executableDependencyBuildOutput = Path.Combine(Path.GetDirectoryName(_appWithConfigBuildOutput), ExecutableDependency); @@ -283,5 +236,22 @@ namespace Microsoft.DotNet.Tests .Execute(); 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(); + } } } diff --git a/test/binding-redirects.Tests/TestSetupFixture.cs b/test/binding-redirects.Tests/TestSetupFixture.cs new file mode 100644 index 000000000..7394a1530 --- /dev/null +++ b/test/binding-redirects.Tests/TestSetupFixture.cs @@ -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(); + } + } +} diff --git a/test/binding-redirects.Tests/project.json b/test/binding-redirects.Tests/project.json index 205b297b5..b92e10aef 100644 --- a/test/binding-redirects.Tests/project.json +++ b/test/binding-redirects.Tests/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "dependencies": { "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.DotNet.Tools.Tests.Utilities": { "target": "project" diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index 45a95a388..5c2869b58 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -242,25 +242,5 @@ namespace Microsoft.DotNet.Tests 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); - } - } } }