Adding more tests for the min version check in the resolver.
This commit is contained in:
parent
f61d1ffbb0
commit
a4213f78e0
3 changed files with 62 additions and 9 deletions
|
@ -53,7 +53,8 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
|||
netcoreSdkVersion = new DirectoryInfo(netcoreSdkDir).Name;;
|
||||
}
|
||||
|
||||
if (SemanticVersion.Parse(netcoreSdkVersion) < SemanticVersion.Parse(sdkReference.MinimumVersion))
|
||||
if (!string.IsNullOrEmpty(sdkReference.MinimumVersion) &&
|
||||
SemanticVersion.Parse(netcoreSdkVersion) < SemanticVersion.Parse(sdkReference.MinimumVersion))
|
||||
{
|
||||
return factory.IndicateFailure(
|
||||
new[]
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// 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.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.DotNet.MSBuildSdkResolver.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
|
@ -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 and/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,
|
||||
|
|
Loading…
Reference in a new issue