2016-10-04 10:07: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 Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-10-25 14:40:18 +00:00
|
|
|
|
using System.IO;
|
2016-10-25 15:27:59 +00:00
|
|
|
|
using System;
|
2016-10-04 10:07:36 +00:00
|
|
|
|
|
2016-10-28 14:45:38 +00:00
|
|
|
|
namespace Microsoft.DotNet.Cli.Test.Tests
|
2016-10-04 10:07:36 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public class GivenDotnettestBuildsAndRunsTestfromCsproj : TestBase
|
2016-10-04 10:07:36 +00:00
|
|
|
|
{
|
2016-11-01 21:31:13 +00:00
|
|
|
|
[Fact]
|
2016-11-02 18:08:20 +00:00
|
|
|
|
public void MSTestSingleTFM()
|
2016-10-04 10:07:36 +00:00
|
|
|
|
{
|
2016-11-02 18:44:03 +00:00
|
|
|
|
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
string testAppName = "VSTestDotNetCore";
|
2016-10-04 10:07:36 +00:00
|
|
|
|
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
|
|
|
|
|
|
|
|
|
|
string testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
|
2016-11-02 18:44:03 +00:00
|
|
|
|
// Restore project VSTestDotNetCore
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new RestoreCommand()
|
2016-10-04 10:07:36 +00:00
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
// Call test
|
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-11-01 20:15:44 +00:00
|
|
|
|
.ExecuteWithCapturedOutput();
|
2016-10-04 10:07:36 +00:00
|
|
|
|
|
|
|
|
|
// Verify
|
|
|
|
|
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
|
|
|
|
|
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
|
|
|
|
|
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
|
|
|
|
|
}
|
2016-10-25 14:40:18 +00:00
|
|
|
|
|
2016-11-01 21:31:13 +00:00
|
|
|
|
[Fact]
|
2016-11-02 18:08:20 +00:00
|
|
|
|
public void XunitSingleTFM()
|
2016-11-01 20:15:44 +00:00
|
|
|
|
{
|
2016-11-02 18:44:03 +00:00
|
|
|
|
// Copy VSTestXunitDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
string testAppName = "VSTestXunitDotNetCore";
|
2016-11-01 20:15:44 +00:00
|
|
|
|
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
|
|
|
|
|
|
|
|
|
|
string testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
|
2016-11-02 18:44:03 +00:00
|
|
|
|
// Restore project VSTestXunitDotNetCore
|
2016-11-01 20:15:44 +00:00
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
|
|
// Call test
|
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.ExecuteWithCapturedOutput();
|
|
|
|
|
|
|
|
|
|
// Verify
|
|
|
|
|
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
|
|
|
|
|
result.StdOut.Should().Contain("Passed TestNamespace.VSTestXunitTests.VSTestXunitPassTest");
|
|
|
|
|
result.StdOut.Should().Contain("Failed TestNamespace.VSTestXunitTests.VSTestXunitFailTest");
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 21:31:13 +00:00
|
|
|
|
[Fact]
|
2016-10-25 14:40:18 +00:00
|
|
|
|
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
|
|
|
|
|
{
|
2016-11-02 18:44:03 +00:00
|
|
|
|
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
string testAppName = "VSTestDotNetCore";
|
2016-10-25 14:40:18 +00:00
|
|
|
|
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
|
|
|
|
|
|
|
|
|
|
string testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
|
2016-11-02 18:44:03 +00:00
|
|
|
|
// Restore project VSTestDotNetCore
|
2016-10-28 14:45:38 +00:00
|
|
|
|
new RestoreCommand()
|
2016-10-25 14:40:18 +00:00
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
2016-10-25 15:27:59 +00:00
|
|
|
|
string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
2016-10-26 11:23:34 +00:00
|
|
|
|
string expectedError = Path.Combine(testProjectDirectory, "bin",
|
2016-11-02 18:44:03 +00:00
|
|
|
|
configuration, "netcoreapp1.0", "VSTestDotNetCore.dll");
|
2016-10-26 11:23:34 +00:00
|
|
|
|
expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found.";
|
2016-10-25 14:40:18 +00:00
|
|
|
|
|
2016-11-01 16:31:30 +00:00
|
|
|
|
// Call test
|
2016-10-28 14:45:38 +00:00
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
2016-10-26 11:23:34 +00:00
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.ExecuteWithCapturedOutput("--noBuild");
|
2016-10-25 14:40:18 +00:00
|
|
|
|
|
|
|
|
|
// Verify
|
2016-10-26 11:23:34 +00:00
|
|
|
|
result.StdOut.Should().Contain(expectedError);
|
2016-10-25 14:40:18 +00:00
|
|
|
|
}
|
2016-10-04 10:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|