commit
9f2bb66198
60 changed files with 5816 additions and 17 deletions
|
@ -0,0 +1,94 @@
|
|||
// 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 FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Configurer;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.DependencyModel.Tests;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Configurer.UnitTests
|
||||
{
|
||||
public class GivenADotnetFirstTimeUseConfigurer
|
||||
{
|
||||
private Mock<INuGetCachePrimer> _nugetCachePrimerMock;
|
||||
private Mock<INuGetCacheSentinel> _nugetCacheSentinelMock;
|
||||
private Mock<IEnvironmentProvider> _environmentProviderMock;
|
||||
|
||||
public GivenADotnetFirstTimeUseConfigurer()
|
||||
{
|
||||
_nugetCachePrimerMock = new Mock<INuGetCachePrimer>();
|
||||
_nugetCacheSentinelMock = new Mock<INuGetCacheSentinel>();
|
||||
_environmentProviderMock = new Mock<IEnvironmentProvider>();
|
||||
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_prime_the_cache_if_the_sentinel_exists()
|
||||
{
|
||||
_nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(true);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_prime_the_cache_if_first_run_experience_is_already_happening()
|
||||
{
|
||||
_nugetCacheSentinelMock.Setup(n => n.InProgressSentinelAlreadyExists()).Returns(true);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_prime_the_cache_if_the_sentinel_exists_but_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environemnt_variable()
|
||||
{
|
||||
_nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false))
|
||||
.Returns(true);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_primes_the_cache_if_the_sentinel_does_not_exist()
|
||||
{
|
||||
_nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
// 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 System.Linq;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities.Mock;
|
||||
using Microsoft.Extensions.DependencyModel.Tests;
|
||||
using Microsoft.Extensions.EnvironmentAbstractions;
|
||||
using Moq;
|
||||
using NuGet.Frameworks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Configurer.UnitTests
|
||||
{
|
||||
public class GivenANuGetCachePrimer
|
||||
{
|
||||
private const string COMPRESSED_ARCHIVE_PATH = "a path to somewhere";
|
||||
private const string TEMPORARY_FOLDER_PATH = "some path";
|
||||
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;
|
||||
|
||||
public GivenANuGetCachePrimer()
|
||||
{
|
||||
var fileSystemMockBuilder = FileSystemMockBuilder.Create();
|
||||
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>();
|
||||
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
_commandFactoryMock.Object,
|
||||
_nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
_fileSystemMock.Directory,
|
||||
_fileSystemMock.File);
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
}
|
||||
|
||||
private Mock<ICommandFactory> SetupCommandFactoryMock()
|
||||
{
|
||||
var commandFactoryMock = new Mock<ICommandFactory>();
|
||||
|
||||
_dotnetNewCommandMock = new Mock<ICommand>();
|
||||
SetupCommandMock(_dotnetNewCommandMock);
|
||||
commandFactoryMock
|
||||
.Setup(c => c.Create("new", Enumerable.Empty<string>(), 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,
|
||||
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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_disposes_the_temporary_directory_created_for_the_temporary_project_used_to_prime_the_cache()
|
||||
{
|
||||
_temporaryDirectoryMock.DisposedTemporaryDirectory.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_new_using_the_temporary_folder()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.WorkingDirectory(TEMPORARY_FOLDER_PATH), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_new_capturing_stdout()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.CaptureStdOut(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_new_capturing_stderr()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.CaptureStdErr(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_actually_runs_dotnet_new()
|
||||
{
|
||||
_dotnetNewCommandMock.Verify(c => c.Execute(), Times.Once);
|
||||
}
|
||||
|
||||
[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.Once);
|
||||
}
|
||||
|
||||
[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.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_restore_capturing_stdout()
|
||||
{
|
||||
_dotnetRestoreCommandMock.Verify(c => c.CaptureStdOut(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_dotnet_restore_capturing_stderr()
|
||||
{
|
||||
_dotnetRestoreCommandMock.Verify(c => c.CaptureStdErr(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_actually_runs_dotnet_restore()
|
||||
{
|
||||
_dotnetRestoreCommandMock.Verify(c => c.Execute(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_creates_a_sentinel_when_restore_succeeds()
|
||||
{
|
||||
_nugetCacheSentinel.Verify(n => n.CreateIfNotExists(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_create_a_sentinel_when_restore_fails()
|
||||
{
|
||||
var nugetCacheSentinel = new Mock<INuGetCacheSentinel>();
|
||||
_dotnetRestoreCommandMock.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();
|
||||
|
||||
nugetCacheSentinel.Verify(n => n.CreateIfNotExists(), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
// 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 FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Configurer;
|
||||
using Microsoft.Extensions.DependencyModel.Tests;
|
||||
using Microsoft.Extensions.EnvironmentAbstractions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Configurer.UnitTests
|
||||
{
|
||||
public class GivenANuGetCacheSentinel
|
||||
{
|
||||
private const string NUGET_CACHE_PATH = "some path";
|
||||
|
||||
private FileSystemMockBuilder _fileSystemMockBuilder;
|
||||
|
||||
public GivenANuGetCacheSentinel()
|
||||
{
|
||||
_fileSystemMockBuilder = FileSystemMockBuilder.Create();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void As_soon_as_it_gets_created_it_tries_to_get_handle_of_the_InProgress_sentinel()
|
||||
{
|
||||
var fileMock = new FileMock();
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
|
||||
|
||||
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()
|
||||
{
|
||||
var fileMock = new FileMock();
|
||||
fileMock.InProgressSentinel = null;
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
|
||||
|
||||
nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_false_to_the_in_progress_sentinel_already_exists_when_it_succeeds_in_getting_a_handle_to_it()
|
||||
{
|
||||
var fileMock = new FileMock();
|
||||
fileMock.InProgressSentinel = new MemoryStream();
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
|
||||
|
||||
nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_disposes_of_the_handle_to_the_InProgressSentinel_when_NuGetCacheSentinel_is_disposed()
|
||||
{
|
||||
var mockStream = new MockStream();
|
||||
var fileMock = new FileMock();
|
||||
fileMock.InProgressSentinel = mockStream;
|
||||
using (var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock))
|
||||
{}
|
||||
|
||||
mockStream.IsDisposed.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_sentinel_has_the_current_version_in_its_name()
|
||||
{
|
||||
NuGetCacheSentinel.SENTINEL.Should().Contain($"{Product.Version}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_true_if_the_sentinel_exists()
|
||||
{
|
||||
_fileSystemMockBuilder.AddFiles(NUGET_CACHE_PATH, NuGetCacheSentinel.SENTINEL);
|
||||
|
||||
var fileSystemMock = _fileSystemMockBuilder.Build();
|
||||
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
|
||||
|
||||
nugetCacheSentinel.Exists().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_false_if_the_sentinel_does_not_exist()
|
||||
{
|
||||
var fileSystemMock = _fileSystemMockBuilder.Build();
|
||||
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
|
||||
|
||||
nugetCacheSentinel.Exists().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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);
|
||||
|
||||
nugetCacheSentinel.Exists().Should().BeFalse();
|
||||
|
||||
nugetCacheSentinel.CreateIfNotExists();
|
||||
|
||||
nugetCacheSentinel.Exists().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_create_the_sentinel_again_if_it_already_exists_in_the_nuget_cache_path()
|
||||
{
|
||||
const string contentToValidateSentinalWasNotReplaced = "some string";
|
||||
var sentinel = Path.Combine(NUGET_CACHE_PATH, NuGetCacheSentinel.SENTINEL);
|
||||
_fileSystemMockBuilder.AddFile(sentinel, contentToValidateSentinalWasNotReplaced);
|
||||
|
||||
var fileSystemMock = _fileSystemMockBuilder.Build();
|
||||
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
|
||||
|
||||
nugetCacheSentinel.Exists().Should().BeTrue();
|
||||
|
||||
nugetCacheSentinel.CreateIfNotExists();
|
||||
|
||||
fileSystemMock.File.ReadAllText(sentinel).Should().Be(contentToValidateSentinalWasNotReplaced);
|
||||
}
|
||||
|
||||
private class FileMock : IFile
|
||||
{
|
||||
public bool OpenFileWithRightParamsCalled { get; private set; }
|
||||
|
||||
public Stream InProgressSentinel { get; set;}
|
||||
|
||||
public bool Exists(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string ReadAllText(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Stream OpenRead(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Stream OpenFile(
|
||||
string path,
|
||||
FileMode fileMode,
|
||||
FileAccess fileAccess,
|
||||
FileShare fileShare,
|
||||
int bufferSize,
|
||||
FileOptions fileOptions)
|
||||
{
|
||||
Stream fileStream = null;
|
||||
|
||||
var inProgressSentinel =
|
||||
Path.Combine(GivenANuGetCacheSentinel.NUGET_CACHE_PATH, NuGetCacheSentinel.INPROGRESS_SENTINEL);
|
||||
|
||||
if (path.Equals(inProgressSentinel) &&
|
||||
fileMode == FileMode.OpenOrCreate &&
|
||||
fileAccess == FileAccess.ReadWrite &&
|
||||
fileShare == FileShare.None &&
|
||||
bufferSize == 1 &&
|
||||
fileOptions == FileOptions.DeleteOnClose)
|
||||
{
|
||||
OpenFileWithRightParamsCalled = true;
|
||||
fileStream = InProgressSentinel;
|
||||
}
|
||||
|
||||
return fileStream;
|
||||
}
|
||||
|
||||
public void CreateEmptyFile(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
private class MockStream : MemoryStream
|
||||
{
|
||||
public bool IsDisposed { get; private set;}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>4c3b06d5-b6d5-4e5b-a44f-3ebe52a1c759</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Configurer.UnitTests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
35
test/Microsoft.DotNet.Configurer.UnitTests/project.json
Normal file
35
test/Microsoft.DotNet.Configurer.UnitTests/project.json
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-rc3-004442-00"
|
||||
},
|
||||
"System.Diagnostics.TraceSource": "4.0.0-rc3-24131-00",
|
||||
"Microsoft.DotNet.Configurer": {
|
||||
"target": "project"
|
||||
},
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": {
|
||||
"target": "project"
|
||||
},
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project"
|
||||
},
|
||||
"FluentAssertions": "4.0.0",
|
||||
"moq.netcore": "4.4.0-beta8",
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-192208-24"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"testRunner": "xunit"
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
// 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.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities.Mock;
|
||||
using Microsoft.Extensions.EnvironmentAbstractions;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyModel.Tests
|
||||
|
@ -13,6 +15,8 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
{
|
||||
private Dictionary<string, string> _files = new Dictionary<string, string>();
|
||||
|
||||
public string TemporaryFolder { get; set; }
|
||||
|
||||
internal static IFileSystem Empty { get; } = Create().Build();
|
||||
|
||||
public static FileSystemMockBuilder Create()
|
||||
|
@ -37,15 +41,15 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
|
||||
internal IFileSystem Build()
|
||||
{
|
||||
return new FileSystemMock(_files);
|
||||
return new FileSystemMock(_files, TemporaryFolder);
|
||||
}
|
||||
|
||||
private class FileSystemMock : IFileSystem
|
||||
{
|
||||
public FileSystemMock(Dictionary<string, string> files)
|
||||
public FileSystemMock(Dictionary<string, string> files, string temporaryFolder)
|
||||
{
|
||||
File = new FileMock(files);
|
||||
Directory = new DirectoryMock(files);
|
||||
Directory = new DirectoryMock(files, temporaryFolder);
|
||||
}
|
||||
|
||||
public IFile File { get; }
|
||||
|
@ -80,14 +84,38 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
{
|
||||
return new MemoryStream(Encoding.UTF8.GetBytes(ReadAllText(path)));
|
||||
}
|
||||
|
||||
public Stream OpenFile(
|
||||
string path,
|
||||
FileMode fileMode,
|
||||
FileAccess fileAccess,
|
||||
FileShare fileShare,
|
||||
int bufferSize,
|
||||
FileOptions fileOptions)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CreateEmptyFile(string path)
|
||||
{
|
||||
_files.Add(path, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private class DirectoryMock : IDirectory
|
||||
{
|
||||
private Dictionary<string, string> _files;
|
||||
public DirectoryMock(Dictionary<string, string> files)
|
||||
private readonly TemporaryDirectoryMock _temporaryDirectory;
|
||||
|
||||
public DirectoryMock(Dictionary<string, string> files, string temporaryDirectory)
|
||||
{
|
||||
_files = files;
|
||||
_temporaryDirectory = new TemporaryDirectoryMock(temporaryDirectory);
|
||||
}
|
||||
|
||||
public ITemporaryDirectory CreateTemporaryDirectory()
|
||||
{
|
||||
return _temporaryDirectory;
|
||||
}
|
||||
|
||||
public bool Exists(string path)
|
||||
|
@ -95,6 +123,23 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
return _files.Keys.Any(k => k.StartsWith(path));
|
||||
}
|
||||
}
|
||||
|
||||
private class TemporaryDirectoryMock : ITemporaryDirectoryMock
|
||||
{
|
||||
public bool DisposedTemporaryDirectory { get; private set; }
|
||||
|
||||
public TemporaryDirectoryMock(string temporaryDirectory)
|
||||
{
|
||||
DirectoryPath = temporaryDirectory;
|
||||
}
|
||||
|
||||
public string DirectoryPath { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisposedTemporaryDirectory = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// 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.Extensions.EnvironmentAbstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities.Mock
|
||||
{
|
||||
internal interface ITemporaryDirectoryMock : ITemporaryDirectory
|
||||
{
|
||||
bool DisposedTemporaryDirectory { get; }
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.Extensions.DependencyModel.Tests , PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.Extensions.DependencyModel.Tests , PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.DotNet.Configurer.UnitTests , PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
|
@ -142,15 +142,17 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
|
||||
[Fact]
|
||||
public void CrossPublishingSucceedsAndHasExpectedArtifacts()
|
||||
{
|
||||
var testNugetCache = "packages_cross_publish_test";
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("PortableTests"));
|
||||
|
||||
|
||||
var testProject = Path.Combine(instance.TestRoot, "StandaloneApp", "project.json");
|
||||
var workingDirectory = Path.GetDirectoryName(testProject);
|
||||
var testNugetCache = Path.Combine(workingDirectory, "packages_cross_publish_test");
|
||||
|
||||
var restoreCommand = new RestoreCommand();
|
||||
|
||||
restoreCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
|
||||
restoreCommand.WorkingDirectory = workingDirectory;
|
||||
|
||||
restoreCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
|
||||
restoreCommand.Execute().Should().Pass();
|
||||
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
// 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.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;
|
||||
|
||||
namespace Microsoft.DotNet.Tests
|
||||
{
|
||||
public class GivenThatTheUserIsRunningDotNetForTheFirstTime : TestBase
|
||||
{
|
||||
private static CommandResult _firstDotnetUseCommandResult;
|
||||
private static DirectoryInfo _nugetCacheFolder;
|
||||
|
||||
static GivenThatTheUserIsRunningDotNetForTheFirstTime()
|
||||
{
|
||||
var testDirectory = TestAssetsManager.CreateTestDirectory("Dotnet_first_time_experience_tests");
|
||||
var testNugetCache = Path.Combine(testDirectory.Path, "nuget_cache");
|
||||
|
||||
var command = new DotnetCommand()
|
||||
.WithWorkingDirectory(testDirectory.Path);
|
||||
command.Environment["NUGET_PACKAGES"] = testNugetCache;
|
||||
|
||||
_firstDotnetUseCommandResult = command.ExecuteWithCapturedOutput("new");
|
||||
|
||||
_nugetCacheFolder = new DirectoryInfo(testNugetCache);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Using_dotnet_for_the_first_time_succeeds()
|
||||
{
|
||||
_firstDotnetUseCommandResult.Should().Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_shows_the_appropriate_message_to_the_user()
|
||||
{
|
||||
const string firstTimeUseWelcomeMessage = @"Welcome to .NET Core!
|
||||
---------------------
|
||||
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
|
||||
Telemetry
|
||||
--------------
|
||||
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
|
||||
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
|
||||
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
|
||||
Configuring...
|
||||
-------------------
|
||||
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.";
|
||||
|
||||
_firstDotnetUseCommandResult.StdOut.Should().StartWith(firstTimeUseWelcomeMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_restores_the_nuget_packages_to_the_nuget_cache_folder()
|
||||
{
|
||||
_nugetCacheFolder.Should().HaveFile($"{GetDotnetVersion()}.dotnetSentinel");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_creates_a_sentinel_file_under_the_nuget_cache_folder()
|
||||
{
|
||||
_nugetCacheFolder.Should().HaveDirectory("Microsoft.NETCore.App");
|
||||
}
|
||||
|
||||
private string GetDotnetVersion()
|
||||
{
|
||||
return new DotnetCommand().ExecuteWithCapturedOutput("--version").StdOut
|
||||
.TrimEnd(Environment.NewLine.ToCharArray());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue