diff --git a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs index c118c64970..3cab7e2336 100644 --- a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs @@ -78,7 +78,15 @@ namespace Microsoft.Extensions.DependencyInjection // Action Discovery // // These are consumed only when creating action descriptors, then they can be de-allocated - services.TryAddTransient(); + if (PlatformServices.Default?.LibraryManager != null) + { + services.TryAddTransient(); + } + else + { + services.TryAddTransient(); + } + services.TryAddTransient(); services.TryAddEnumerable( ServiceDescriptor.Transient()); diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultAssemblyProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultAssemblyProvider.cs index 788fb0a949..ffdf3d39ae 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultAssemblyProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultAssemblyProvider.cs @@ -41,8 +41,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure "Microsoft.AspNet.Mvc.Razor", "Microsoft.AspNet.Mvc.Razor.Host", "Microsoft.AspNet.Mvc.TagHelpers", - "Microsoft.AspNet.Mvc.ViewFeatures", - "Microsoft.AspNet.PageExecutionInstrumentation.Interfaces", + "Microsoft.AspNet.Mvc.ViewFeatures" }; /// diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DependencyContextAssemblyProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DependencyContextAssemblyProvider.cs new file mode 100644 index 0000000000..235769398c --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DependencyContextAssemblyProvider.cs @@ -0,0 +1,78 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using Microsoft.Extensions.DependencyModel; + +namespace Microsoft.AspNet.Mvc.Infrastructure +{ + public class DependencyContextAssemblyProvider : IAssemblyProvider + { + /// + /// Gets the set of assembly names that are used as root for discovery of + /// MVC controllers, view components and views. + /// + // DefaultControllerTypeProvider uses CandidateAssemblies to determine if the base type of a POCO controller + // lives in an assembly that references MVC. CandidateAssemblies excludes all assemblies from the + // ReferenceAssemblies set. Consequently adding WebApiCompatShim to this set would cause the ApiController to + // fail this test. + protected virtual HashSet ReferenceAssemblies { get; } = new HashSet(StringComparer.Ordinal) + { + "Microsoft.AspNet.Mvc", + "Microsoft.AspNet.Mvc.Abstractions", + "Microsoft.AspNet.Mvc.ApiExplorer", + "Microsoft.AspNet.Mvc.Core", + "Microsoft.AspNet.Mvc.Cors", + "Microsoft.AspNet.Mvc.DataAnnotations", + "Microsoft.AspNet.Mvc.Formatters.Json", + "Microsoft.AspNet.Mvc.Formatters.Xml", + "Microsoft.AspNet.Mvc.Localization", + "Microsoft.AspNet.Mvc.Razor", + "Microsoft.AspNet.Mvc.Razor.Host", + "Microsoft.AspNet.Mvc.TagHelpers", + "Microsoft.AspNet.Mvc.ViewFeatures" + }; + + /// + public IEnumerable CandidateAssemblies + { + get + { + return GetCandidateLibraries() + .SelectMany(l => l.Assemblies) + .Select(Load); + } + } + + /// + /// Returns a list of libraries that references the assemblies in . + /// By default it returns all assemblies that reference any of the primary MVC assemblies + /// while ignoring MVC assemblies. + /// + /// A set of . + protected virtual IEnumerable GetCandidateLibraries() + { + if (ReferenceAssemblies == null) + { + return Enumerable.Empty(); + } + + return DependencyContext.Default.RuntimeLibraries.Where(IsCandidateLibrary); + } + + private static Assembly Load(RuntimeAssembly assembly) + { + return Assembly.Load(assembly.Name); + } + + private bool IsCandidateLibrary(RuntimeLibrary library) + { + Debug.Assert(ReferenceAssemblies != null); + return library.Dependencies.Any(dependency => ReferenceAssemblies.Contains(dependency.Name)); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/project.json b/src/Microsoft.AspNet.Mvc.Core/project.json index 6e9f7cf26e..72f7dfe17c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/project.json +++ b/src/Microsoft.AspNet.Mvc.Core/project.json @@ -21,6 +21,7 @@ "version": "1.0.0-*" }, "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", + "Microsoft.Extensions.DependencyModel": "1.0.0-*", "Microsoft.Extensions.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" @@ -48,6 +49,7 @@ "frameworks": { "net451": { "frameworkAssemblies": { + "System.Reflection": "", "System.Runtime": "" } }, diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRoslynCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRoslynCompilationService.cs new file mode 100644 index 0000000000..3055d220d9 --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRoslynCompilationService.cs @@ -0,0 +1,121 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using Microsoft.CodeAnalysis; +using Microsoft.Dnx.Compilation.CSharp; +using Microsoft.Extensions.CompilationAbstractions; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.PlatformAbstractions; + +namespace Microsoft.AspNet.Mvc.Razor.Compilation +{ + /// + /// A type that uses Roslyn to compile C# content and to find out references. + /// + public class DefaultRoslynCompilationService : RoslynCompilationService + { + private readonly IApplicationEnvironment _environment; + private readonly ILibraryExporter _libraryExporter; + + /// + /// Initalizes a new instance of the class. + /// + /// The environment for the executing application. + /// The library manager that provides export and reference information. + /// The that was used to generate the code. + /// Accessor to . + /// The . + /// The . + public DefaultRoslynCompilationService(IApplicationEnvironment environment, + ILibraryExporter libraryExporter, + IMvcRazorHost host, + IOptions optionsAccessor, + IRazorViewEngineFileProviderAccessor fileProviderAccessor, + ILoggerFactory loggerFactory) + : base(environment, host, optionsAccessor, fileProviderAccessor, loggerFactory) + { + _environment = environment; + _libraryExporter = libraryExporter; + } + + protected override List GetApplicationReferences() + { + var references = new List(); + + // Get the MetadataReference for the executing application. If it's a Roslyn reference, + // we can copy the references created when compiling the application to the Razor page being compiled. + // This avoids performing expensive calls to MetadataReference.CreateFromImage. + var libraryExport = _libraryExporter.GetExport(_environment.ApplicationName); + if (libraryExport?.MetadataReferences != null && libraryExport.MetadataReferences.Count > 0) + { + Debug.Assert(libraryExport.MetadataReferences.Count == 1, + "Expected 1 MetadataReferences, found " + libraryExport.MetadataReferences.Count); + var roslynReference = libraryExport.MetadataReferences[0] as IRoslynMetadataReference; + var compilationReference = roslynReference?.MetadataReference as CompilationReference; + if (compilationReference != null) + { + references.AddRange(compilationReference.Compilation.References); + references.Add(roslynReference.MetadataReference); + return references; + } + } + + var export = _libraryExporter.GetAllExports(_environment.ApplicationName); + if (export != null) + { + foreach (var metadataReference in export.MetadataReferences) + { + // Taken from https://github.com/aspnet/KRuntime/blob/757ba9bfdf80bd6277e715d6375969a7f44370ee/src/... + // Microsoft.Extensions.Runtime.Roslyn/RoslynCompiler.cs#L164 + // We don't want to take a dependency on the Roslyn bit directly since it pulls in more dependencies + // than the view engine needs (Microsoft.Extensions.Runtime) for example + references.Add(ConvertMetadataReference(metadataReference)); + } + } + + return references; + } + + private MetadataReference ConvertMetadataReference(IMetadataReference metadataReference) + { + var roslynReference = metadataReference as IRoslynMetadataReference; + + if (roslynReference != null) + { + return roslynReference.MetadataReference; + } + + var embeddedReference = metadataReference as IMetadataEmbeddedReference; + + if (embeddedReference != null) + { + return MetadataReference.CreateFromImage(embeddedReference.Contents); + } + + var fileMetadataReference = metadataReference as IMetadataFileReference; + + if (fileMetadataReference != null) + { + return CreateMetadataFileReference(fileMetadataReference.Path); + } + + var projectReference = metadataReference as IMetadataProjectReference; + if (projectReference != null) + { + using (var ms = new MemoryStream()) + { + projectReference.EmitReferenceAssembly(ms); + + return MetadataReference.CreateFromImage(ms.ToArray()); + } + } + + throw new NotSupportedException(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/DependencyContextCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/DependencyContextCompilationService.cs new file mode 100644 index 0000000000..e2d659603c --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/DependencyContextCompilationService.cs @@ -0,0 +1,68 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.DependencyModel; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.PlatformAbstractions; + +namespace Microsoft.AspNet.Mvc.Razor.Compilation +{ + /// + /// A type that uses Roslyn to compile C# content and to locate references. + /// + public class DependencyContextCompilationService : RoslynCompilationService + { + private readonly DependencyContext _dependencyContext; + + /// + /// Initalizes a new instance of the class. + /// + /// The environment for the executing application. + /// The that was used to generate the code. + /// Accessor to . + /// The . + /// The . + public DependencyContextCompilationService( + IApplicationEnvironment environment, + IMvcRazorHost host, + IOptions optionsAccessor, + IRazorViewEngineFileProviderAccessor fileProviderAccessor, + ILoggerFactory loggerFactory) + : this(DependencyContext.Default, environment, host, optionsAccessor, fileProviderAccessor, loggerFactory) + { + } + + /// + /// Initalizes a new instance of the class. + /// + /// to use for reference resolution. + /// The environment for the executing application. + /// The that was used to generate the code. + /// Accessor to . + /// The . + /// The . + public DependencyContextCompilationService( + DependencyContext dependencyContext, + IApplicationEnvironment environment, + IMvcRazorHost host, + IOptions optionsAccessor, + IRazorViewEngineFileProviderAccessor fileProviderAccessor, + ILoggerFactory loggerFactory) + : base(environment, host, optionsAccessor, fileProviderAccessor, loggerFactory) + { + _dependencyContext = dependencyContext; + } + + protected override List GetApplicationReferences() + { + return _dependencyContext.CompileLibraries + .SelectMany(library => library.ResolveReferencePaths()) + .Select(CreateMetadataFileReference) + .ToList(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs index 0e6f74041e..4ce786186a 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs @@ -13,6 +13,7 @@ using System.Reflection.PortableExecutable; using System.Runtime.Loader; #endif using System.Runtime.Versioning; +using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Logging; using Microsoft.AspNet.Mvc.Razor.Internal; @@ -22,7 +23,6 @@ using Microsoft.CodeAnalysis.Emit; using Microsoft.Dnx.Compilation.CSharp; using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.Options; -using Microsoft.AspNet.Diagnostics; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Mvc.Razor.Compilation @@ -30,13 +30,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation /// /// A type that uses Roslyn to compile C# content. /// - public class RoslynCompilationService : ICompilationService + public abstract class RoslynCompilationService : ICompilationService { private readonly Lazy _supportsPdbGeneration = new Lazy(SymbolsUtility.SupportsSymbolsGeneration); private readonly ConcurrentDictionary _metadataFileCache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); - private readonly Extensions.CompilationAbstractions.ILibraryExporter _libraryExporter; private readonly IApplicationEnvironment _environment; private readonly IFileProvider _fileProvider; private readonly Lazy> _applicationReferences; @@ -54,20 +53,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation /// Initalizes a new instance of the class. /// /// The environment for the executing application. - /// The library manager that provides export and reference information. /// The that was used to generate the code. /// Accessor to . /// The . public RoslynCompilationService( IApplicationEnvironment environment, - Extensions.CompilationAbstractions.ILibraryExporter libraryExporter, IMvcRazorHost host, IOptions optionsAccessor, IRazorViewEngineFileProviderAccessor fileProviderAccessor, ILoggerFactory loggerFactory) { _environment = environment; - _libraryExporter = libraryExporter; _applicationReferences = new Lazy>(GetApplicationReferences); _fileProvider = fileProviderAccessor.FileProvider; _classPrefix = host.MainClassNamePrefix; @@ -156,8 +152,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation assembly = LoadStream(ms, assemblySymbols: null); } - var type = assembly.GetExportedTypes() - .First(t => t.Name.StartsWith(_classPrefix, StringComparison.Ordinal)); + var type = assembly + .GetExportedTypes() + .First(t => t.Name.StartsWith(_classPrefix, StringComparison.Ordinal)); _logger.GeneratedCodeToAssemblyCompilationEnd(fileInfo.RelativePath, startTimestamp); @@ -239,83 +236,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation return diagnostic.Location.GetMappedLineSpan().Path; } - private List GetApplicationReferences() - { - var references = new List(); + protected abstract List GetApplicationReferences(); - // Get the MetadataReference for the executing application. If it's a Roslyn reference, - // we can copy the references created when compiling the application to the Razor page being compiled. - // This avoids performing expensive calls to MetadataReference.CreateFromImage. - var libraryExport = _libraryExporter.GetExport(_environment.ApplicationName); - if (libraryExport?.MetadataReferences != null && libraryExport.MetadataReferences.Count > 0) - { - Debug.Assert(libraryExport.MetadataReferences.Count == 1, - "Expected 1 MetadataReferences, found " + libraryExport.MetadataReferences.Count); - var roslynReference = libraryExport.MetadataReferences[0] as IRoslynMetadataReference; - var compilationReference = roslynReference?.MetadataReference as CompilationReference; - if (compilationReference != null) - { - references.AddRange(compilationReference.Compilation.References); - references.Add(roslynReference.MetadataReference); - return references; - } - } - - var export = _libraryExporter.GetAllExports(_environment.ApplicationName); - if (export != null) - { - foreach (var metadataReference in export.MetadataReferences) - { - // Taken from https://github.com/aspnet/KRuntime/blob/757ba9bfdf80bd6277e715d6375969a7f44370ee/src/... - // Microsoft.Extensions.Runtime.Roslyn/RoslynCompiler.cs#L164 - // We don't want to take a dependency on the Roslyn bit directly since it pulls in more dependencies - // than the view engine needs (Microsoft.Extensions.Runtime) for example - references.Add(ConvertMetadataReference(metadataReference)); - } - } - - return references; - } - - private MetadataReference ConvertMetadataReference( - Extensions.CompilationAbstractions.IMetadataReference metadataReference) - { - var roslynReference = metadataReference as IRoslynMetadataReference; - - if (roslynReference != null) - { - return roslynReference.MetadataReference; - } - - var embeddedReference = metadataReference as Extensions.CompilationAbstractions.IMetadataEmbeddedReference; - - if (embeddedReference != null) - { - return MetadataReference.CreateFromImage(embeddedReference.Contents); - } - - var fileMetadataReference = metadataReference as Extensions.CompilationAbstractions.IMetadataFileReference; - - if (fileMetadataReference != null) - { - return CreateMetadataFileReference(fileMetadataReference.Path); - } - - var projectReference = metadataReference as Extensions.CompilationAbstractions.IMetadataProjectReference; - if (projectReference != null) - { - using (var ms = new MemoryStream()) - { - projectReference.EmitReferenceAssembly(ms); - - return MetadataReference.CreateFromImage(ms.ToArray()); - } - } - - throw new NotSupportedException(); - } - - private MetadataReference CreateMetadataFileReference(string path) + protected MetadataReference CreateMetadataFileReference(string path) { var metadata = _metadataFileCache.GetOrAdd(path, _ => { diff --git a/src/Microsoft.AspNet.Mvc.Razor/DependencyContextRazorViewEngineOptionsSetup.cs b/src/Microsoft.AspNet.Mvc.Razor/DependencyContextRazorViewEngineOptionsSetup.cs new file mode 100644 index 0000000000..d87b34d817 --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Razor/DependencyContextRazorViewEngineOptionsSetup.cs @@ -0,0 +1,88 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Mvc.Razor; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.DependencyModel; + +namespace Microsoft.AspNet.Mvc +{ + /// + /// Sets up compilation and parse option default options for using + /// + public class DependencyContextRazorViewEngineOptionsSetup : ConfigureOptions + { + /// + /// Initializes a new instance of . + /// + public DependencyContextRazorViewEngineOptionsSetup() : this(DependencyContext.Default) + { + } + + /// + /// Initializes a new instance of . + /// + /// to use as compilation and parse option source. + public DependencyContextRazorViewEngineOptionsSetup(DependencyContext dependencyContext) : base(options => ConfigureRazor(options, dependencyContext)) + { + } + + private static void ConfigureRazor(RazorViewEngineOptions options, DependencyContext dependencyContext) + { + var compilationOptions = dependencyContext.CompilationOptions; + + SetParseOptions(options, compilationOptions); + SetCompilationOptions(options, compilationOptions); + } + + private static void SetCompilationOptions(RazorViewEngineOptions options, Microsoft.Extensions.DependencyModel.CompilationOptions compilationOptions) + { + var roslynOptions = options.CompilationOptions; + + // Disable 1702 until roslyn turns this off by default + roslynOptions = roslynOptions.WithSpecificDiagnosticOptions( + new Dictionary + { + {"CS1701", ReportDiagnostic.Suppress}, // Binding redirects + {"CS1702", ReportDiagnostic.Suppress}, + {"CS1705", ReportDiagnostic.Suppress} + }); + + if (compilationOptions.AllowUnsafe.HasValue) + { + roslynOptions = roslynOptions.WithAllowUnsafe(compilationOptions.AllowUnsafe.Value); + } + + if (compilationOptions.Optimize.HasValue) + { + var optimizationLevel = compilationOptions.Optimize.Value ? OptimizationLevel.Debug : OptimizationLevel.Release; + roslynOptions = roslynOptions.WithOptimizationLevel(optimizationLevel); + } + + if (compilationOptions.WarningsAsErrors.HasValue) + { + var reportDiagnostic = compilationOptions.WarningsAsErrors.Value ? ReportDiagnostic.Error : ReportDiagnostic.Default; + roslynOptions = roslynOptions.WithGeneralDiagnosticOption(reportDiagnostic); + } + + options.CompilationOptions = roslynOptions; + } + + private static void SetParseOptions(RazorViewEngineOptions options, Microsoft.Extensions.DependencyModel.CompilationOptions compilationOptions) + { + var roslynParseOptions = options.ParseOptions; + roslynParseOptions = roslynParseOptions.WithPreprocessorSymbols(compilationOptions.Defines); + + var languageVersion = roslynParseOptions.LanguageVersion; + if (Enum.TryParse(compilationOptions.LanguageVersion, ignoreCase: true, result: out languageVersion)) + { + roslynParseOptions = roslynParseOptions.WithLanguageVersion(languageVersion); + } + + options.ParseOptions = roslynParseOptions; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs index bc68a4a978..5a2098486f 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs @@ -94,9 +94,22 @@ namespace Microsoft.Extensions.DependencyInjection // Internal for testing. internal static void AddRazorViewEngineServices(IServiceCollection services) { - if (CompilationServices.Default != null) + var compilationServicesAvailible = CompilationServices.Default != null; + + if (compilationServicesAvailible) { services.TryAddSingleton(CompilationServices.Default.LibraryExporter); + + // This caches compilation related details that are valid across the lifetime of the application. + services.TryAddSingleton(); + } + else + { + services.TryAddEnumerable( + ServiceDescriptor.Transient, DependencyContextRazorViewEngineOptionsSetup>()); + + // This caches compilation related details that are valid across the lifetime of the application. + services.TryAddSingleton(); } services.TryAddEnumerable( @@ -117,9 +130,6 @@ namespace Microsoft.Extensions.DependencyInjection // Caches compilation artifacts across the lifetime of the application. services.TryAddSingleton(); - // This caches compilation related details that are valid across the lifetime of the application. - services.TryAddSingleton(); - // In the default scenario the following services are singleton by virtue of being initialized as part of // creating the singleton RazorViewEngine instance. services.TryAddTransient(); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultAssemblyProviderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultAssemblyProviderTests.cs index a52ef250c1..381a1b4528 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultAssemblyProviderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultAssemblyProviderTests.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Http; using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.Extensions.DependencyInjection; using Moq; using Xunit; @@ -107,14 +107,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure { // Arrange var provider = new MvcAssembliesTestingProvider(); - - var expected = provider.LoadableReferenceAssemblies; + var expected = provider.LoadableReferenceAssemblies.OrderBy(p => p, StringComparer.Ordinal); // Act - var referenceAssemblies = provider.ReferenceAssemblies; + var referenceAssemblies = provider.ReferenceAssemblies.OrderBy(p => p, StringComparer.Ordinal); // Assert - Assert.True(expected.SetEquals(referenceAssemblies)); + Assert.Equal(expected, referenceAssemblies); } private static ILibraryManager CreateLibraryManager() @@ -236,7 +235,6 @@ namespace Microsoft.AspNet.Mvc.Infrastructure // The following assemblies are not reachable from Microsoft.AspNet.Mvc mvcAssemblies.Add("Microsoft.AspNet.Mvc.TagHelpers"); mvcAssemblies.Add("Microsoft.AspNet.Mvc.Formatters.Xml"); - mvcAssemblies.Add("Microsoft.AspNet.PageExecutionInstrumentation.Interfaces"); return mvcAssemblies; } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RoslynCompilationServiceTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRoslynCompilationServiceTest.cs similarity index 95% rename from test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RoslynCompilationServiceTest.cs rename to test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRoslynCompilationServiceTest.cs index dc870f2de4..73c2eb4834 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RoslynCompilationServiceTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRoslynCompilationServiceTest.cs @@ -14,7 +14,7 @@ using Xunit; namespace Microsoft.AspNet.Mvc.Razor.Compilation { - public class RoslynCompilationServiceTest + public class DefaultRoslynCompilationServiceTest { private const string ConfigurationName = "Release"; @@ -30,7 +30,7 @@ public class MyTestType {}"; mvcRazorHost.SetupGet(m => m.MainClassNamePrefix) .Returns(string.Empty); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( applicationEnvironment, libraryExporter, mvcRazorHost.Object, @@ -63,7 +63,7 @@ this should fail"; var fileProvider = new TestFileProvider(); var fileInfo = fileProvider.AddFile(viewPath, fileContent); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( applicationEnvironment, libraryExporter, mvcRazorHost, @@ -93,7 +93,7 @@ this should fail"; var libraryExporter = CompilationServices.Default.LibraryExporter; var mvcRazorHost = Mock.Of(); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( applicationEnvironment, libraryExporter, mvcRazorHost, @@ -134,7 +134,7 @@ this should fail"; var fileProvider = new TestFileProvider(); fileProvider.AddFile(path, mockFileInfo.Object); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( applicationEnvironment, libraryExporter, mvcRazorHost, @@ -175,7 +175,7 @@ public class MyNonCustomDefinedClass {} var options = GetOptions(); options.Value.ParseOptions = options.Value.ParseOptions.WithPreprocessorSymbols("MY_CUSTOM_DEFINE"); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( applicationEnvironment, libraryExporter, mvcRazorHost.Object, @@ -207,7 +207,7 @@ public class NotRazorPrefixType {}"; mvcRazorHost.SetupGet(m => m.MainClassNamePrefix) .Returns("RazorPrefix"); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( applicationEnvironment, libraryExporter, mvcRazorHost.Object, @@ -240,7 +240,7 @@ public class NotRazorPrefixType {}"; var optionsAccessor = new Mock>(); optionsAccessor.SetupGet(o => o.Value) .Returns(options); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( PlatformServices.Default.Application, CompilationServices.Default.LibraryExporter, Mock.Of(), @@ -333,7 +333,7 @@ public class NotRazorPrefixType {}"; mvcRazorHost.SetupGet(m => m.MainClassNamePrefix) .Returns(string.Empty); - var compilationService = new RoslynCompilationService( + var compilationService = new DefaultRoslynCompilationService( applicationEnvironment, libraryExporter, mvcRazorHost.Object,