2016-03-15 00:38:36 +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;
|
|
|
|
|
using System.IO;
|
2016-04-28 23:30:32 +00:00
|
|
|
|
using Microsoft.DotNet.InternalAbstractions;
|
2016-03-15 00:38:36 +00:00
|
|
|
|
using Microsoft.DotNet.ProjectModel;
|
2016-04-08 03:08:17 +00:00
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2016-03-15 00:38:36 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2016-04-28 23:30:32 +00:00
|
|
|
|
using Xunit;
|
2016-03-15 00:38:36 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.Dotnet.Tools.Test.Tests
|
|
|
|
|
{
|
|
|
|
|
public class GivenThatWeWantToRunTestsInTheConsole : TestBase
|
|
|
|
|
{
|
|
|
|
|
private string _projectFilePath;
|
|
|
|
|
private string _defaultOutputPath;
|
|
|
|
|
|
|
|
|
|
public GivenThatWeWantToRunTestsInTheConsole()
|
|
|
|
|
{
|
|
|
|
|
var testInstance =
|
2016-04-14 22:59:11 +00:00
|
|
|
|
TestAssetsManager.CreateTestInstance(Path.Combine("ProjectsWithTests", "NetCoreAppOnlyProject"), identifier: "ConsoleTests");
|
2016-03-15 00:38:36 +00:00
|
|
|
|
|
|
|
|
|
_projectFilePath = Path.Combine(testInstance.TestRoot, "project.json");
|
|
|
|
|
var contexts = ProjectContext.CreateContextForEachFramework(
|
|
|
|
|
_projectFilePath,
|
|
|
|
|
null,
|
2016-04-28 23:30:32 +00:00
|
|
|
|
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
|
2016-03-15 00:38:36 +00:00
|
|
|
|
|
2016-04-13 22:59:48 +00:00
|
|
|
|
// Restore the project again in the destination to resolve projects
|
|
|
|
|
// Since the lock file has project relative paths in it, those will be broken
|
|
|
|
|
// unless we re-restore
|
|
|
|
|
new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute().Should().Pass();
|
|
|
|
|
|
2016-04-08 03:08:17 +00:00
|
|
|
|
_defaultOutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0");
|
2016-03-15 00:38:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ISSUE https://github.com/dotnet/cli/issues/1935
|
2016-03-17 18:56:57 +00:00
|
|
|
|
// This fact technically succeeds on Windows, but it causes a crash dialog to pop, which interrupts the build.
|
|
|
|
|
//[WindowsOnlyFact]
|
2016-03-15 00:38:36 +00:00
|
|
|
|
public void It_returns_a_failure_when_it_fails_to_run_the_tests()
|
|
|
|
|
{
|
|
|
|
|
var testCommand = new DotnetTestCommand();
|
|
|
|
|
var result = testCommand.Execute(
|
|
|
|
|
$"{_projectFilePath} -o {Path.Combine(AppContext.BaseDirectory, "nonExistingFolder")} --no-build");
|
|
|
|
|
result.Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void It_builds_the_project_before_running()
|
|
|
|
|
{
|
|
|
|
|
var testCommand = new DotnetTestCommand();
|
|
|
|
|
var result = testCommand.Execute($"{_projectFilePath}");
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 22:22:09 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void It_runs_tests_for_a_local_project_json()
|
|
|
|
|
{
|
|
|
|
|
string projectDirectory = Path.GetDirectoryName(_projectFilePath);
|
|
|
|
|
|
|
|
|
|
new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute("project.json")
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 00:38:36 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void It_builds_the_project_using_the_output_passed()
|
|
|
|
|
{
|
|
|
|
|
var testCommand = new DotnetTestCommand();
|
2016-03-21 21:00:03 +00:00
|
|
|
|
var result = testCommand.Execute(
|
2016-04-08 03:08:17 +00:00
|
|
|
|
$"{_projectFilePath} -o {Path.Combine(AppContext.BaseDirectory, "output")} -f netcoreapp1.0");
|
2016-03-15 00:38:36 +00:00
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void It_builds_the_project_using_the_build_base_path_passed()
|
|
|
|
|
{
|
|
|
|
|
var buildBasePath = GetNotSoLongBuildBasePath();
|
|
|
|
|
var testCommand = new DotnetTestCommand();
|
|
|
|
|
var result = testCommand.Execute($"{_projectFilePath} -b {buildBasePath}");
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void It_skips_build_when_the_no_build_flag_is_passed()
|
|
|
|
|
{
|
|
|
|
|
var buildCommand = new BuildCommand(_projectFilePath);
|
|
|
|
|
var result = buildCommand.Execute();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var testCommand = new DotnetTestCommand();
|
|
|
|
|
result = testCommand.Execute($"{_projectFilePath} -o {_defaultOutputPath} --no-build");
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetNotSoLongBuildBasePath()
|
|
|
|
|
{
|
|
|
|
|
return Path.GetFullPath(
|
|
|
|
|
Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "buildBasePathTest"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|