2016-10-28 14:45:38 +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 FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using System.IO;
|
2016-11-01 20:15:44 +00:00
|
|
|
|
using System;
|
2017-06-13 07:04:25 +00:00
|
|
|
|
using Xunit;
|
2016-10-28 14:45:38 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Test.Tests
|
|
|
|
|
{
|
2016-11-24 08:48:54 +00:00
|
|
|
|
public class GivenDotnetTestBuildsAndRunsTestFromCsprojForMultipleTFM : TestBase
|
2016-10-28 14:45:38 +00:00
|
|
|
|
{
|
2017-05-03 04:30:51 +00:00
|
|
|
|
[WindowsOnlyFact]
|
2016-11-02 18:08:20 +00:00
|
|
|
|
public void MStestMultiTFM()
|
2016-10-28 14:45:38 +00:00
|
|
|
|
{
|
2017-05-03 04:30:51 +00:00
|
|
|
|
var testProjectDirectory = TestAssets.Get("VSTestMulti")
|
|
|
|
|
.CreateInstance("1")
|
2016-11-04 05:12:33 +00:00
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages)
|
|
|
|
|
.Root;
|
|
|
|
|
|
|
|
|
|
var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
2016-10-28 14:45:38 +00:00
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-11-04 05:12:33 +00:00
|
|
|
|
.WithRuntime(runtime)
|
2016-10-28 14:45:38 +00:00
|
|
|
|
.Execute()
|
2016-11-04 05:12:33 +00:00
|
|
|
|
.Should().Pass();
|
2016-10-28 14:45:38 +00:00
|
|
|
|
|
2016-11-04 05:12:33 +00:00
|
|
|
|
var result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.WithRuntime(runtime)
|
2017-02-18 17:35:33 +00:00
|
|
|
|
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
|
2016-11-04 05:12:33 +00:00
|
|
|
|
|
2017-06-13 01:32:31 +00:00
|
|
|
|
if (!DotnetUnderTest.IsLocalized())
|
|
|
|
|
{
|
|
|
|
|
result.StdOut
|
|
|
|
|
.Should().Contain("Total tests: 3. Passed: 2. Failed: 1. Skipped: 0.", "because .NET 4.6 tests will pass")
|
|
|
|
|
.And.Contain("Passed TestNamespace.VSTestTests.VSTestPassTestDesktop", "because .NET 4.6 tests will pass")
|
|
|
|
|
.And.Contain("Total tests: 3. Passed: 1. Failed: 2. Skipped: 0.", "because netcoreapp2.0 tests will fail")
|
|
|
|
|
.And.Contain("Failed TestNamespace.VSTestTests.VSTestFailTestNetCoreApp", "because netcoreapp2.0 tests will fail");
|
|
|
|
|
}
|
2016-12-16 10:09:52 +00:00
|
|
|
|
result.ExitCode.Should().Be(1);
|
2016-11-01 20:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[WindowsOnlyFact]
|
2016-11-02 18:08:20 +00:00
|
|
|
|
public void XunitMultiTFM()
|
2016-11-01 20:15:44 +00:00
|
|
|
|
{
|
2017-05-03 04:30:51 +00:00
|
|
|
|
// Copy XunitMulti project in output directory of project dotnet-test.Tests
|
|
|
|
|
string testAppName = "XunitMulti";
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
2017-05-03 04:30:51 +00:00
|
|
|
|
.CreateInstance("2")
|
2017-02-15 23:35:03 +00:00
|
|
|
|
.WithSourceFiles();
|
2016-11-01 20:15:44 +00:00
|
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2016-11-01 20:15:44 +00:00
|
|
|
|
|
2017-05-03 04:30:51 +00:00
|
|
|
|
// Restore project XunitMulti
|
2016-11-01 20:15:44 +00:00
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
|
|
// Call test
|
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-02-18 17:35:33 +00:00
|
|
|
|
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
|
2016-11-02 09:37:13 +00:00
|
|
|
|
|
2016-11-02 18:08:20 +00:00
|
|
|
|
// Verify
|
2017-06-13 01:32:31 +00:00
|
|
|
|
if (!DotnetUnderTest.IsLocalized())
|
|
|
|
|
{
|
|
|
|
|
// for target framework net46
|
|
|
|
|
result.StdOut.Should().Contain("Total tests: 3. Passed: 2. Failed: 1. Skipped: 0.");
|
|
|
|
|
result.StdOut.Should().Contain("Passed TestNamespace.VSTestXunitTests.VSTestXunitPassTestDesktop");
|
|
|
|
|
|
|
|
|
|
// for target framework netcoreapp1.0
|
|
|
|
|
result.StdOut.Should().Contain("Total tests: 3. Passed: 1. Failed: 2. Skipped: 0.");
|
|
|
|
|
result.StdOut.Should().Contain("Failed TestNamespace.VSTestXunitTests.VSTestXunitFailTestNetCoreApp");
|
|
|
|
|
}
|
2016-11-01 20:15:44 +00:00
|
|
|
|
|
2016-12-16 10:09:52 +00:00
|
|
|
|
result.ExitCode.Should().Be(1);
|
2016-10-28 14:45:38 +00:00
|
|
|
|
}
|
2017-06-13 01:32:31 +00:00
|
|
|
|
|
2017-06-13 07:04:25 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItCanTestAMultiTFMProjectWithImplicitRestore()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get(
|
|
|
|
|
TestAssetKinds.DesktopTestProjects,
|
|
|
|
|
"MultiTFMXunitProject")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
string projectDirectory = Path.Combine(testInstance.Root.FullName, "XUnitProject");
|
|
|
|
|
|
|
|
|
|
new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --framework netcoreapp2.0")
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
}
|
2016-10-28 14:45:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|