Merge pull request #2078 from livarcocc/dotnet_test_help
Added a Help property to DotnetTestParams that indicates when the par…
This commit is contained in:
commit
1ff15e35bc
7 changed files with 143 additions and 7 deletions
68
test/dotnet-test.UnitTests/GivenATestCommand.cs
Normal file
68
test/dotnet-test.UnitTests/GivenATestCommand.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
// 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.IO;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestCommand
|
||||
{
|
||||
private static readonly string ProjectJsonPath = Path.Combine(
|
||||
AppContext.BaseDirectory,
|
||||
"TestAssets",
|
||||
"TestProjects",
|
||||
"ProjectWithTests",
|
||||
"project.json");
|
||||
|
||||
private TestCommand _testCommand;
|
||||
private Mock<IDotnetTestRunnerFactory> _dotnetTestRunnerFactoryMock;
|
||||
private Mock<IDotnetTestRunner> _dotnetTestRunnerMock;
|
||||
|
||||
public GivenATestCommand()
|
||||
{
|
||||
_dotnetTestRunnerMock = new Mock<IDotnetTestRunner>();
|
||||
_dotnetTestRunnerMock
|
||||
.Setup(d => d.RunTests(It.IsAny<ProjectContext>(), It.IsAny<DotnetTestParams>()))
|
||||
.Returns(0);
|
||||
|
||||
_dotnetTestRunnerFactoryMock = new Mock<IDotnetTestRunnerFactory>();
|
||||
_dotnetTestRunnerFactoryMock.Setup(d => d.Create(null)).Returns(_dotnetTestRunnerMock.Object);
|
||||
|
||||
_testCommand = new TestCommand(_dotnetTestRunnerFactoryMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_create_a_runner_if_the_args_include_help()
|
||||
{
|
||||
var result = _testCommand.DoRun(new[] {"--help"});
|
||||
|
||||
result.Should().Be(0);
|
||||
_dotnetTestRunnerFactoryMock.Verify(d => d.Create(It.IsAny<int?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_creates_a_runner_if_the_args_do_no_include_help()
|
||||
{
|
||||
var result = _testCommand.DoRun(new[] { ProjectJsonPath });
|
||||
|
||||
result.Should().Be(0);
|
||||
_dotnetTestRunnerFactoryMock.Verify(d => d.Create(It.IsAny<int?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_the_tests_through_the_DotnetTestRunner()
|
||||
{
|
||||
var result = _testCommand.DoRun(new[] { ProjectJsonPath });
|
||||
|
||||
_dotnetTestRunnerMock.Verify(
|
||||
d => d.RunTests(It.IsAny<ProjectContext>(), It.IsAny<DotnetTestParams>()),
|
||||
Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -192,5 +192,20 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
{
|
||||
_emptyDotnetTestParams.NoBuild.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sets_Help_to_false_when_help_is_not_passed_in()
|
||||
{
|
||||
_dotnetTestFullParams.Help.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sets_Help_to_true_when_help_is_passed_in()
|
||||
{
|
||||
var dotnetTestParams = new DotnetTestParams();
|
||||
dotnetTestParams.Parse(new[] { "--help" });
|
||||
|
||||
dotnetTestParams.Help.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,5 +23,8 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/ProjectWithTests/project.json"
|
||||
],
|
||||
"testRunner": "xunit"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue