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