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