diff --git a/src/dotnet/ICommandRunner.cs b/src/dotnet/ICommandRunner.cs new file mode 100644 index 000000000..376d13fba --- /dev/null +++ b/src/dotnet/ICommandRunner.cs @@ -0,0 +1,13 @@ +// 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; + +namespace Microsoft.DotNet.Cli +{ + public interface ICommandRunner + { + int Run(string[] commandArgs); + } +} diff --git a/src/dotnet/commands/dotnet-nuget/Program.cs b/src/dotnet/commands/dotnet-nuget/Program.cs index 0eb3d8c14..6bac61b7a 100644 --- a/src/dotnet/commands/dotnet-nuget/Program.cs +++ b/src/dotnet/commands/dotnet-nuget/Program.cs @@ -3,6 +3,7 @@ using System; using System.Linq; +using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.InternalAbstractions; @@ -10,15 +11,33 @@ using Microsoft.DotNet.Tools; namespace Microsoft.DotNet.Tools.Restore { - public partial class NuGetCommand + public class NuGetCommand { public static int Run(string[] args) + { + return Run(args, new NuGetCommandRunner()); + } + + public static int Run(string[] args, ICommandRunner nugetCommandRunner) { DebugHelper.HandleDebugSwitch(ref args); - var nugetApp = new NuGetForwardingApp(args); + if (nugetCommandRunner == null) + { + throw new ArgumentNullException(nameof(nugetCommandRunner)); + } - return nugetApp.Execute(); + return nugetCommandRunner.Run(args); + } + + private class NuGetCommandRunner : ICommandRunner + { + public int Run(string [] args) + { + var nugetApp = new NuGetForwardingApp(args); + + return nugetApp.Execute(); + } } } } diff --git a/test/dotnet-new.Tests/GivenThatIWantANewCSxUnitProject.cs b/test/dotnet-new.Tests/GivenThatIWantANewCSxUnitProject.cs index d4081640d..566e00e38 100644 --- a/test/dotnet-new.Tests/GivenThatIWantANewCSxUnitProject.cs +++ b/test/dotnet-new.Tests/GivenThatIWantANewCSxUnitProject.cs @@ -4,6 +4,7 @@ using Microsoft.DotNet.Tools.Test.Utilities; using Xunit; using FluentAssertions; +using System.IO; namespace Microsoft.DotNet.Tests { @@ -18,8 +19,7 @@ namespace Microsoft.DotNet.Tests new TestCommand("dotnet") { WorkingDirectory = rootPath } .Execute("new --type xunittest") - .Should() - .Pass(); + .Should().Pass(); new TestCommand("dotnet") { WorkingDirectory = rootPath } .Execute("restore") diff --git a/test/dotnet-nuget.UnitTests/GivenANuGetCommand.cs b/test/dotnet-nuget.UnitTests/GivenANuGetCommand.cs index 9d63e20d6..38f629e3f 100644 --- a/test/dotnet-nuget.UnitTests/GivenANuGetCommand.cs +++ b/test/dotnet-nuget.UnitTests/GivenANuGetCommand.cs @@ -42,14 +42,14 @@ namespace Microsoft.DotNet.Tools.Run.Tests { // Arrange string[] receivedArgs = null; - var testCommandRunner = new Mock(); + var testCommandRunner = new Mock(); testCommandRunner .Setup(x => x.Run(It.IsAny())) .Callback(s => receivedArgs = s) .Returns(0); // Act - var returned = NuGetCommand.RunCommand(inputArgs, testCommandRunner.Object); + var returned = NuGetCommand.Run(inputArgs, testCommandRunner.Object); // Assert receivedArgs.Should().BeEquivalentTo(inputArgs);