react to DNX renames

This commit is contained in:
Andrew Stanton-Nurse 2015-07-21 17:13:24 -07:00
parent bb618ac437
commit 991dff6b9e
15 changed files with 82 additions and 194 deletions

View File

@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Mvc
{ {
get get
{ {
return GetCandidateLibraries().SelectMany(l => l.LoadableAssemblies) return GetCandidateLibraries().SelectMany(l => l.Assemblies)
.Select(Load); .Select(Load);
} }
} }
@ -60,12 +60,12 @@ namespace Microsoft.AspNet.Mvc
/// By default it returns all assemblies that reference any of the primary MVC assemblies /// By default it returns all assemblies that reference any of the primary MVC assemblies
/// while ignoring MVC assemblies. /// while ignoring MVC assemblies.
/// </summary> /// </summary>
/// <returns>A set of <see cref="ILibraryInformation"/>.</returns> /// <returns>A set of <see cref="Library"/>.</returns>
protected virtual IEnumerable<ILibraryInformation> GetCandidateLibraries() protected virtual IEnumerable<Library> GetCandidateLibraries()
{ {
if (ReferenceAssemblies == null) if (ReferenceAssemblies == null)
{ {
return Enumerable.Empty<ILibraryInformation>(); return Enumerable.Empty<Library>();
} }
// GetReferencingLibraries returns the transitive closure of referencing assemblies // GetReferencingLibraries returns the transitive closure of referencing assemblies
@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Mvc
return Assembly.Load(assemblyName); return Assembly.Load(assemblyName);
} }
private bool IsCandidateLibrary(ILibraryInformation library) private bool IsCandidateLibrary(Library library)
{ {
Debug.Assert(ReferenceAssemblies != null); Debug.Assert(ReferenceAssemblies != null);
return !ReferenceAssemblies.Contains(library.Name); return !ReferenceAssemblies.Contains(library.Name);

View File

@ -21,7 +21,7 @@
"Microsoft.Framework.PropertyActivator.Sources": { "version": "1.0.0-*", "type": "build" }, "Microsoft.Framework.PropertyActivator.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }, "Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.SecurityHelper.Sources": { "version": "1.0.0-*", "type": "build" }, "Microsoft.Framework.SecurityHelper.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", "Microsoft.Framework.Runtime.Compilation.Abstractions": "1.0.0-*",
"Newtonsoft.Json": "6.0.6" "Newtonsoft.Json": "6.0.6"
}, },
"frameworks": { "frameworks": {

View File

@ -4,8 +4,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime.Compilation;
namespace Microsoft.AspNet.Mvc.Razor.Compilation namespace Microsoft.AspNet.Mvc.Razor.Compilation
{ {
@ -20,16 +20,16 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
/// <param name="compilationFailures"><see cref="ICompilationFailure"/>s containing /// <param name="compilationFailures"><see cref="ICompilationFailure"/>s containing
/// details of the compilation failure.</param> /// details of the compilation failure.</param>
public CompilationFailedException( public CompilationFailedException(
[NotNull] IEnumerable<ICompilationFailure> compilationFailures) [NotNull] IEnumerable<CompilationFailure> compilationFailures)
: base(FormatMessage(compilationFailures)) : base(FormatMessage(compilationFailures))
{ {
CompilationFailures = compilationFailures; CompilationFailures = compilationFailures;
} }
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<ICompilationFailure> CompilationFailures { get; } public IEnumerable<CompilationFailure> CompilationFailures { get; }
private static string FormatMessage(IEnumerable<ICompilationFailure> compilationFailures) private static string FormatMessage(IEnumerable<CompilationFailure> compilationFailures)
{ {
return Resources.CompilationFailed + Environment.NewLine + return Resources.CompilationFailed + Environment.NewLine +
string.Join( string.Join(

View File

@ -3,6 +3,7 @@
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;
using Microsoft.Framework.Runtime.Roslyn; using Microsoft.Framework.Runtime.Roslyn;
namespace Microsoft.AspNet.Mvc.Razor.Compilation namespace Microsoft.AspNet.Mvc.Razor.Compilation

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;
namespace Microsoft.AspNet.Mvc.Razor.Compilation namespace Microsoft.AspNet.Mvc.Razor.Compilation
{ {
@ -37,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
/// </summary> /// </summary>
/// <remarks>This property is <c>null</c> when compilation succeeded. An empty sequence /// <remarks>This property is <c>null</c> when compilation succeeded. An empty sequence
/// indicates a failed compilation.</remarks> /// indicates a failed compilation.</remarks>
public IEnumerable<ICompilationFailure> CompilationFailures { get; private set; } public IEnumerable<CompilationFailure> CompilationFailures { get; private set; }
/// <summary> /// <summary>
/// Gets the <see cref="CompilationResult"/>. /// Gets the <see cref="CompilationResult"/>.
@ -57,10 +58,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
/// <summary> /// <summary>
/// Creates a <see cref="CompilationResult"/> for a failed compilation. /// Creates a <see cref="CompilationResult"/> for a failed compilation.
/// </summary> /// </summary>
/// <param name="compilationFailures"><see cref="ICompilationFailure"/>s produced from parsing or /// <param name="compilationFailures"><see cref="CompilationFailure"/>s produced from parsing or
/// compiling the Razor file.</param> /// compiling the Razor file.</param>
/// <returns>A <see cref="CompilationResult"/> instance for a failed compilation.</returns> /// <returns>A <see cref="CompilationResult"/> instance for a failed compilation.</returns>
public static CompilationResult Failed([NotNull] IEnumerable<ICompilationFailure> compilationFailures) public static CompilationResult Failed([NotNull] IEnumerable<CompilationFailure> compilationFailures)
{ {
return new CompilationResult return new CompilationResult
{ {

View File

@ -1,42 +0,0 @@
// 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 Microsoft.Framework.Runtime;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor.Compilation
{
/// <summary>
/// <see cref="ICompilationFailure"/> for Razor parse failures.
/// </summary>
public class RazorCompilationFailure : ICompilationFailure
{
/// <summary>Initializes a new instance of <see cref="RazorCompilationFailure"/>.</summary>
/// <param name="sourceFilePath">The path of the Razor source file that was compiled.</param>
/// <param name="sourceFileContent">The contents of the Razor source file.</param>
/// <param name="messages">A sequence of <see cref="ICompilationMessage"/> encountered
/// during compilation.</param>
public RazorCompilationFailure(
[NotNull] string sourceFilePath,
[NotNull] string sourceFileContent,
[NotNull] IEnumerable<RazorCompilationMessage> messages)
{
SourceFilePath = sourceFilePath;
SourceFileContent = sourceFileContent;
Messages = messages;
}
/// <inheritdoc />
public string SourceFilePath { get; }
/// <inheritdoc />
public string SourceFileContent { get; }
/// <inheritdoc />
public string CompiledContent { get; } = null;
/// <inheritdoc />
public IEnumerable<ICompilationMessage> Messages { get; }
}
}

View File

@ -1,74 +0,0 @@
// 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 Microsoft.AspNet.Razor;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime;
namespace Microsoft.AspNet.Mvc.Razor.Compilation
{
/// <summary>
/// <see cref="ICompilationMessage"/> for a <see cref="RazorError"/> encountered during parsing.
/// </summary>
public class RazorCompilationMessage : ICompilationMessage
{
/// <summary>
/// Initializes a <see cref="RazorCompilationMessage"/> with the specified message.
/// </summary>
/// <param name="razorError">A <see cref="RazorError"/>.</param>
/// <param name="sourceFilePath">The path of the Razor source file that was parsed.</param>
public RazorCompilationMessage(
[NotNull] RazorError razorError,
string sourceFilePath)
{
SourceFilePath = sourceFilePath;
Message = razorError.Message;
var location = razorError.Location;
FormattedMessage =
$"{sourceFilePath} ({location.LineIndex},{location.CharacterIndex}) {razorError.Message}";
StartColumn = location.CharacterIndex;
StartLine = location.LineIndex + 1;
EndColumn = location.CharacterIndex + razorError.Length;
EndLine = location.LineIndex + 1;
}
/// <summary>
/// Gets a message produced from compilation.
/// </summary>
public string Message { get; }
/// <inheritdoc />
public int StartColumn { get; }
/// <inheritdoc />
public int StartLine { get; }
/// <inheritdoc />
public int EndColumn { get; }
/// <inheritdoc />
public int EndLine { get; }
/// <inheritdoc />
public string SourceFilePath { get; }
/// <inheritdoc />
public string FormattedMessage { get; }
/// <inheritdoc />
// All Razor diagnostics are errors
public CompilationMessageSeverity Severity { get; } = CompilationMessageSeverity.Error;
/// <summary>
/// Returns a <see cref="string"/> representation of this instance of <see cref="RazorCompilationMessage"/>.
/// </summary>
/// <returns>A <see cref="string"/> representing this <see cref="RazorCompilationMessage"/> instance.</returns>
/// <remarks>Returns same value as <see cref="Message"/>.</remarks>
public override string ToString()
{
return FormattedMessage;
}
}
}

View File

@ -10,6 +10,8 @@ using Microsoft.AspNet.Razor;
using Microsoft.AspNet.Razor.CodeGenerators; using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;
namespace Microsoft.AspNet.Mvc.Razor.Compilation namespace Microsoft.AspNet.Mvc.Razor.Compilation
{ {
@ -82,21 +84,34 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
razorError.Location.FilePath ?? file.RelativePath, razorError.Location.FilePath ?? file.RelativePath,
StringComparer.Ordinal); StringComparer.Ordinal);
var failures = new List<RazorCompilationFailure>(); var failures = new List<CompilationFailure>();
foreach (var group in messageGroups) foreach (var group in messageGroups)
{ {
var filePath = group.Key; var filePath = group.Key;
var fileContent = ReadFileContentsSafely(filePath); var fileContent = ReadFileContentsSafely(filePath);
var compilationFailure = new RazorCompilationFailure( var compilationFailure = new CompilationFailure(
filePath, filePath,
fileContent, fileContent,
group.Select(parserError => new RazorCompilationMessage(parserError, filePath))); group.Select(parserError => CreateDiagnosticMessage(parserError, filePath)));
failures.Add(compilationFailure); failures.Add(compilationFailure);
} }
return CompilationResult.Failed(failures); return CompilationResult.Failed(failures);
} }
private DiagnosticMessage CreateDiagnosticMessage(RazorError error, string filePath)
{
return new DiagnosticMessage(
error.Message,
$"{error} ({error.Location.LineIndex},{error.Location.CharacterIndex}) {error.Message}",
filePath,
DiagnosticMessageSeverity.Error,
error.Location.LineIndex + 1,
error.Location.CharacterIndex,
error.Location.LineIndex + 1,
error.Location.CharacterIndex + error.Length);
}
private string ReadFileContentsSafely(string relativePath) private string ReadFileContentsSafely(string relativePath)
{ {
var fileInfo = _fileProvider.GetFileInfo(relativePath); var fileInfo = _fileProvider.GetFileInfo(relativePath);

View File

@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
private readonly ConcurrentDictionary<string, AssemblyMetadata> _metadataFileCache = private readonly ConcurrentDictionary<string, AssemblyMetadata> _metadataFileCache =
new ConcurrentDictionary<string, AssemblyMetadata>(StringComparer.OrdinalIgnoreCase); new ConcurrentDictionary<string, AssemblyMetadata>(StringComparer.OrdinalIgnoreCase);
private readonly ILibraryManager _libraryManager; private readonly ILibraryExporter _libraryExporter;
private readonly IApplicationEnvironment _environment; private readonly IApplicationEnvironment _environment;
private readonly IAssemblyLoadContext _loader; private readonly IAssemblyLoadContext _loader;
private readonly ICompilerOptionsProvider _compilerOptionsProvider; private readonly ICompilerOptionsProvider _compilerOptionsProvider;
@ -53,14 +53,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
/// <param name="host">The <see cref="IMvcRazorHost"/> that was used to generate the code.</param> /// <param name="host">The <see cref="IMvcRazorHost"/> that was used to generate the code.</param>
public RoslynCompilationService(IApplicationEnvironment environment, public RoslynCompilationService(IApplicationEnvironment environment,
IAssemblyLoadContextAccessor loaderAccessor, IAssemblyLoadContextAccessor loaderAccessor,
ILibraryManager libraryManager, ILibraryExporter libraryExporter,
ICompilerOptionsProvider compilerOptionsProvider, ICompilerOptionsProvider compilerOptionsProvider,
IMvcRazorHost host, IMvcRazorHost host,
IOptions<RazorViewEngineOptions> optionsAccessor) IOptions<RazorViewEngineOptions> optionsAccessor)
{ {
_environment = environment; _environment = environment;
_loader = loaderAccessor.GetLoadContext(typeof(RoslynCompilationService).GetTypeInfo().Assembly); _loader = loaderAccessor.GetLoadContext(typeof(RoslynCompilationService).GetTypeInfo().Assembly);
_libraryManager = libraryManager; _libraryExporter = libraryExporter;
_applicationReferences = new Lazy<List<MetadataReference>>(GetApplicationReferences); _applicationReferences = new Lazy<List<MetadataReference>>(GetApplicationReferences);
_compilerOptionsProvider = compilerOptionsProvider; _compilerOptionsProvider = compilerOptionsProvider;
_fileProvider = optionsAccessor.Options.FileProvider; _fileProvider = optionsAccessor.Options.FileProvider;
@ -141,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
.Where(IsError) .Where(IsError)
.GroupBy(diagnostic => GetFilePath(relativePath, diagnostic), StringComparer.Ordinal); .GroupBy(diagnostic => GetFilePath(relativePath, diagnostic), StringComparer.Ordinal);
var failures = new List<ICompilationFailure>(); var failures = new List<CompilationFailure>();
foreach (var group in diagnosticGroups) foreach (var group in diagnosticGroups)
{ {
var sourceFilePath = group.Key; var sourceFilePath = group.Key;
@ -157,12 +157,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
sourceFileContent = ReadFileContentsSafely(_fileProvider, sourceFilePath); sourceFileContent = ReadFileContentsSafely(_fileProvider, sourceFilePath);
} }
var compilationFailure = new RoslynCompilationFailure(group) var compilationFailure = new CompilationFailure(sourceFilePath, sourceFileContent, compilationContent, group.Select(d => d.ToDiagnosticMessage(_environment.RuntimeFramework)));
{
CompiledContent = compilationContent,
SourceFileContent = sourceFileContent,
SourceFilePath = sourceFilePath
};
failures.Add(compilationFailure); failures.Add(compilationFailure);
} }
@ -187,7 +182,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
// Get the MetadataReference for the executing application. If it's a Roslyn reference, // 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. // we can copy the references created when compiling the application to the Razor page being compiled.
// This avoids performing expensive calls to MetadataReference.CreateFromImage. // This avoids performing expensive calls to MetadataReference.CreateFromImage.
var libraryExport = _libraryManager.GetLibraryExport(_environment.ApplicationName); var libraryExport = _libraryExporter.GetLibraryExport(_environment.ApplicationName);
if (libraryExport?.MetadataReferences != null && libraryExport.MetadataReferences.Count > 0) if (libraryExport?.MetadataReferences != null && libraryExport.MetadataReferences.Count > 0)
{ {
Debug.Assert(libraryExport.MetadataReferences.Count == 1, Debug.Assert(libraryExport.MetadataReferences.Count == 1,
@ -202,7 +197,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
} }
} }
var export = _libraryManager.GetAllExports(_environment.ApplicationName); var export = _libraryExporter.GetAllExports(_environment.ApplicationName);
foreach (var metadataReference in export.MetadataReferences) foreach (var metadataReference in export.MetadataReferences)
{ {
// Taken from https://github.com/aspnet/KRuntime/blob/757ba9bfdf80bd6277e715d6375969a7f44370ee/src/... // Taken from https://github.com/aspnet/KRuntime/blob/757ba9bfdf80bd6277e715d6375969a7f44370ee/src/...

View File

@ -7,6 +7,7 @@ using Microsoft.AspNet.Mvc.Razor.Precompilation;
using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;
using Microsoft.Framework.Runtime.Roslyn; using Microsoft.Framework.Runtime.Roslyn;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc

View File

@ -22,10 +22,10 @@ namespace Microsoft.AspNet.Mvc.Core
manager.Setup(f => f.GetReferencingLibraries(It.IsAny<string>())) manager.Setup(f => f.GetReferencingLibraries(It.IsAny<string>()))
.Returns(new[] .Returns(new[]
{ {
CreateLibraryInfo("Microsoft.AspNet.Mvc.Core"), new Library("Microsoft.AspNet.Mvc.Core"),
CreateLibraryInfo("Microsoft.AspNet.Mvc"), new Library("Microsoft.AspNet.Mvc"),
CreateLibraryInfo("Microsoft.AspNet.Mvc.Abstractions"), new Library("Microsoft.AspNet.Mvc.Abstractions"),
CreateLibraryInfo("SomeRandomAssembly"), new Library("SomeRandomAssembly"),
}) })
.Verifiable(); .Verifiable();
var provider = new TestAssemblyProvider(manager.Object); var provider = new TestAssemblyProvider(manager.Object);
@ -45,13 +45,13 @@ namespace Microsoft.AspNet.Mvc.Core
// Arrange // Arrange
var manager = new Mock<ILibraryManager>(); var manager = new Mock<ILibraryManager>();
manager.Setup(f => f.GetReferencingLibraries(It.IsAny<string>())) manager.Setup(f => f.GetReferencingLibraries(It.IsAny<string>()))
.Returns(Enumerable.Empty<ILibraryInformation>()); .Returns(Enumerable.Empty<Library>());
manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc.Core")) manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc.Core"))
.Returns(new[] { CreateLibraryInfo("Foo") }); .Returns(new[] { new Library("Foo") });
manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc.Abstractions")) manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc.Abstractions"))
.Returns(new[] { CreateLibraryInfo("Bar") }); .Returns(new[] { new Library("Bar") });
manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc")) manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc"))
.Returns(new[] { CreateLibraryInfo("Baz") }); .Returns(new[] { new Library("Baz") });
var provider = new TestAssemblyProvider(manager.Object); var provider = new TestAssemblyProvider(manager.Object);
// Act // Act
@ -118,30 +118,23 @@ namespace Microsoft.AspNet.Mvc.Core
Assert.True(expected.SetEquals(referenceAssemblies)); Assert.True(expected.SetEquals(referenceAssemblies));
} }
private static ILibraryInformation CreateLibraryInfo(string name)
{
var info = new Mock<ILibraryInformation>();
info.SetupGet(b => b.Name).Returns(name);
return info.Object;
}
private static ILibraryManager CreateLibraryManager() private static ILibraryManager CreateLibraryManager()
{ {
var manager = new Mock<ILibraryManager>(); var manager = new Mock<ILibraryManager>();
manager.Setup(f => f.GetReferencingLibraries(It.IsAny<string>())) manager.Setup(f => f.GetReferencingLibraries(It.IsAny<string>()))
.Returns(Enumerable.Empty<ILibraryInformation>()); .Returns(Enumerable.Empty<Library>());
manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc.Core")) manager.Setup(f => f.GetReferencingLibraries("Microsoft.AspNet.Mvc.Core"))
.Returns(new[] { CreateLibraryInfo("Baz") }); .Returns(new[] { new Library("Baz") });
manager.Setup(f => f.GetReferencingLibraries("MyAssembly")) manager.Setup(f => f.GetReferencingLibraries("MyAssembly"))
.Returns(new[] { CreateLibraryInfo("Foo") }); .Returns(new[] { new Library("Foo") });
manager.Setup(f => f.GetReferencingLibraries("AnotherAssembly")) manager.Setup(f => f.GetReferencingLibraries("AnotherAssembly"))
.Returns(new[] { CreateLibraryInfo("Bar") }); .Returns(new[] { new Library("Bar") });
return manager.Object; return manager.Object;
} }
private class TestAssemblyProvider : DefaultAssemblyProvider private class TestAssemblyProvider : DefaultAssemblyProvider
{ {
public new IEnumerable<ILibraryInformation> GetCandidateLibraries() public new IEnumerable<Library> GetCandidateLibraries()
{ {
return base.GetCandidateLibraries(); return base.GetCandidateLibraries();
} }
@ -202,7 +195,7 @@ namespace Microsoft.AspNet.Mvc.Core
return new HashSet<string>( return new HashSet<string>(
SelectMvcAssemblies( SelectMvcAssemblies(
GetLoadableAssemblies(dependencies))); GetAssemblies(dependencies)));
} }
} }
@ -249,11 +242,11 @@ namespace Microsoft.AspNet.Mvc.Core
return mvcAssemblies; return mvcAssemblies;
} }
private static IEnumerable<string> GetLoadableAssemblies(IEnumerable<string> libraries) private static IEnumerable<string> GetAssemblies(IEnumerable<string> libraries)
{ {
return libraries return libraries
.Select(n => _libraryManager.GetLibraryInformation(n)) .Select(n => _libraryManager.GetLibraryInformation(n))
.SelectMany(n => n.LoadableAssemblies) .SelectMany(n => n.Assemblies)
.Distinct() .Distinct()
.Select(n => n.Name); .Select(n => n.Name);
} }

View File

@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
} }
protected override IEnumerable<ILibraryInformation> GetCandidateLibraries() protected override IEnumerable<Library> GetCandidateLibraries()
{ {
var libraries = base.GetCandidateLibraries(); var libraries = base.GetCandidateLibraries();
// Filter out other WebSite projects // Filter out other WebSite projects

View File

@ -28,9 +28,9 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
get { return _applicationName; } get { return _applicationName; }
} }
public string Version public string ApplicationVersion
{ {
get { return _originalAppEnvironment.Version; } get { return _originalAppEnvironment.ApplicationVersion; }
} }
public string ApplicationBasePath public string ApplicationBasePath

View File

@ -1,7 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;
using Moq; using Moq;
using Xunit; using Xunit;
@ -13,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
public void EnsureSuccessful_ThrowsIfCompilationFailed() public void EnsureSuccessful_ThrowsIfCompilationFailed()
{ {
// Arrange // Arrange
var compilationFailure = Mock.Of<ICompilationFailure>(); var compilationFailure = new CompilationFailure("test", Enumerable.Empty<Framework.Runtime.DiagnosticMessage>());
var failures = new[] { compilationFailure }; var failures = new[] { compilationFailure };
var result = CompilationResult.Failed(failures); var result = CompilationResult.Failed(failures);

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
public class MyTestType {}"; public class MyTestType {}";
var applicationEnvironment = GetApplicationEnvironment(); var applicationEnvironment = GetApplicationEnvironment();
var accessor = GetLoadContextAccessor(); var accessor = GetLoadContextAccessor();
var libraryManager = GetLibraryManager(); var libraryExporter = GetLibraryExporter();
var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>(); var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>();
compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName, compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName,
@ -39,7 +39,7 @@ public class MyTestType {}";
var compilationService = new RoslynCompilationService(applicationEnvironment, var compilationService = new RoslynCompilationService(applicationEnvironment,
accessor, accessor,
libraryManager, libraryExporter,
compilerOptionsProvider.Object, compilerOptionsProvider.Object,
mvcRazorHost.Object, mvcRazorHost.Object,
GetOptions()); GetOptions());
@ -66,7 +66,7 @@ public class MyTestType {}";
this should fail"; this should fail";
var applicationEnvironment = GetApplicationEnvironment(); var applicationEnvironment = GetApplicationEnvironment();
var accessor = GetLoadContextAccessor(); var accessor = GetLoadContextAccessor();
var libraryManager = GetLibraryManager(); var libraryExporter = GetLibraryExporter();
var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>(); var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>();
compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName, compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName,
@ -79,7 +79,7 @@ this should fail";
var compilationService = new RoslynCompilationService(applicationEnvironment, var compilationService = new RoslynCompilationService(applicationEnvironment,
accessor, accessor,
libraryManager, libraryExporter,
compilerOptionsProvider.Object, compilerOptionsProvider.Object,
mvcRazorHost, mvcRazorHost,
GetOptions(fileProvider)); GetOptions(fileProvider));
@ -104,7 +104,7 @@ this should fail";
var content = @"this should fail"; var content = @"this should fail";
var applicationEnvironment = GetApplicationEnvironment(); var applicationEnvironment = GetApplicationEnvironment();
var accessor = GetLoadContextAccessor(); var accessor = GetLoadContextAccessor();
var libraryManager = GetLibraryManager(); var libraryExporter = GetLibraryExporter();
var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>(); var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>();
compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName, compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName,
@ -115,7 +115,7 @@ this should fail";
var compilationService = new RoslynCompilationService(applicationEnvironment, var compilationService = new RoslynCompilationService(applicationEnvironment,
accessor, accessor,
libraryManager, libraryExporter,
compilerOptionsProvider.Object, compilerOptionsProvider.Object,
mvcRazorHost, mvcRazorHost,
GetOptions()); GetOptions());
@ -144,7 +144,7 @@ this should fail";
this should fail"; this should fail";
var applicationEnvironment = GetApplicationEnvironment(); var applicationEnvironment = GetApplicationEnvironment();
var accessor = GetLoadContextAccessor(); var accessor = GetLoadContextAccessor();
var libraryManager = GetLibraryManager(); var libraryExporter = GetLibraryExporter();
var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>(); var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>();
compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName, compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName,
@ -161,7 +161,7 @@ this should fail";
var compilationService = new RoslynCompilationService(applicationEnvironment, var compilationService = new RoslynCompilationService(applicationEnvironment,
accessor, accessor,
libraryManager, libraryExporter,
compilerOptionsProvider.Object, compilerOptionsProvider.Object,
mvcRazorHost, mvcRazorHost,
GetOptions(fileProvider)); GetOptions(fileProvider));
@ -192,7 +192,7 @@ public class MyNonCustomDefinedClass {}
"; ";
var applicationEnvironment = GetApplicationEnvironment(); var applicationEnvironment = GetApplicationEnvironment();
var accessor = GetLoadContextAccessor(); var accessor = GetLoadContextAccessor();
var libraryManager = GetLibraryManager(); var libraryExporter = GetLibraryExporter();
var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>(); var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>();
compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName, compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName,
@ -205,7 +205,7 @@ public class MyNonCustomDefinedClass {}
var compilationService = new RoslynCompilationService(applicationEnvironment, var compilationService = new RoslynCompilationService(applicationEnvironment,
accessor, accessor,
libraryManager, libraryExporter,
compilerOptionsProvider.Object, compilerOptionsProvider.Object,
mvcRazorHost.Object, mvcRazorHost.Object,
GetOptions()); GetOptions());
@ -229,7 +229,7 @@ public class RazorPrefixType {}
public class NotRazorPrefixType {}"; public class NotRazorPrefixType {}";
var applicationEnvironment = GetApplicationEnvironment(); var applicationEnvironment = GetApplicationEnvironment();
var accessor = GetLoadContextAccessor(); var accessor = GetLoadContextAccessor();
var libraryManager = GetLibraryManager(); var libraryExporter = GetLibraryExporter();
var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>(); var compilerOptionsProvider = new Mock<ICompilerOptionsProvider>();
compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName, compilerOptionsProvider.Setup(p => p.GetCompilerOptions(applicationEnvironment.ApplicationName,
@ -242,7 +242,7 @@ public class NotRazorPrefixType {}";
var compilationService = new RoslynCompilationService(applicationEnvironment, var compilationService = new RoslynCompilationService(applicationEnvironment,
accessor, accessor,
libraryManager, libraryExporter,
compilerOptionsProvider.Object, compilerOptionsProvider.Object,
mvcRazorHost.Object, mvcRazorHost.Object,
GetOptions()); GetOptions());
@ -275,7 +275,7 @@ public class NotRazorPrefixType {}";
var compilationService = new RoslynCompilationService( var compilationService = new RoslynCompilationService(
GetApplicationEnvironment(), GetApplicationEnvironment(),
GetLoadContextAccessor(), GetLoadContextAccessor(),
GetLibraryManager(), GetLibraryExporter(),
Mock.Of<ICompilerOptionsProvider>(), Mock.Of<ICompilerOptionsProvider>(),
Mock.Of<IMvcRazorHost>(), Mock.Of<IMvcRazorHost>(),
options.Object); options.Object);
@ -365,21 +365,17 @@ public class NotRazorPrefixType {}";
isEnabledByDefault: true); isEnabledByDefault: true);
} }
private static ILibraryManager GetLibraryManager() private static ILibraryExporter GetLibraryExporter()
{ {
var fileReference = new Mock<IMetadataFileReference>(); var fileReference = new Mock<IMetadataFileReference>();
fileReference.SetupGet(f => f.Path) fileReference.SetupGet(f => f.Path)
.Returns(typeof(string).Assembly.Location); .Returns(typeof(string).Assembly.Location);
var libraryExport = new Mock<ILibraryExport>(); var libraryExport = new LibraryExport(fileReference.Object);
libraryExport.SetupGet(e => e.MetadataReferences)
.Returns(new[] { fileReference.Object });
libraryExport.SetupGet(e => e.SourceReferences)
.Returns(new ISourceReference[0]);
var libraryManager = new Mock<ILibraryManager>(); var libraryExporter = new Mock<ILibraryExporter>();
libraryManager.Setup(l => l.GetAllExports(It.IsAny<string>())) libraryExporter.Setup(l => l.GetAllExports(It.IsAny<string>()))
.Returns(libraryExport.Object); .Returns(libraryExport);
return libraryManager.Object; return libraryExporter.Object;
} }
private static IAssemblyLoadContextAccessor GetLoadContextAccessor() private static IAssemblyLoadContextAccessor GetLoadContextAccessor()