Enabling E2E tests by setting HOME and USERPROFILE env variables. This will cause the NuGet.Config and fallback folder to be extract to the location in those variables during the tests. Also refactored all NuGet path calculators for the first run to a single place.
This commit is contained in:
parent
a46237784e
commit
0c1af8a2fe
6 changed files with 47 additions and 23 deletions
|
@ -6,6 +6,7 @@ using System.IO;
|
|||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
using NuGet.Common;
|
||||
|
||||
namespace Microsoft.DotNet.Configurer
|
||||
{
|
||||
|
@ -21,5 +22,13 @@ namespace Microsoft.DotNet.Configurer
|
|||
return Path.Combine(profileDir, ".dotnet", "NuGetFallbackFolder");
|
||||
}
|
||||
}
|
||||
|
||||
public string NuGetUserSettingsDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,17 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
private readonly INuGetConfig _nuGetConfig;
|
||||
|
||||
private readonly CLIFallbackFolderPathCalculator _cliFallbackFolderPathCalculator;
|
||||
|
||||
public NuGetCachePrimer(
|
||||
INuGetPackagesArchiver nugetPackagesArchiver,
|
||||
INuGetCacheSentinel nuGetCacheSentinel,
|
||||
INuGetConfig nuGetConfig)
|
||||
INuGetConfig nuGetConfig,
|
||||
CLIFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
|
||||
: this(nugetPackagesArchiver,
|
||||
nuGetCacheSentinel,
|
||||
nuGetConfig,
|
||||
cliFallbackFolderPathCalculator,
|
||||
FileSystemWrapper.Default.File)
|
||||
{
|
||||
}
|
||||
|
@ -33,6 +37,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
INuGetPackagesArchiver nugetPackagesArchiver,
|
||||
INuGetCacheSentinel nuGetCacheSentinel,
|
||||
INuGetConfig nuGetConfig,
|
||||
CLIFallbackFolderPathCalculator cliFallbackFolderPathCalculator,
|
||||
IFile file)
|
||||
{
|
||||
_nugetPackagesArchiver = nugetPackagesArchiver;
|
||||
|
@ -41,6 +46,8 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
_nuGetConfig = nuGetConfig;
|
||||
|
||||
_cliFallbackFolderPathCalculator = cliFallbackFolderPathCalculator;
|
||||
|
||||
_file = file;
|
||||
}
|
||||
|
||||
|
@ -51,8 +58,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
return;
|
||||
}
|
||||
|
||||
var cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator();
|
||||
var nuGetFallbackFolder = cliFallbackFolderPathCalculator.CLIFallbackFolderPath;
|
||||
var nuGetFallbackFolder = _cliFallbackFolderPathCalculator.CLIFallbackFolderPath;
|
||||
|
||||
_nuGetConfig.AddCLIFallbackFolder(nuGetFallbackFolder);
|
||||
|
||||
|
|
|
@ -13,10 +13,9 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
private ISettings _settings;
|
||||
|
||||
public NuGetConfig()
|
||||
public NuGetConfig(CLIFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
|
||||
{
|
||||
var nuGetConfigFolder = NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);
|
||||
_settings = new Settings(nuGetConfigFolder);
|
||||
_settings = new Settings(cliFallbackFolderPathCalculator.NuGetUserSettingsDirectory);
|
||||
}
|
||||
|
||||
internal NuGetConfig(ISettings settings)
|
||||
|
|
|
@ -171,11 +171,15 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
using (var nugetPackagesArchiver = new NuGetPackagesArchiver())
|
||||
{
|
||||
var cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator();
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true);
|
||||
var nugetConfig = new NuGetConfi();
|
||||
var nugetCachePrimer =
|
||||
new NuGetCachePrimer(nugetPackagesArchiver, nugetCacheSentinel, nugetConfig);
|
||||
var nugetConfig = new NuGetConfi(cliFallbackFolderPathCalculator);
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
nugetPackagesArchiver,
|
||||
nugetCacheSentinel,
|
||||
nugetConfig,
|
||||
cliFallbackFolderPathCalculator);
|
||||
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
nugetCachePrimer,
|
||||
nugetCacheSentinel,
|
||||
|
|
|
@ -26,8 +26,7 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
private Mock<INuGetPackagesArchiver> _nugetPackagesArchiverMock;
|
||||
private Mock<INuGetCacheSentinel> _nugetCacheSentinel;
|
||||
private Mock<INuGetConfig> _nugetConfigMock;
|
||||
|
||||
private string _nuGetFallbackFolder;
|
||||
private CLIFallbackFolderPathCalculator _cliFallbackFolderPathCalculator;
|
||||
|
||||
public GivenANuGetCachePrimer()
|
||||
{
|
||||
|
@ -43,15 +42,15 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
|
||||
_nugetConfigMock = new Mock<INuGetConfig>();
|
||||
|
||||
_cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator();
|
||||
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
_nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
_nugetConfigMock.Object,
|
||||
_cliFallbackFolderPathCalculator,
|
||||
_fileSystemMock.File);
|
||||
|
||||
var cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator();
|
||||
_nuGetFallbackFolder = cliFallbackFolderPathCalculator.CLIFallbackFolderPath;
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
}
|
||||
|
||||
|
@ -68,6 +67,7 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
_nugetConfigMock.Object,
|
||||
_cliFallbackFolderPathCalculator,
|
||||
fileSystemMock.File);
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
|
@ -78,13 +78,17 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
[Fact]
|
||||
public void It_adds_the_fallback_folder_to_NuGet_Config()
|
||||
{
|
||||
_nugetConfigMock.Verify(n => n.AddCLIFallbackFolder(_nuGetFallbackFolder), Times.Exactly(1));
|
||||
_nugetConfigMock.Verify(n =>
|
||||
n.AddCLIFallbackFolder(_cliFallbackFolderPathCalculator.CLIFallbackFolderPath),
|
||||
Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_extracts_the_archive_to_the_fallback_folder()
|
||||
{
|
||||
_nugetPackagesArchiverMock.Verify(n => n.ExtractArchive(_nuGetFallbackFolder), Times.Exactly(1));
|
||||
_nugetPackagesArchiverMock.Verify(n =>
|
||||
n.ExtractArchive(_cliFallbackFolderPathCalculator.CLIFallbackFolderPath),
|
||||
Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -104,6 +108,7 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
nugetPackagesArchiveMock.Object,
|
||||
nugetCacheSentinel.Object,
|
||||
_nugetConfigMock.Object,
|
||||
_cliFallbackFolderPathCalculator,
|
||||
_fileSystemMock.File);
|
||||
|
||||
Action action = () => nugetCachePrimer.PrimeCache();
|
||||
|
|
|
@ -19,23 +19,24 @@ namespace Microsoft.DotNet.Tests
|
|||
{
|
||||
private static CommandResult _firstDotnetNonVerbUseCommandResult;
|
||||
private static CommandResult _firstDotnetVerbUseCommandResult;
|
||||
private static DirectoryInfo _nugetCacheFolder;
|
||||
private static DirectoryInfo _nugetFallbackFolder;
|
||||
|
||||
static GivenThatTheUserIsRunningDotNetForTheFirstTime()
|
||||
{
|
||||
var testDirectory = TestAssets.CreateTestDirectory("Dotnet_first_time_experience_tests");
|
||||
var testNugetCache = Path.Combine(testDirectory.FullName, "nuget_cache");
|
||||
var testNuGetHome = Path.Combine(testDirectory.FullName, "nuget_home");
|
||||
|
||||
var command = new DotnetCommand()
|
||||
.WithWorkingDirectory(testDirectory);
|
||||
command.Environment["NUGET_PACKAGES"] = testNugetCache;
|
||||
command.Environment["HOME"] = testNuGetHome;
|
||||
command.Environment["USERPROFILE"] = testNuGetHome;
|
||||
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
|
||||
command.Environment["SkipInvalidConfigurations"] = "true";
|
||||
|
||||
_firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
|
||||
_firstDotnetVerbUseCommandResult = command.ExecuteWithCapturedOutput("new --debug:ephemeral-hive");
|
||||
|
||||
_nugetCacheFolder = new DirectoryInfo(testNugetCache);
|
||||
_nugetFallbackFolder = new DirectoryInfo(Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -82,7 +83,7 @@ A command is running to initially populate your local package cache, to improve
|
|||
[Fact]
|
||||
public void ItCreatesASentinelFileUnderTheNuGetCacheFolder()
|
||||
{
|
||||
_nugetCacheFolder
|
||||
_nugetFallbackFolder
|
||||
.Should()
|
||||
.HaveFile($"{GetDotnetVersion()}.dotnetSentinel");
|
||||
}
|
||||
|
@ -115,11 +116,11 @@ A command is running to initially populate your local package cache, to improve
|
|||
"microsoft.visualstudio.web.browserlink",
|
||||
};
|
||||
|
||||
_nugetCacheFolder
|
||||
_nugetFallbackFolder
|
||||
.Should()
|
||||
.HaveDirectories(expectedDirectories);
|
||||
|
||||
_nugetCacheFolder
|
||||
_nugetFallbackFolder
|
||||
.Should()
|
||||
.NotHaveDirectories(unexpectedDirectories);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue