2016-06-06 17:39:05 +00:00
|
|
|
|
// 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.
|
|
|
|
|
|
2016-06-06 19:51:27 +00:00
|
|
|
|
using System.IO;
|
2016-06-06 17:39:05 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using Microsoft.DotNet.Configurer;
|
|
|
|
|
using Microsoft.Extensions.DependencyModel.Tests;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Configurer.UnitTests
|
|
|
|
|
{
|
|
|
|
|
public class GivenANuGetCacheSentinel
|
|
|
|
|
{
|
2016-06-06 19:51:27 +00:00
|
|
|
|
private FileSystemMockBuilder _fileSystemMockBuilder;
|
|
|
|
|
|
|
|
|
|
public GivenANuGetCacheSentinel()
|
|
|
|
|
{
|
|
|
|
|
_fileSystemMockBuilder = FileSystemMockBuilder.Create();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 17:39:05 +00:00
|
|
|
|
private const string NUGET_CACHE_PATH = "some path";
|
|
|
|
|
|
|
|
|
|
[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()
|
|
|
|
|
{
|
2016-06-06 19:51:27 +00:00
|
|
|
|
_fileSystemMockBuilder.AddFiles(NUGET_CACHE_PATH, NuGetCacheSentinel.SENTINEL);
|
2016-06-06 17:39:05 +00:00
|
|
|
|
|
2016-06-06 19:51:27 +00:00
|
|
|
|
var fileSystemMock = _fileSystemMockBuilder.Build();
|
2016-06-06 17:39:05 +00:00
|
|
|
|
|
2016-06-06 19:51:27 +00:00
|
|
|
|
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
|
2016-06-06 17:39:05 +00:00
|
|
|
|
|
|
|
|
|
nugetCacheSentinel.Exists().Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void It_returns_false_if_the_sentinel_does_not_exist()
|
|
|
|
|
{
|
2016-06-06 19:51:27 +00:00
|
|
|
|
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();
|
2016-06-06 17:39:05 +00:00
|
|
|
|
|
2016-06-06 19:51:27 +00:00
|
|
|
|
nugetCacheSentinel.CreateIfNotExists();
|
2016-06-06 17:39:05 +00:00
|
|
|
|
|
|
|
|
|
nugetCacheSentinel.Exists().Should().BeTrue();
|
|
|
|
|
}
|
2016-06-06 19:51:27 +00:00
|
|
|
|
|
|
|
|
|
[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);
|
|
|
|
|
}
|
2016-06-06 17:39:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|