Modified the build script to generate the lzma archive without the nupkgs. Modified the configurer to upsert NuGet.Config with the fallback folder info and to extract the fallback folder. Added unit tests for all this. Next step: update E2E tests.
This commit is contained in:
parent
3634da519a
commit
a46237784e
12 changed files with 181 additions and 254 deletions
|
@ -99,7 +99,7 @@
|
|||
SkipInvalidConfigurations="True"
|
||||
WorkingDirectory="$(NuGetPackagesArchiveProject)/Console" />
|
||||
|
||||
<Delete Files="$(IntermediateArchive);$(IntermediateArchive).zip" />
|
||||
<Delete Files="$(IntermediateArchive);$(IntermediateArchive).zip;$(NuGetPackagesArchiveFolder)/**/*.nupkg" />
|
||||
|
||||
<Message Text="Publishing Archiver" />
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// 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 System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Configurer
|
||||
{
|
||||
public class CLIFallbackFolderPathCalculator
|
||||
{
|
||||
public string CLIFallbackFolderPath
|
||||
{
|
||||
get
|
||||
{
|
||||
string profileDir = Environment.GetEnvironmentVariable(
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "USERPROFILE" : "HOME");
|
||||
|
||||
return Path.Combine(profileDir, ".dotnet", "NuGetFallbackFolder");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
src/Microsoft.DotNet.Configurer/INuGetConfig.cs
Normal file
10
src/Microsoft.DotNet.Configurer/INuGetConfig.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
// 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.
|
||||
|
||||
namespace Microsoft.DotNet.Configurer
|
||||
{
|
||||
public interface INuGetConfig
|
||||
{
|
||||
void AddCLIFallbackFolder(string fallbackFolderPath);
|
||||
}
|
||||
}
|
|
@ -5,10 +5,10 @@ using System;
|
|||
|
||||
namespace Microsoft.DotNet.Configurer
|
||||
{
|
||||
public interface INuGetPackagesArchiver : IDisposable
|
||||
public interface INuGetPackagesArchiver
|
||||
{
|
||||
string NuGetPackagesArchive { get; }
|
||||
|
||||
string ExtractArchive();
|
||||
void ExtractArchive(string archiveDestination);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
<RepositoryUrl>git://github.com/dotnet/cli</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NuGet.Common" Version="$(CLI_NuGet_Version)" />
|
||||
<PackageReference Include="NuGet.Configuration" Version="$(CLI_NuGet_Version)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
|
|
|
@ -10,48 +10,37 @@ namespace Microsoft.DotNet.Configurer
|
|||
{
|
||||
public class NuGetCachePrimer : INuGetCachePrimer
|
||||
{
|
||||
private static IReadOnlyList<IReadOnlyList<string>> _templatesUsedToPrimeCache = new List<IReadOnlyList<string>>()
|
||||
{
|
||||
new List<string>() { "console", "--debug:ephemeral-hive" },
|
||||
};
|
||||
|
||||
private readonly ICommandFactory _commandFactory;
|
||||
|
||||
private readonly IDirectory _directory;
|
||||
|
||||
private readonly IFile _file;
|
||||
|
||||
private readonly INuGetPackagesArchiver _nugetPackagesArchiver;
|
||||
|
||||
private readonly INuGetCacheSentinel _nuGetCacheSentinel;
|
||||
|
||||
private readonly INuGetConfig _nuGetConfig;
|
||||
|
||||
public NuGetCachePrimer(
|
||||
ICommandFactory commandFactory,
|
||||
INuGetPackagesArchiver nugetPackagesArchiver,
|
||||
INuGetCacheSentinel nuGetCacheSentinel)
|
||||
: this(commandFactory,
|
||||
nugetPackagesArchiver,
|
||||
INuGetCacheSentinel nuGetCacheSentinel,
|
||||
INuGetConfig nuGetConfig)
|
||||
: this(nugetPackagesArchiver,
|
||||
nuGetCacheSentinel,
|
||||
FileSystemWrapper.Default.Directory,
|
||||
nuGetConfig,
|
||||
FileSystemWrapper.Default.File)
|
||||
{
|
||||
}
|
||||
|
||||
internal NuGetCachePrimer(
|
||||
ICommandFactory commandFactory,
|
||||
INuGetPackagesArchiver nugetPackagesArchiver,
|
||||
INuGetCacheSentinel nuGetCacheSentinel,
|
||||
IDirectory directory,
|
||||
INuGetConfig nuGetConfig,
|
||||
IFile file)
|
||||
{
|
||||
_commandFactory = commandFactory;
|
||||
|
||||
_directory = directory;
|
||||
|
||||
_nugetPackagesArchiver = nugetPackagesArchiver;
|
||||
|
||||
_nuGetCacheSentinel = nuGetCacheSentinel;
|
||||
|
||||
_nuGetConfig = nuGetConfig;
|
||||
|
||||
_file = file;
|
||||
}
|
||||
|
||||
|
@ -62,79 +51,19 @@ namespace Microsoft.DotNet.Configurer
|
|||
return;
|
||||
}
|
||||
|
||||
var extractedPackagesArchiveDirectory = _nugetPackagesArchiver.ExtractArchive();
|
||||
var cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator();
|
||||
var nuGetFallbackFolder = cliFallbackFolderPathCalculator.CLIFallbackFolderPath;
|
||||
|
||||
PrimeCacheUsingArchive(extractedPackagesArchiveDirectory);
|
||||
_nuGetConfig.AddCLIFallbackFolder(nuGetFallbackFolder);
|
||||
|
||||
_nugetPackagesArchiver.ExtractArchive(nuGetFallbackFolder);
|
||||
|
||||
_nuGetCacheSentinel.CreateIfNotExists();
|
||||
}
|
||||
|
||||
private bool SkipPrimingTheCache()
|
||||
{
|
||||
return !_file.Exists(_nugetPackagesArchiver.NuGetPackagesArchive);
|
||||
}
|
||||
|
||||
private void PrimeCacheUsingArchive(string extractedPackagesArchiveDirectory)
|
||||
{
|
||||
bool succeeded = true;
|
||||
|
||||
foreach (IReadOnlyList<string> templateInfo in _templatesUsedToPrimeCache)
|
||||
{
|
||||
if (succeeded)
|
||||
{
|
||||
using (var temporaryDotnetNewDirectory = _directory.CreateTemporaryDirectory())
|
||||
{
|
||||
var workingDirectory = temporaryDotnetNewDirectory.DirectoryPath;
|
||||
|
||||
succeeded &= CreateTemporaryProject(workingDirectory, templateInfo);
|
||||
|
||||
if (succeeded)
|
||||
{
|
||||
succeeded &= RestoreTemporaryProject(extractedPackagesArchiveDirectory, workingDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (succeeded)
|
||||
{
|
||||
_nuGetCacheSentinel.CreateIfNotExists();
|
||||
}
|
||||
}
|
||||
|
||||
private bool CreateTemporaryProject(string workingDirectory, IReadOnlyList<string> templateInfo)
|
||||
{
|
||||
return RunCommand(
|
||||
"new",
|
||||
templateInfo,
|
||||
workingDirectory);
|
||||
}
|
||||
|
||||
private bool RestoreTemporaryProject(string extractedPackagesArchiveDirectory, string workingDirectory)
|
||||
{
|
||||
return RunCommand(
|
||||
"restore",
|
||||
new[] { "-s", extractedPackagesArchiveDirectory },
|
||||
workingDirectory);
|
||||
}
|
||||
|
||||
private bool RunCommand(string commandToExecute, IEnumerable<string> args, string workingDirectory)
|
||||
{
|
||||
var command = _commandFactory
|
||||
.Create(commandToExecute, args)
|
||||
.WorkingDirectory(workingDirectory)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr();
|
||||
|
||||
var commandResult = command.Execute();
|
||||
|
||||
if (commandResult.ExitCode != 0)
|
||||
{
|
||||
Reporter.Verbose.WriteLine(commandResult.StdErr);
|
||||
|
||||
Reporter.Error.WriteLine(
|
||||
string.Format(LocalizableStrings.FailedToPrimeCacheError, commandToExecute, commandResult.ExitCode));
|
||||
}
|
||||
|
||||
return commandResult.ExitCode == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
40
src/Microsoft.DotNet.Configurer/NuGetConfig.cs
Normal file
40
src/Microsoft.DotNet.Configurer/NuGetConfig.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
// 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 NuGet.Common;
|
||||
using NuGet.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Configurer
|
||||
{
|
||||
public class NuGetConfig : INuGetConfig
|
||||
{
|
||||
public const string FallbackPackageFolders = "fallbackPackageFolders";
|
||||
|
||||
private ISettings _settings;
|
||||
|
||||
public NuGetConfig()
|
||||
{
|
||||
var nuGetConfigFolder = NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);
|
||||
_settings = new Settings(nuGetConfigFolder);
|
||||
}
|
||||
|
||||
internal NuGetConfig(ISettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public void AddCLIFallbackFolder(string fallbackFolderPath)
|
||||
{
|
||||
if (!IsCLIFallbackFolderSet(fallbackFolderPath))
|
||||
{
|
||||
_settings.SetValue(FallbackPackageFolders, "CLIFallbackFolder", fallbackFolderPath);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsCLIFallbackFolderSet(string fallbackFolderPath)
|
||||
{
|
||||
return _settings.GetSettingValues(FallbackPackageFolders).Any(s => s.Value == fallbackFolderPath);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,33 +10,15 @@ namespace Microsoft.DotNet.Configurer
|
|||
{
|
||||
public class NuGetPackagesArchiver : INuGetPackagesArchiver
|
||||
{
|
||||
private ITemporaryDirectory _temporaryDirectory;
|
||||
|
||||
public string NuGetPackagesArchive =>
|
||||
Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "nuGetPackagesArchive.lzma"));
|
||||
|
||||
public NuGetPackagesArchiver() : this(FileSystemWrapper.Default.Directory)
|
||||
{
|
||||
}
|
||||
|
||||
internal NuGetPackagesArchiver(IDirectory directory)
|
||||
{
|
||||
_temporaryDirectory = directory.CreateTemporaryDirectory();
|
||||
}
|
||||
|
||||
public string ExtractArchive()
|
||||
public void ExtractArchive(string archiveDestination)
|
||||
{
|
||||
var progress = new ConsoleProgressReport();
|
||||
var archive = new IndexedArchive();
|
||||
|
||||
archive.Extract(NuGetPackagesArchive, _temporaryDirectory.DirectoryPath, progress);
|
||||
|
||||
return _temporaryDirectory.DirectoryPath;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_temporaryDirectory.Dispose();
|
||||
archive.Extract(NuGetPackagesArchive, archiveDestination, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,8 +173,9 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true);
|
||||
var nugetConfig = new NuGetConfi();
|
||||
var nugetCachePrimer =
|
||||
new NuGetCachePrimer(commandFactory, nugetPackagesArchiver, nugetCacheSentinel);
|
||||
new NuGetCachePrimer(nugetPackagesArchiver, nugetCacheSentinel, nugetConfig);
|
||||
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
nugetCachePrimer,
|
||||
nugetCacheSentinel,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
|
@ -21,13 +22,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
private const string PACKAGES_ARCHIVE_PATH = "some other path";
|
||||
|
||||
private IFileSystem _fileSystemMock;
|
||||
private ITemporaryDirectoryMock _temporaryDirectoryMock;
|
||||
|
||||
private Mock<ICommandFactory> _commandFactoryMock;
|
||||
private Mock<ICommand> _dotnetNewCommandMock;
|
||||
private Mock<ICommand> _dotnetRestoreCommandMock;
|
||||
private Mock<INuGetPackagesArchiver> _nugetPackagesArchiverMock;
|
||||
private Mock<INuGetCacheSentinel> _nugetCacheSentinel;
|
||||
private Mock<INuGetConfig> _nugetConfigMock;
|
||||
|
||||
private string _nuGetFallbackFolder;
|
||||
|
||||
public GivenANuGetCachePrimer()
|
||||
{
|
||||
|
@ -35,175 +35,56 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
fileSystemMockBuilder.TemporaryFolder = TEMPORARY_FOLDER_PATH;
|
||||
fileSystemMockBuilder.AddFile(COMPRESSED_ARCHIVE_PATH);
|
||||
_fileSystemMock = fileSystemMockBuilder.Build();
|
||||
_temporaryDirectoryMock = (ITemporaryDirectoryMock)_fileSystemMock.Directory.CreateTemporaryDirectory();
|
||||
|
||||
_commandFactoryMock = SetupCommandFactoryMock();
|
||||
|
||||
|
||||
_nugetPackagesArchiverMock = new Mock<INuGetPackagesArchiver>();
|
||||
_nugetPackagesArchiverMock.Setup(n => n.ExtractArchive()).Returns(PACKAGES_ARCHIVE_PATH);
|
||||
_nugetPackagesArchiverMock.Setup(n => n.NuGetPackagesArchive).Returns(COMPRESSED_ARCHIVE_PATH);
|
||||
|
||||
_nugetCacheSentinel = new Mock<INuGetCacheSentinel>();
|
||||
|
||||
_nugetConfigMock = new Mock<INuGetConfig>();
|
||||
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
_commandFactoryMock.Object,
|
||||
_nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
_fileSystemMock.Directory,
|
||||
_nugetConfigMock.Object,
|
||||
_fileSystemMock.File);
|
||||
|
||||
var cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator();
|
||||
_nuGetFallbackFolder = cliFallbackFolderPathCalculator.CLIFallbackFolderPath;
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
}
|
||||
|
||||
private Mock<ICommandFactory> SetupCommandFactoryMock()
|
||||
{
|
||||
var commandFactoryMock = new Mock<ICommandFactory>();
|
||||
|
||||
_dotnetNewCommandMock = new Mock<ICommand>();
|
||||
SetupCommandMock(_dotnetNewCommandMock);
|
||||
|
||||
commandFactoryMock
|
||||
.Setup(c => c.Create("new", new[] { "console", "--debug:ephemeral-hive" }, null, Constants.DefaultConfiguration))
|
||||
.Returns(_dotnetNewCommandMock.Object);
|
||||
|
||||
_dotnetRestoreCommandMock = new Mock<ICommand>();
|
||||
SetupCommandMock(_dotnetRestoreCommandMock);
|
||||
commandFactoryMock
|
||||
.Setup(c => c.Create(
|
||||
"restore",
|
||||
It.IsAny<IEnumerable<string>>(),
|
||||
null,
|
||||
Constants.DefaultConfiguration))
|
||||
.Returns(_dotnetRestoreCommandMock.Object);
|
||||
|
||||
return commandFactoryMock;
|
||||
}
|
||||
|
||||
private void SetupCommandMock(Mock<ICommand> commandMock)
|
||||
{
|
||||
commandMock
|
||||
.Setup(c => c.WorkingDirectory(TEMPORARY_FOLDER_PATH))
|
||||
.Returns(commandMock.Object);
|
||||
commandMock.Setup(c => c.CaptureStdOut()).Returns(commandMock.Object);
|
||||
commandMock.Setup(c => c.CaptureStdErr()).Returns(commandMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_prime_the_NuGet_cache_if_the_archive_is_not_found_so_that_we_do_not_need_to_generate_the_archive_for_stage1()
|
||||
{
|
||||
var fileSystemMockBuilder = FileSystemMockBuilder.Create();
|
||||
var fileSystemMock = fileSystemMockBuilder.Build();
|
||||
|
||||
var commandFactoryMock = SetupCommandFactoryMock();
|
||||
|
||||
var nugetPackagesArchiverMock = new Mock<INuGetPackagesArchiver>();
|
||||
nugetPackagesArchiverMock.Setup(n => n.NuGetPackagesArchive).Returns(COMPRESSED_ARCHIVE_PATH);
|
||||
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
commandFactoryMock.Object,
|
||||
nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
fileSystemMock.Directory,
|
||||
_nugetConfigMock.Object,
|
||||
fileSystemMock.File);
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
|
||||
nugetPackagesArchiverMock.Verify(n => n.ExtractArchive(), Times.Never);
|
||||
commandFactoryMock.Verify(c => c.Create(
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<IEnumerable<string>>(),
|
||||
null,
|
||||
Constants.DefaultConfiguration), Times.Never);
|
||||
nugetPackagesArchiverMock.Verify(n => n.ExtractArchive(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_disposes_the_temporary_directory_created_for_the_temporary_project_used_to_prime_the_cache()
|
||||
public void It_adds_the_fallback_folder_to_NuGet_Config()
|
||||
{
|
||||
_temporaryDirectoryMock.DisposedTemporaryDirectory.Should().BeTrue();
|
||||
_nugetConfigMock.Verify(n => n.AddCLIFallbackFolder(_nuGetFallbackFolder), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_new_using_the_temporary_folder()
|
||||
public void It_extracts_the_archive_to_the_fallback_folder()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.WorkingDirectory(TEMPORARY_FOLDER_PATH), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_new_capturing_stdout()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.CaptureStdOut(), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_new_capturing_stderr()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.CaptureStdErr(), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_actually_runs_dotnet_new()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.Execute(), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_uses_the_packages_archive_with_dotnet_restore()
|
||||
{
|
||||
_commandFactoryMock.Verify(
|
||||
c => c.Create(
|
||||
"restore",
|
||||
new[] { "-s", $"{PACKAGES_ARCHIVE_PATH}" },
|
||||
null,
|
||||
Constants.DefaultConfiguration),
|
||||
Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_run_restore_if_dotnet_new_fails()
|
||||
{
|
||||
var commandFactoryMock = SetupCommandFactoryMock();
|
||||
_dotnetNewCommandMock.Setup(c => c.Execute()).Returns(new CommandResult(null, -1, null, null));
|
||||
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
commandFactoryMock.Object,
|
||||
_nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
_fileSystemMock.Directory,
|
||||
_fileSystemMock.File);
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
|
||||
commandFactoryMock.Verify(
|
||||
c => c.Create(
|
||||
"restore",
|
||||
It.IsAny<IEnumerable<string>>(),
|
||||
It.IsAny<NuGetFramework>(),
|
||||
It.IsAny<string>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_restore_using_the_temporary_folder()
|
||||
{
|
||||
_dotnetRestoreCommandMock.Verify(c => c.WorkingDirectory(TEMPORARY_FOLDER_PATH), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_restore_capturing_stdout()
|
||||
{
|
||||
_dotnetRestoreCommandMock.Verify(c => c.CaptureStdOut(), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_restore_capturing_stderr()
|
||||
{
|
||||
_dotnetRestoreCommandMock.Verify(c => c.CaptureStdErr(), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_actually_runs_dotnet_restore()
|
||||
{
|
||||
_dotnetRestoreCommandMock.Verify(c => c.Execute(), Times.Exactly(1));
|
||||
_nugetPackagesArchiverMock.Verify(n => n.ExtractArchive(_nuGetFallbackFolder), Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -213,20 +94,21 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_create_a_sentinel_when_restore_fails()
|
||||
public void It_does_not_create_a_sentinel_when_extracting_the_archive_fails()
|
||||
{
|
||||
var nugetCacheSentinel = new Mock<INuGetCacheSentinel>();
|
||||
_dotnetRestoreCommandMock.Setup(c => c.Execute()).Returns(new CommandResult(null, -1, null, null));
|
||||
var nugetPackagesArchiveMock = new Mock<INuGetPackagesArchiver>();
|
||||
nugetPackagesArchiveMock.Setup(n => n.ExtractArchive(It.IsAny<string>())).Throws<Exception>();
|
||||
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
_commandFactoryMock.Object,
|
||||
_nugetPackagesArchiverMock.Object,
|
||||
nugetPackagesArchiveMock.Object,
|
||||
nugetCacheSentinel.Object,
|
||||
_fileSystemMock.Directory,
|
||||
_nugetConfigMock.Object,
|
||||
_fileSystemMock.File);
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
Action action = () => nugetCachePrimer.PrimeCache();
|
||||
|
||||
action.ShouldThrow<Exception>();
|
||||
nugetCacheSentinel.Verify(n => n.CreateIfNotExists(), Times.Never);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// 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 System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NuGet.Configuration;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Configurer.UnitTests
|
||||
{
|
||||
public class GivenANuGetConfig
|
||||
{
|
||||
private const string PathToFallbackFolderAlreadySet = "some path to fallback folder";
|
||||
|
||||
private Mock<ISettings> _settingsMock;
|
||||
private INuGetConfig _nugetConfig;
|
||||
|
||||
public GivenANuGetConfig()
|
||||
{
|
||||
_settingsMock = new Mock<ISettings>();
|
||||
_settingsMock
|
||||
.Setup(s => s.GetSettingValues(NuGetConfig.FallbackPackageFolders, false))
|
||||
.Returns(new List<SettingValue>()
|
||||
{
|
||||
new SettingValue("CLIFallbackFolder", PathToFallbackFolderAlreadySet, false)
|
||||
});
|
||||
|
||||
_nugetConfig = new NuGetConfig(_settingsMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItAddsACliFallbackFolderIfOneIsNotPresentAlready()
|
||||
{
|
||||
const string FallbackFolderNotAlreadySet = "some path not already set";
|
||||
_nugetConfig.AddCLIFallbackFolder(FallbackFolderNotAlreadySet);
|
||||
|
||||
_settingsMock.Verify(s =>
|
||||
s.SetValue(NuGetConfig.FallbackPackageFolders, "CLIFallbackFolder", FallbackFolderNotAlreadySet),
|
||||
Times.Exactly(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItDoesNotAddTheCliFallbackFolderIfItIsAlreadyPresent()
|
||||
{
|
||||
_nugetConfig.AddCLIFallbackFolder(PathToFallbackFolderAlreadySet);
|
||||
|
||||
_settingsMock.Verify(s =>
|
||||
s.SetValue(NuGetConfig.FallbackPackageFolders, "CLIFallbackFolder", PathToFallbackFolderAlreadySet),
|
||||
Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
<SignAssembly>true</SignAssembly>
|
||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
|
||||
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -18,7 +19,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="4.18.0" />
|
||||
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
|
||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
|
||||
|
|
Loading…
Reference in a new issue