Пример #1
0
        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 <RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { "Foo", "Bar", "Baz", "LibraryA", "LibraryB" }, candidates.Select(a => a.Name));
        }
Пример #2
0
        public void GetCandidateLibraries_SkipsMvcAssemblies()
        {
            // Arrange
            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
            {
                GetLibrary("MvcSandbox", "Microsoft.AspNetCore.Mvc.Core", "Microsoft.AspNetCore.Mvc"),
                GetLibrary("Microsoft.AspNetCore.Mvc.Core", "Microsoft.AspNetCore.HttpAbstractions"),
                GetLibrary("Microsoft.AspNetCore.HttpAbstractions"),
                GetLibrary("Microsoft.AspNetCore.Mvc", "Microsoft.AspNetCore.Mvc.Abstractions", "Microsoft.AspNetCore.Mvc.Core"),
                GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
                GetLibrary("Microsoft.AspNetCore.Mvc.TagHelpers", "Microsoft.AspNetCore.Mvc.Razor"),
                GetLibrary("Microsoft.AspNetCore.Mvc.Razor"),
                GetLibrary("ControllersAssembly", "Microsoft.AspNetCore.Mvc"),
            },
                Enumerable.Empty <RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { "MvcSandbox", "ControllersAssembly" }, candidates.Select(a => a.Name));
        }
Пример #3
0
        public void GetCandidateLibraries_ReturnsLibrariesReferencingAnyMvcAssembly()
        {
            // 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("Microsoft.AspNetCore.Mvc"),
                GetLibrary("Not.Mvc.Assembly"),
                GetLibrary("Unofficial.Microsoft.AspNetCore.Mvc"),
                GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
            },
                Enumerable.Empty <RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { "Foo", "Bar", "Baz" }, candidates.Select(a => a.Name));
        }
Пример #4
0
        public void CandidateAssemblies_ReturnsEntryAssemblyIfDependencyContextIsNull()
        {
            // Arrange & Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateAssemblies(CurrentAssembly, dependencyContext: null);

            // Assert
            Assert.Equal(new[] { CurrentAssembly }, candidates);
        }
        public void ResolveAdditionalReferences_DiscoversAdditionalReferences(ResolveAdditionalReferencesTestData testData)
        {
            // Arrange
            var resolver = testData.AssemblyResolver;

            DefaultAssemblyPartDiscoveryProvider.AssemblyResolver = path => resolver.ContainsKey(path);
            DefaultAssemblyPartDiscoveryProvider.AssemblyLoader   = path => resolver.TryGetValue(path, out var result) ? result : null;

            // Arrange & Act
            var(additionalReferences, entryAssemblyAdditionalReferences) =
                DefaultAssemblyPartDiscoveryProvider.ResolveAdditionalReferences(testData.EntryAssembly, testData.CandidateAssemblies);

            var additionalRefs = additionalReferences.Select(a => a.FullName).OrderBy(id => id).ToArray();
            var entryAssemblyAdditionalRefs = entryAssemblyAdditionalReferences.Select(a => a.FullName).OrderBy(id => id).ToArray();

            // Assert
            Assert.Equal(testData.ExpectedAdditionalReferences, additionalRefs);
            Assert.Equal(testData.ExpectedEntryAssemblyAdditionalReferences, entryAssemblyAdditionalRefs);
        }
        public void GetCandidateLibraries_DoesNotThrow_IfLibraryDoesNotHaveRuntimeComponent()
        {
            // Arrange
            var expected = GetLibrary("MyApplication", "Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Mvc");
            var deps     = new DependencyContext(
                new TargetInfo("netcoreapp2.0", "rurntime", "signature", isPortable: true),
                CompilationOptions.Default,
                Enumerable.Empty <CompilationLibrary>(),
                new[]
            {
                expected,
                GetLibrary("Microsoft.AspNetCore.Server.Kestrel", "Libuv"),
                GetLibrary("Microsoft.AspNetCore.Mvc"),
            },
                Enumerable.Empty <RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(deps).ToList();

            // Assert
            Assert.Equal(new[] { expected }, candidates);
        }
Пример #7
0
        public void GetCandidateLibraries_IgnoresMvcAssemblies()
        {
            // Arrange
            var expected          = GetLibrary("SomeRandomAssembly", "Microsoft.AspNetCore.Mvc.Abstractions");
            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
            {
                GetLibrary("Microsoft.AspNetCore.Mvc.Core"),
                GetLibrary("Microsoft.AspNetCore.Mvc"),
                GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
                expected,
            },
                Enumerable.Empty <RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { expected }, candidates);
        }
        public void CandidateResolver_ThrowsIfDependencyContextContainsDuplicateRuntimeLibraryNames()
        {
            // Arrange
            var upperCaseLibrary = "Microsoft.AspNetCore.Mvc";
            var mixedCaseLibrary = "microsoft.aspNetCore.mvc";

            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
            {
                GetLibrary(mixedCaseLibrary),
                GetLibrary(upperCaseLibrary),
            },
                Enumerable.Empty <RuntimeFallbacks>());

            // Act
            var exception = Assert.Throws <InvalidOperationException>(() => DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext));

            // Assert
            Assert.Equal($"A duplicate entry for library reference {upperCaseLibrary} was found. Please check that all package references in all projects use the same casing for the same package references.", exception.Message);
        }