|
| 1 | +// Copyright (c) .NET Foundation and contributors. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using FluentAssertions; |
| 6 | +using Microsoft.DotNet.Tools.Test.Utilities; |
| 7 | +using Microsoft.Extensions.DependencyModel; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.DotNet.Cli.Utils.Tests |
| 11 | +{ |
| 12 | + public class GivenAFrameworkDependencyFile |
| 13 | + { |
| 14 | + private readonly IReadOnlyList<RuntimeFallbacks> _testRuntimeGraph; |
| 15 | + |
| 16 | + public GivenAFrameworkDependencyFile() |
| 17 | + { |
| 18 | + _testRuntimeGraph = new List<RuntimeFallbacks> |
| 19 | + { |
| 20 | + new RuntimeFallbacks("win-x64", new [] { "win", "any", "base" }), |
| 21 | + new RuntimeFallbacks("win8", new [] { "win7", "win", "any", "base" }), |
| 22 | + new RuntimeFallbacks("win7", new [] { "win", "any", "base" }), |
| 23 | + new RuntimeFallbacks("win", new [] { "any", "base" }), |
| 24 | + }; |
| 25 | + } |
| 26 | + |
| 27 | + [Fact] |
| 28 | + public void WhenPassSeveralCompatibleRuntimeIdentifiersItOutMostFitRid() |
| 29 | + { |
| 30 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 31 | + currentRuntimeIdentifier: "win7", |
| 32 | + alternativeCurrentRuntimeIdentifier : "win", |
| 33 | + runtimeGraph : _testRuntimeGraph, |
| 34 | + candidateRuntimeIdentifiers : new [] { "win", "any" }, |
| 35 | + mostFitRuntimeIdentifier : out string mostFitRid) |
| 36 | + .Should().BeTrue(); |
| 37 | + |
| 38 | + mostFitRid.Should().Be("win"); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void WhenPassSeveralCompatibleRuntimeIdentifiersItOutMostFitRid2() |
| 43 | + { |
| 44 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 45 | + currentRuntimeIdentifier: "win", |
| 46 | + alternativeCurrentRuntimeIdentifier: null, |
| 47 | + runtimeGraph: _testRuntimeGraph, |
| 48 | + candidateRuntimeIdentifiers: new[] { "win", "any" }, |
| 49 | + mostFitRuntimeIdentifier: out string mostFitRid) |
| 50 | + .Should().BeTrue(); |
| 51 | + |
| 52 | + mostFitRid.Should().Be("win"); |
| 53 | + } |
| 54 | + |
| 55 | + [Fact] |
| 56 | + public void WhenPassSeveralCompatibleRuntimeIdentifiersAndCurrentRuntimeIdentifierIsNullReturnsFalse() |
| 57 | + { |
| 58 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 59 | + currentRuntimeIdentifier: null, |
| 60 | + alternativeCurrentRuntimeIdentifier: null, |
| 61 | + runtimeGraph: _testRuntimeGraph, |
| 62 | + candidateRuntimeIdentifiers: new[] { "win", "any" }, |
| 63 | + mostFitRuntimeIdentifier: out string mostFitRid) |
| 64 | + .Should().BeFalse(); |
| 65 | + } |
| 66 | + |
| 67 | + [Fact] |
| 68 | + public void WhenPassSeveralCompatibleRuntimeIdentifiersItOutMostFitRidWithCasingPreserved() |
| 69 | + { |
| 70 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 71 | + currentRuntimeIdentifier: "win7", |
| 72 | + alternativeCurrentRuntimeIdentifier : null, |
| 73 | + runtimeGraph : _testRuntimeGraph, |
| 74 | + candidateRuntimeIdentifiers : new [] { "Win", "any" }, |
| 75 | + mostFitRuntimeIdentifier : out string mostFitRid) |
| 76 | + .Should().BeTrue(); |
| 77 | + |
| 78 | + mostFitRid.Should().Be("Win"); |
| 79 | + } |
| 80 | + |
| 81 | + [Fact] |
| 82 | + public void WhenPassSeveralCompatibleRuntimeIdentifiersWithDuplicationItOutMostFitRid() |
| 83 | + { |
| 84 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 85 | + currentRuntimeIdentifier: "win7", |
| 86 | + alternativeCurrentRuntimeIdentifier : null, |
| 87 | + runtimeGraph : _testRuntimeGraph, |
| 88 | + candidateRuntimeIdentifiers : new [] { "win", "win", "any" }, |
| 89 | + mostFitRuntimeIdentifier : out string mostFitRid) |
| 90 | + .Should().BeTrue(); |
| 91 | + |
| 92 | + mostFitRid.Should().Be("win"); |
| 93 | + } |
| 94 | + |
| 95 | + [Fact] |
| 96 | + public void WhenPassSeveralCompatibleRuntimeIdentifiersAndDuplicationItOutMostFitRidWithCasingPreservedTheFirstIsFavoriated() |
| 97 | + { |
| 98 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 99 | + currentRuntimeIdentifier: "win7", |
| 100 | + alternativeCurrentRuntimeIdentifier: null, |
| 101 | + runtimeGraph: _testRuntimeGraph, |
| 102 | + candidateRuntimeIdentifiers: new[] { "Win", "win", "win", "any" }, |
| 103 | + mostFitRuntimeIdentifier: out string mostFitRid) |
| 104 | + .Should().BeTrue(); |
| 105 | + |
| 106 | + mostFitRid.Should().Be("Win"); |
| 107 | + } |
| 108 | + |
| 109 | + [Fact] |
| 110 | + public void WhenPassSeveralNonCompatibleRuntimeIdentifiersItReturnsFalse() |
| 111 | + { |
| 112 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 113 | + currentRuntimeIdentifier: "win7", |
| 114 | + alternativeCurrentRuntimeIdentifier : null, |
| 115 | + runtimeGraph : _testRuntimeGraph, |
| 116 | + candidateRuntimeIdentifiers : new [] { "centos", "debian" }, |
| 117 | + mostFitRuntimeIdentifier : out string mostFitRid) |
| 118 | + .Should().BeFalse(); |
| 119 | + } |
| 120 | + |
| 121 | + [Fact] |
| 122 | + public void WhenCurrentRuntimeIdentifierIsNotSupportedItUsesAlternative() |
| 123 | + { |
| 124 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 125 | + currentRuntimeIdentifier: "win-vnext", |
| 126 | + alternativeCurrentRuntimeIdentifier: "win8", |
| 127 | + runtimeGraph: _testRuntimeGraph, |
| 128 | + candidateRuntimeIdentifiers: new[] { "win", "any" }, |
| 129 | + mostFitRuntimeIdentifier: out string mostFitRid) |
| 130 | + .Should().BeTrue(); |
| 131 | + |
| 132 | + mostFitRid.Should().Be("win"); |
| 133 | + } |
| 134 | + |
| 135 | + [Fact] |
| 136 | + public void WhenCurrentRuntimeIdentifierIsNotSupportedSoIsTheAlternativeItReturnsFalse() |
| 137 | + { |
| 138 | + FrameworkDependencyFile.TryGetMostFitRuntimeIdentifier( |
| 139 | + currentRuntimeIdentifier: "osx10.13-x64", |
| 140 | + alternativeCurrentRuntimeIdentifier: "osx-x64", |
| 141 | + runtimeGraph: _testRuntimeGraph, |
| 142 | + candidateRuntimeIdentifiers: new[] { "win", "any" }, |
| 143 | + mostFitRuntimeIdentifier: out string mostFitRid) |
| 144 | + .Should().BeFalse(); |
| 145 | + } |
| 146 | + } |
| 147 | +} |
0 commit comments