Merge pull request #6646 from livarcocc/min_version_resolver

Add a min version check to the resolver
This commit is contained in:
Livar 2017-05-23 22:17:42 -07:00 committed by GitHub
commit 96ff9a3223
7 changed files with 372 additions and 4 deletions

View file

@ -47,13 +47,72 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
new MockContext { ProjectFilePath = environment.TestDirectory.FullName },
new MockFactory());
result.Success.Should().Be(true);
result.Success.Should().BeTrue();
result.Path.Should().Be(expected.FullName);
result.Version.Should().Be("99.99.98");
result.Warnings.Should().BeNullOrEmpty();
result.Errors.Should().BeNullOrEmpty();
}
[Fact]
public void ItReturnsNullIfTheVersionFoundDoesNotSatisfyTheMinVersion()
{
var environment = new TestEnvironment();
environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "99.99.99");
var resolver = environment.CreateResolver();
var result = (MockResult)resolver.Resolve(
new SdkReference("Some.Test.Sdk", null, "999.99.99"),
new MockContext { ProjectFilePath = environment.TestDirectory.FullName },
new MockFactory());
result.Success.Should().BeFalse();
result.Path.Should().BeNull();
result.Version.Should().BeNull();
result.Warnings.Should().BeNullOrEmpty();
result.Errors.Should().Contain("Version 99.99.99 of the SDK is smaller than the minimum version 999.99.99"
+ " requested. Check that a recent enough .NET Core SDK is installed, increase the minimum version"
+ " specified in the project, or increase the version specified in global.json.");
}
[Fact]
public void ItReturnsTheVersionIfItIsEqualToTheMinVersion()
{
var environment = new TestEnvironment();
var expected = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "99.99.99");
var resolver = environment.CreateResolver();
var result = (MockResult)resolver.Resolve(
new SdkReference("Some.Test.Sdk", null, "99.99.99"),
new MockContext { ProjectFilePath = environment.TestDirectory.FullName },
new MockFactory());
result.Success.Should().BeTrue();
result.Path.Should().Be(expected.FullName);
result.Version.Should().Be("99.99.99");
result.Warnings.Should().BeNullOrEmpty();
result.Errors.Should().BeNullOrEmpty();
}
[Fact]
public void ItReturnsTheVersionIfItIsHigherThanTheMinVersion()
{
var environment = new TestEnvironment();
var expected = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "999.99.99");
var resolver = environment.CreateResolver();
var result = (MockResult)resolver.Resolve(
new SdkReference("Some.Test.Sdk", null, "99.99.99"),
new MockContext { ProjectFilePath = environment.TestDirectory.FullName },
new MockFactory());
result.Success.Should().BeTrue();
result.Path.Should().Be(expected.FullName);
result.Version.Should().Be("999.99.99");
result.Warnings.Should().BeNullOrEmpty();
result.Errors.Should().BeNullOrEmpty();
}
private enum ProgramFiles
{
X64,

View file

@ -0,0 +1,35 @@
// 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 Xunit;
using Microsoft.DotNet.MSBuildSdkResolver;
using FluentAssertions;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
public class GivenThatWeWantToCompareFXVersions
{
[Theory]
[InlineData("2.0.0", "1.0.0", 1)]
[InlineData("1.1.0", "1.0.0", 1)]
[InlineData("1.0.1", "1.0.0", 1)]
[InlineData("1.0.0", "1.0.0-pre", 1)]
[InlineData("1.0.0-pre+2", "1.0.0-pre+1", 1)]
[InlineData("1.0.0", "2.0.0", -1)]
[InlineData("1.0.0", "1.1.0", -1)]
[InlineData("1.0.0", "1.0.1", -1)]
[InlineData("1.0.0-pre", "1.0.0", -1)]
[InlineData("1.0.0-pre+1", "1.0.0-pre+2", -1)]
[InlineData("1.2.3", "1.2.3", 0)]
[InlineData("1.2.3-pre", "1.2.3-pre", 0)]
[InlineData("1.2.3-pre+1", "1.2.3-pre+1", 0)]
public void OneFXVersionIsBiggerThanTheOther(string s1, string s2, int expectedResult)
{
FXVersion fxVersion1;
FXVersion fxVersion2;
FXVersion.TryParse(s1, out fxVersion1);
FXVersion.TryParse(s2, out fxVersion2);
FXVersion.Compare(fxVersion1, fxVersion2).Should().Be(expectedResult);
}
}
}

View file

@ -0,0 +1,89 @@
// 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 Xunit;
using Microsoft.DotNet.MSBuildSdkResolver;
using FluentAssertions;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
public class GivenThatWeWantToParseFXVersions
{
[Fact]
public void ReturnsNullWhenNoMajorSeparatorIsFound()
{
FXVersion fxVersion;
FXVersion.TryParse("1", out fxVersion).Should().BeFalse();
}
[Fact]
public void ReturnsNullWhenMajorPortionIsNotANumber()
{
FXVersion fxVersion;
FXVersion.TryParse("a.0.0", out fxVersion).Should().BeFalse();
}
[Fact]
public void ReturnsNullWhenNoMinorSeparatorIsFound()
{
FXVersion fxVersion;
FXVersion.TryParse("1.0", out fxVersion).Should().BeFalse();
}
[Fact]
public void ReturnsNullWhenMinorPortionIsNotANumber()
{
FXVersion fxVersion;
FXVersion.TryParse("1.a.0", out fxVersion).Should().BeFalse();
}
[Fact]
public void ReturnsNullWhenPatchPortionIsNotANumber()
{
FXVersion fxVersion;
FXVersion.TryParse("1.0.a", out fxVersion).Should().BeFalse();
}
[Fact]
public void ReturnsFXVersionWhenOnlyMajorMinorPatchIsFound()
{
FXVersion fxVersion;
var result = FXVersion.TryParse("1.2.3", out fxVersion);
result.Should().BeTrue();
fxVersion.Major.Should().Be(1);
fxVersion.Minor.Should().Be(2);
fxVersion.Patch.Should().Be(3);
}
[Fact]
public void ReturnsFXVersionWhenOnlyMajorMinorPatchAndPreIsFound()
{
FXVersion fxVersion;
var result = FXVersion.TryParse("1.2.3-pre", out fxVersion);
result.Should().BeTrue();
fxVersion.Major.Should().Be(1);
fxVersion.Minor.Should().Be(2);
fxVersion.Patch.Should().Be(3);
fxVersion.Pre.Should().Be("-pre");
}
[Fact]
public void ReturnsFXVersionWhenMajorMinorPatchAndPreAndBuildIsFound()
{
FXVersion fxVersion;
var result = FXVersion.TryParse("1.2.3-pre+build", out fxVersion);
result.Should().BeTrue();
fxVersion.Major.Should().Be(1);
fxVersion.Minor.Should().Be(2);
fxVersion.Patch.Should().Be(3);
fxVersion.Pre.Should().Be("-pre");
fxVersion.Build.Should().Be("build");
}
}
}

View file

@ -2,8 +2,8 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<TargetFrameworks>net461;$(CliTargetFramework)</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">$(CliTargetFramework)</TargetFrameworks>
<!-- https://github.com/dotnet/cli/issues/6672: Re-enable net461 as a TFM for tests. -->
<TargetFrameworks>$(CliTargetFramework)</TargetFrameworks>
<RuntimeFrameworkVersion>$(CLI_SharedFrameworkVersion)</RuntimeFrameworkVersion>
<OutputType>Exe</OutputType>
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
@ -29,6 +29,10 @@
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>