From ee2a591d2c99cecfdac6b3e42cf8b3818c6c3fd3 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Thu, 19 May 2016 16:27:54 -0700 Subject: [PATCH] [Fixes #4655] Make comparisons in DefaultAssemblyPartDiscoveryProvider case insensitive --- .../DefaultAssemblyPartDiscoveryProvider.cs | 4 +-- ...efaultAssemblyPartDiscoveryProviderTest.cs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs index 26ff3c1630..d5db9a861d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal // Discovers assemblies that are part of the MVC application using the DependencyContext. public static class DefaultAssemblyPartDiscoveryProvider { - internal static HashSet ReferenceAssemblies { get; } = new HashSet(StringComparer.Ordinal) + internal static HashSet ReferenceAssemblies { get; } = new HashSet(StringComparer.OrdinalIgnoreCase) { "Microsoft.AspNetCore.Mvc", "Microsoft.AspNetCore.Mvc.Abstractions", @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal public CandidateResolver(IReadOnlyList dependencies, ISet referenceAssemblies) { _dependencies = dependencies - .ToDictionary(d => d.Name, d => CreateDependency(d, referenceAssemblies)); + .ToDictionary(d => d.Name, d => CreateDependency(d, referenceAssemblies), StringComparer.OrdinalIgnoreCase); } private Dependency CreateDependency(RuntimeLibrary library, ISet referenceAssemblies) diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs index 45d87810ba..abc3a35246 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs @@ -79,6 +79,37 @@ namespace Microsoft.AspNetCore.Mvc.Internal Assert.Equal(new[] { "Foo", "Bar", "Baz" }, candidates.Select(a => a.Name)); } + [Fact] + public void GetCandidateLibraries_LibraryNameComparisonsAreCaseInsensitive() + { + // Arrange + var dependencyContext = new DependencyContext( + new TargetInfo("framework", "runtime", "signature", isPortable: true), + CompilationOptions.Default, + new CompilationLibrary[0], + new[] + { + GetLibrary("Foo", "MICROSOFT.ASPNETCORE.MVC.CORE"), + GetLibrary("Bar", "microsoft.aspnetcore.mvc"), + GetLibrary("Qux", "Not.Mvc.Assembly", "Unofficial.Microsoft.AspNetCore.Mvc"), + GetLibrary("Baz", "mIcRoSoFt.AsPnEtCoRe.MvC.aBsTrAcTiOnS"), + GetLibrary("Microsoft.AspNetCore.Mvc.Core"), + GetLibrary("LibraryA", "LIBRARYB"), + GetLibrary("LibraryB", "microsoft.aspnetcore.mvc"), + GetLibrary("Microsoft.AspNetCore.Mvc"), + GetLibrary("Not.Mvc.Assembly"), + GetLibrary("Unofficial.Microsoft.AspNetCore.Mvc"), + GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"), + }, + Enumerable.Empty()); + + // Act + var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext); + + // Assert + Assert.Equal(new[] { "Foo", "Bar", "Baz", "LibraryA", "LibraryB" }, candidates.Select(a => a.Name)); + } + [Fact] public void GetCandidateLibraries_ReturnsLibrariesWithTransitiveReferencesToAnyMvcAssembly() {