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