2017-04-05 13:50:12 -07:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2016-06-09 20:52:49 -07:00
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System ;
using System.IO ;
using System.Collections.Generic ;
using Microsoft.DotNet.Cli.Utils ;
using Microsoft.DotNet.Cli ;
using Microsoft.DotNet.TestFramework ;
using Microsoft.DotNet.Tools.Test.Utilities ;
using Xunit ;
using FluentAssertions ;
2017-01-31 17:31:37 -08:00
[assembly: CollectionBehavior(DisableTestParallelization = true)]
2016-06-09 20:52:49 -07:00
namespace Microsoft.DotNet.Tests
{
2017-01-31 17:31:37 -08:00
public class GivenThatTheUserIsRunningDotNetForTheFirstTime : TestBase
2016-06-09 20:52:49 -07:00
{
2016-06-22 15:17:54 -07:00
private static CommandResult _firstDotnetNonVerbUseCommandResult ;
private static CommandResult _firstDotnetVerbUseCommandResult ;
2017-03-30 11:28:01 -07:00
private static DirectoryInfo _nugetFallbackFolder ;
2017-07-25 22:30:36 -07:00
private static DirectoryInfo _dotDotnetFolder ;
private static string _testDirectory ;
2016-06-09 20:52:49 -07:00
static GivenThatTheUserIsRunningDotNetForTheFirstTime ( )
{
2017-07-25 22:30:36 -07:00
_testDirectory = TestAssets . CreateTestDirectory ( "Dotnet_first_time_experience_tests" ) . FullName ;
var testNuGetHome = Path . Combine ( _testDirectory , "nuget_home" ) ;
2017-05-31 13:44:03 -07:00
var cliTestFallbackFolder = Path . Combine ( testNuGetHome , ".dotnet" , "NuGetFallbackFolder" ) ;
2017-11-27 10:45:43 -08:00
var profiled = Path . Combine ( _testDirectory , "profile.d" ) ;
var pathsd = Path . Combine ( _testDirectory , "paths.d" ) ;
2016-06-09 20:52:49 -07:00
var command = new DotnetCommand ( )
2017-07-25 22:30:36 -07:00
. WithWorkingDirectory ( _testDirectory ) ;
2017-03-30 11:28:01 -07:00
command . Environment [ "HOME" ] = testNuGetHome ;
command . Environment [ "USERPROFILE" ] = testNuGetHome ;
2017-04-03 10:45:35 -07:00
command . Environment [ "APPDATA" ] = testNuGetHome ;
2017-05-31 13:44:03 -07:00
command . Environment [ "DOTNET_CLI_TEST_FALLBACKFOLDER" ] = cliTestFallbackFolder ;
2017-11-27 10:45:43 -08:00
command . Environment [ "DOTNET_CLI_TEST_LINUX_PROFILED_PATH" ] = profiled ;
command . Environment [ "DOTNET_CLI_TEST_OSX_PATHSD_PATH" ] = pathsd ;
2016-06-14 02:41:47 -07:00
command . Environment [ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE" ] = "" ;
2016-10-14 00:06:35 -07:00
command . Environment [ "SkipInvalidConfigurations" ] = "true" ;
2016-06-09 20:52:49 -07:00
2016-06-22 15:17:54 -07:00
_firstDotnetNonVerbUseCommandResult = command . ExecuteWithCapturedOutput ( "--info" ) ;
2017-01-31 17:31:37 -08:00
_firstDotnetVerbUseCommandResult = command . ExecuteWithCapturedOutput ( "new --debug:ephemeral-hive" ) ;
2016-06-09 20:52:49 -07:00
2017-05-31 13:44:03 -07:00
_nugetFallbackFolder = new DirectoryInfo ( cliTestFallbackFolder ) ;
2017-07-25 22:30:36 -07:00
_dotDotnetFolder = new DirectoryInfo ( Path . Combine ( testNuGetHome , ".dotnet" ) ) ;
2017-03-02 20:35:20 -08:00
}
2016-06-09 20:52:49 -07:00
[Fact]
2016-12-13 14:15:35 -08:00
public void UsingDotnetForTheFirstTimeSucceeds ( )
2016-06-09 20:52:49 -07:00
{
2016-08-18 15:25:16 -07:00
_firstDotnetVerbUseCommandResult
. Should ( )
. Pass ( ) ;
2016-06-22 15:17:54 -07:00
}
[Fact]
2016-12-13 14:15:35 -08:00
public void UsingDotnetForTheFirstTimeWithNonVerbsDoesNotPrintEula ( )
2016-06-22 15:17:54 -07:00
{
2017-06-12 17:31:40 -07:00
string firstTimeNonVerbUseMessage = Cli . Utils . LocalizableStrings . DotNetCommandLineTools ;
2016-06-22 15:17:54 -07:00
2016-08-18 15:25:16 -07:00
_firstDotnetNonVerbUseCommandResult . StdOut
. Should ( )
. StartWith ( firstTimeNonVerbUseMessage ) ;
2016-06-09 20:52:49 -07:00
}
[Fact]
2016-12-13 14:15:35 -08:00
public void ItShowsTheAppropriateMessageToTheUser ( )
2016-06-09 20:52:49 -07:00
{
2017-06-19 11:54:42 -07:00
_firstDotnetVerbUseCommandResult . StdOut
. Should ( )
. ContainVisuallySameFragment ( Configurer . LocalizableStrings . FirstTimeWelcomeMessage )
. And . NotContain ( "Restore completed in" ) ;
2016-06-09 20:52:49 -07:00
}
2018-01-09 23:10:59 -08:00
[Fact]
public void ItShowsTheAspNetCertificateGenerationMessageToTheUser ( )
{
_firstDotnetVerbUseCommandResult . StdOut
. Should ( )
. ContainVisuallySameFragment ( Configurer . LocalizableStrings . AspNetCertificateInstalled )
. And . NotContain ( "Restore completed in" ) ;
}
2017-01-31 17:31:37 -08:00
[Fact]
public void ItCreatesASentinelFileUnderTheNuGetCacheFolder ( )
{
2017-03-30 11:28:01 -07:00
_nugetFallbackFolder
2016-08-18 15:25:16 -07:00
. Should ( )
2017-01-23 20:21:58 -08:00
. HaveFile ( $"{GetDotnetVersion()}.dotnetSentinel" ) ;
2016-06-09 20:52:49 -07:00
}
2017-07-25 22:30:36 -07:00
[Fact]
public void ItCreatesAFirstUseSentinelFileUnderTheDotDotNetFolder ( )
{
_dotDotnetFolder
. Should ( )
. HaveFile ( $"{GetDotnetVersion()}.dotnetFirstUseSentinel" ) ;
}
[Fact]
2018-01-09 23:10:59 -08:00
public void ItCreatesAnAspNetCertificateSentinelFileUnderTheDotDotNetFolder ( )
{
_dotDotnetFolder
. Should ( )
. HaveFile ( $"{GetDotnetVersion()}.aspNetCertificateSentinel" ) ;
}
[Fact]
public void ItDoesNotCreateAFirstUseSentinelFileNorAnAspNetCertificateSentinelFileUnderTheDotDotNetFolderWhenInternalReportInstallSuccessIsInvoked ( )
2017-07-25 22:30:36 -07:00
{
2017-07-26 10:29:10 -07:00
var emptyHome = Path . Combine ( _testDirectory , "empty_home" ) ;
2017-11-27 10:45:43 -08:00
var profiled = Path . Combine ( _testDirectory , "profile.d" ) ;
var pathsd = Path . Combine ( _testDirectory , "paths.d" ) ;
2017-07-25 22:30:36 -07:00
var command = new DotnetCommand ( )
. WithWorkingDirectory ( _testDirectory ) ;
2017-07-26 10:29:10 -07:00
command . Environment [ "HOME" ] = emptyHome ;
command . Environment [ "USERPROFILE" ] = emptyHome ;
command . Environment [ "APPDATA" ] = emptyHome ;
2017-07-25 22:30:36 -07:00
command . Environment [ "DOTNET_CLI_TEST_FALLBACKFOLDER" ] = _nugetFallbackFolder . FullName ;
command . Environment [ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE" ] = "" ;
2017-11-27 10:45:43 -08:00
command . Environment [ "DOTNET_CLI_TEST_LINUX_PROFILED_PATH" ] = profiled ;
command . Environment [ "DOTNET_CLI_TEST_OSX_PATHSD_PATH" ] = pathsd ;
2017-07-26 10:29:10 -07:00
// Disable to prevent the creation of the .dotnet folder by optimizationdata.
command . Environment [ "DOTNET_DISABLE_MULTICOREJIT" ] = "true" ;
2017-07-25 22:30:36 -07:00
command . Environment [ "SkipInvalidConfigurations" ] = "true" ;
command . ExecuteWithCapturedOutput ( "internal-reportinstallsuccess test" ) . Should ( ) . Pass ( ) ;
2017-06-05 20:51:58 -07:00
var homeFolder = new DirectoryInfo ( Path . Combine ( emptyHome , ".dotnet" ) ) ;
string [ ] fileEntries = Directory . GetFiles ( homeFolder . ToString ( ) ) ;
fileEntries . Should ( ) . OnlyContain ( x = > ! x . Contains ( ".dotnetFirstUseSentinel" ) ) ;
2018-01-09 23:10:59 -08:00
fileEntries . Should ( ) . OnlyContain ( x = > ! x . Contains ( ".aspNetCertificateSentinel" ) ) ;
2017-07-25 22:30:36 -07:00
}
[Fact]
public void ItShowsTheTelemetryNoticeWhenInvokingACommandAfterInternalReportInstallSuccessHasBeenInvoked ( )
{
var newHome = Path . Combine ( _testDirectory , "new_home" ) ;
var newHomeFolder = new DirectoryInfo ( Path . Combine ( newHome , ".dotnet" ) ) ;
2017-11-27 10:45:43 -08:00
var profiled = Path . Combine ( _testDirectory , "profile.d" ) ;
var pathsd = Path . Combine ( _testDirectory , "paths.d" ) ;
2017-07-25 22:30:36 -07:00
var command = new DotnetCommand ( )
. WithWorkingDirectory ( _testDirectory ) ;
command . Environment [ "HOME" ] = newHome ;
command . Environment [ "USERPROFILE" ] = newHome ;
command . Environment [ "APPDATA" ] = newHome ;
command . Environment [ "DOTNET_CLI_TEST_FALLBACKFOLDER" ] = _nugetFallbackFolder . FullName ;
2017-11-27 10:45:43 -08:00
command . Environment [ "DOTNET_CLI_TEST_LINUX_PROFILED_PATH" ] = profiled ;
command . Environment [ "DOTNET_CLI_TEST_OSX_PATHSD_PATH" ] = pathsd ;
2017-07-25 22:30:36 -07:00
command . Environment [ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE" ] = "" ;
command . Environment [ "SkipInvalidConfigurations" ] = "true" ;
command . ExecuteWithCapturedOutput ( "internal-reportinstallsuccess test" ) . Should ( ) . Pass ( ) ;
var result = command . ExecuteWithCapturedOutput ( "new --debug:ephemeral-hive" ) ;
result . StdOut
. Should ( )
. ContainVisuallySameFragment ( Configurer . LocalizableStrings . FirstTimeWelcomeMessage ) ;
}
2018-01-09 23:10:59 -08:00
[Fact]
public void ItShowsTheAspNetCertificateGenerationMessageWhenInvokingACommandAfterInternalReportInstallSuccessHasBeenInvoked ( )
{
var newHome = Path . Combine ( _testDirectory , "aspnet_home" ) ;
var newHomeFolder = new DirectoryInfo ( Path . Combine ( newHome , ".dotnet" ) ) ;
var profiled = Path . Combine ( _testDirectory , "profile.d" ) ;
var pathsd = Path . Combine ( _testDirectory , "paths.d" ) ;
var command = new DotnetCommand ( )
. WithWorkingDirectory ( _testDirectory ) ;
command . Environment [ "HOME" ] = newHome ;
command . Environment [ "USERPROFILE" ] = newHome ;
command . Environment [ "APPDATA" ] = newHome ;
command . Environment [ "DOTNET_CLI_TEST_FALLBACKFOLDER" ] = _nugetFallbackFolder . FullName ;
command . Environment [ "DOTNET_CLI_TEST_LINUX_PROFILED_PATH" ] = profiled ;
command . Environment [ "DOTNET_CLI_TEST_OSX_PATHSD_PATH" ] = pathsd ;
command . Environment [ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE" ] = "" ;
command . Environment [ "SkipInvalidConfigurations" ] = "true" ;
command . ExecuteWithCapturedOutput ( "internal-reportinstallsuccess test" ) . Should ( ) . Pass ( ) ;
var result = command . ExecuteWithCapturedOutput ( "new --debug:ephemeral-hive" ) ;
result . StdOut
. Should ( )
. ContainVisuallySameFragment ( Configurer . LocalizableStrings . AspNetCertificateInstalled ) ;
}
2016-06-09 20:52:49 -07:00
[Fact]
2016-12-27 11:28:24 -10:00
public void ItRestoresTheNuGetPackagesToTheNuGetCacheFolder ( )
2016-06-09 20:52:49 -07:00
{
2016-12-27 11:28:24 -10:00
List < string > expectedDirectories = new List < string > ( )
{
"microsoft.netcore.app" ,
2017-01-27 17:46:55 -06:00
"microsoft.netcore.platforms" ,
"netstandard.library" ,
2016-12-27 11:28:24 -10:00
"microsoft.aspnetcore.diagnostics" ,
"microsoft.aspnetcore.mvc" ,
"microsoft.aspnetcore.routing" ,
"microsoft.aspnetcore.server.iisintegration" ,
"microsoft.aspnetcore.server.kestrel" ,
"microsoft.aspnetcore.staticfiles" ,
"microsoft.extensions.configuration.environmentvariables" ,
"microsoft.extensions.configuration.json" ,
"microsoft.extensions.logging" ,
"microsoft.extensions.logging.console" ,
"microsoft.extensions.logging.debug" ,
"microsoft.extensions.options.configurationextensions" ,
2017-04-22 11:52:54 -07:00
//BrowserLink has been temporarily disabled until https://github.com/dotnet/templating/issues/644 is resolved
//"microsoft.visualstudio.web.browserlink",
2016-12-27 11:28:24 -10:00
} ;
2017-03-30 11:28:01 -07:00
_nugetFallbackFolder
2016-08-18 15:25:16 -07:00
. Should ( )
2016-12-27 11:28:24 -10:00
. HaveDirectories ( expectedDirectories ) ;
2016-06-09 20:52:49 -07:00
}
2017-01-07 08:43:28 -06:00
private string GetDotnetVersion ( )
2017-01-31 17:31:37 -08:00
{
return new DotnetCommand ( ) . ExecuteWithCapturedOutput ( "--version" ) . StdOut
. TrimEnd ( Environment . NewLine . ToCharArray ( ) ) ;
}
2016-06-09 20:52:49 -07:00
}
2017-03-02 20:35:20 -08:00
}