Moving the expanding fallback folder to the dotnet folder hive. The folder will be expanded at sdk/NuGetFallbackFolder.

This commit is contained in:
Livar Cunha 2017-05-31 13:44:03 -07:00
parent 58e18a61b7
commit 529d7caa79
17 changed files with 171 additions and 48 deletions

View file

@ -13,6 +13,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
{
public class GivenADotnetFirstTimeUseConfigurer
{
private const string CliFallbackFolderPath = "some path";
private Mock<INuGetCachePrimer> _nugetCachePrimerMock;
private Mock<INuGetCacheSentinel> _nugetCacheSentinelMock;
private Mock<IFirstTimeUseNoticeSentinel> _firstTimeUseNoticeSentinelMock;
@ -45,7 +47,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -66,7 +69,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -87,7 +91,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -105,7 +110,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -123,7 +129,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -140,7 +147,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -157,7 +165,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -177,7 +186,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -194,7 +204,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -212,7 +223,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();

View file

@ -2,12 +2,14 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.Extensions.DependencyModel.Tests;
using Microsoft.Extensions.EnvironmentAbstractions;
using Moq;
using Xunit;
namespace Microsoft.DotNet.Configurer.UnitTests
@ -26,18 +28,44 @@ namespace Microsoft.DotNet.Configurer.UnitTests
[Fact]
public void As_soon_as_it_gets_created_it_tries_to_get_handle_of_the_InProgress_sentinel()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
fileMock.OpenFileWithRightParamsCalled.Should().BeTrue();
}
[Fact]
public void It_returns_true_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it()
public void It_sets_UnauthorizedAccess_to_false_when_no_UnauthorizedAccessException_happens()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
nugetCacheSentinel.UnauthorizedAccess.Should().BeFalse();
}
[Fact]
public void It_sets_UnauthorizedAccess_to_true_when_an_UnauthorizedAccessException_happens()
{
var fileMock = new FileMock();
var directoryMock = new DirectoryMock();
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, directoryMock);
nugetCacheSentinel.UnauthorizedAccess.Should().BeTrue();
}
[Fact]
public void It_returns_true_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
fileMock.InProgressSentinel = null;
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeTrue();
}
@ -45,9 +73,11 @@ namespace Microsoft.DotNet.Configurer.UnitTests
[Fact]
public void It_returns_false_to_the_in_progress_sentinel_already_exists_when_it_succeeds_in_getting_a_handle_to_it()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
fileMock.InProgressSentinel = new MemoryStream();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeFalse();
}
@ -55,10 +85,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests
[Fact]
public void It_disposes_of_the_handle_to_the_InProgressSentinel_when_NuGetCacheSentinel_is_disposed()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var mockStream = new MockStream();
var fileMock = new FileMock();
fileMock.InProgressSentinel = mockStream;
using (var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock))
using (var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory))
{}
mockStream.IsDisposed.Should().BeTrue();
@ -77,7 +109,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeTrue();
}
@ -87,7 +120,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeFalse();
}
@ -96,7 +130,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
public void It_creates_the_sentinel_in_the_nuget_cache_path_if_it_does_not_exist_already()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeFalse();
@ -114,7 +149,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeTrue();
@ -123,6 +159,34 @@ namespace Microsoft.DotNet.Configurer.UnitTests
fileSystemMock.File.ReadAllText(sentinel).Should().Be(contentToValidateSentinalWasNotReplaced);
}
private class DirectoryMock : IDirectory
{
public bool Exists(string path)
{
return false;
}
public ITemporaryDirectory CreateTemporaryDirectory()
{
throw new NotImplementedException();
}
public IEnumerable<string> GetFiles(string path, string searchPattern)
{
throw new NotImplementedException();
}
public string GetDirectoryFullName(string path)
{
throw new NotImplementedException();
}
public void CreateDirectory(string path)
{
throw new UnauthorizedAccessException();
}
}
private class FileMock : IFile
{
public bool OpenFileWithRightParamsCalled { get; private set; }

View file

@ -138,6 +138,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests
{
return _files.Keys.Any(k => k.StartsWith(path));
}
public void CreateDirectory(string path)
{
_files.Add(path, path);
}
}
private class TemporaryDirectoryMock : ITemporaryDirectoryMock

View file

@ -190,10 +190,13 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
{
private readonly Func<bool> _exists;
public bool UnauthorizedAccess => true;
public MockNuGetCacheSentinel(Func<bool> exists = null)
{
_exists = exists ?? (() => true);
}
public void Dispose()
{
}

View file

@ -25,19 +25,21 @@ namespace Microsoft.DotNet.Tests
{
var testDirectory = TestAssets.CreateTestDirectory("Dotnet_first_time_experience_tests");
var testNuGetHome = Path.Combine(testDirectory.FullName, "nuget_home");
var cliTestFallbackFolder = Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder");
var command = new DotnetCommand()
.WithWorkingDirectory(testDirectory);
command.Environment["HOME"] = testNuGetHome;
command.Environment["USERPROFILE"] = testNuGetHome;
command.Environment["APPDATA"] = testNuGetHome;
command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = cliTestFallbackFolder;
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
command.Environment["SkipInvalidConfigurations"] = "true";
_firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
_firstDotnetVerbUseCommandResult = command.ExecuteWithCapturedOutput("new --debug:ephemeral-hive");
_nugetFallbackFolder = new DirectoryInfo(Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder"));
_nugetFallbackFolder = new DirectoryInfo(cliTestFallbackFolder);
}
[Fact]