dotnet-installer/src/Microsoft.DotNet.Tools.Test/ConsoleTestRunner.cs

56 lines
1.7 KiB
C#
Raw Normal View History

// 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.Collections.Generic;
using Microsoft.DotNet.Cli.Utils;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Test
{
public class ConsoleTestRunner : IDotnetTestRunner
{
2016-08-29 16:46:12 +00:00
private readonly ITestRunnerNameResolver _testRunnerNameResolver;
private readonly ICommandFactory _commandFactory;
private readonly string _assemblyUnderTest;
private readonly NuGetFramework _framework;
public ConsoleTestRunner(
2016-08-29 16:46:12 +00:00
ITestRunnerNameResolver testRunnerNameResolver,
ICommandFactory commandFactory,
string assemblyUnderTest,
NuGetFramework framework = null)
{
2016-08-29 16:46:12 +00:00
_testRunnerNameResolver = testRunnerNameResolver;
_commandFactory = commandFactory;
_assemblyUnderTest = assemblyUnderTest;
_framework = framework;
}
public int RunTests(DotnetTestParams dotnetTestParams)
{
return _commandFactory.Create(
2016-08-29 16:46:12 +00:00
_testRunnerNameResolver.ResolveTestRunner(),
GetCommandArgs(dotnetTestParams),
_framework,
dotnetTestParams.Config)
.Execute()
.ExitCode;
}
private IEnumerable<string> GetCommandArgs(DotnetTestParams dotnetTestParams)
{
var commandArgs = new List<string>
{
_assemblyUnderTest
};
commandArgs.AddRange(dotnetTestParams.RemainingArguments);
return commandArgs;
}
}
}