Merge branch 'release' into dev

This commit is contained in:
Pranav K 2016-04-26 10:07:43 -07:00
commit 8de0f36bf2
6 changed files with 23 additions and 131 deletions

View File

@ -11,11 +11,11 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.Views; using Microsoft.AspNetCore.Diagnostics.Views;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.Extensions.PlatformAbstractions;
using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame; using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame;
namespace Microsoft.AspNetCore.Diagnostics namespace Microsoft.AspNetCore.Diagnostics
@ -38,13 +38,13 @@ namespace Microsoft.AspNetCore.Diagnostics
/// <param name="next"></param> /// <param name="next"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <param name="loggerFactory"></param> /// <param name="loggerFactory"></param>
/// <param name="appEnvironment"></param> /// <param name="hostingEnvironment"></param>
/// <param name="diagnosticSource"></param> /// <param name="diagnosticSource"></param>
public DeveloperExceptionPageMiddleware( public DeveloperExceptionPageMiddleware(
RequestDelegate next, RequestDelegate next,
IOptions<DeveloperExceptionPageOptions> options, IOptions<DeveloperExceptionPageOptions> options,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IApplicationEnvironment appEnvironment, IHostingEnvironment hostingEnvironment,
DiagnosticSource diagnosticSource) DiagnosticSource diagnosticSource)
{ {
if (next == null) if (next == null)
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Diagnostics
_next = next; _next = next;
_options = options.Value; _options = options.Value;
_logger = loggerFactory.CreateLogger<DeveloperExceptionPageMiddleware>(); _logger = loggerFactory.CreateLogger<DeveloperExceptionPageMiddleware>();
_fileProvider = _options.FileProvider ?? new PhysicalFileProvider(appEnvironment.ApplicationBasePath); _fileProvider = _options.FileProvider ?? hostingEnvironment.ContentRootFileProvider;
_diagnosticSource = diagnosticSource; _diagnosticSource = diagnosticSource;
} }

View File

@ -5,7 +5,6 @@ using System;
using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.AspNetCore.Builder namespace Microsoft.AspNetCore.Builder
{ {
@ -47,8 +46,7 @@ namespace Microsoft.AspNetCore.Builder
throw new ArgumentNullException(nameof(options)); throw new ArgumentNullException(nameof(options));
} }
var runtimeEnvironment = app.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment; return app.UseMiddleware<RuntimeInfoMiddleware>(Options.Create(options));
return app.UseMiddleware<RuntimeInfoMiddleware>(Options.Create(options), runtimeEnvironment);
} }
} }
} }

View File

@ -18,18 +18,15 @@ namespace Microsoft.AspNetCore.Diagnostics
{ {
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
private readonly RuntimeInfoPageOptions _options; private readonly RuntimeInfoPageOptions _options;
private readonly IRuntimeEnvironment _runtimeEnvironment;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RuntimeInfoMiddleware"/> class /// Initializes a new instance of the <see cref="RuntimeInfoMiddleware"/> class
/// </summary> /// </summary>
/// <param name="next"></param> /// <param name="next"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <param name="runtimeEnvironment"></param>
public RuntimeInfoMiddleware( public RuntimeInfoMiddleware(
RequestDelegate next, RequestDelegate next,
IOptions<RuntimeInfoPageOptions> options, IOptions<RuntimeInfoPageOptions> options)
IRuntimeEnvironment runtimeEnvironment)
{ {
if (next == null) if (next == null)
{ {
@ -41,14 +38,8 @@ namespace Microsoft.AspNetCore.Diagnostics
throw new ArgumentNullException(nameof(options)); throw new ArgumentNullException(nameof(options));
} }
if (runtimeEnvironment == null)
{
throw new ArgumentNullException(nameof(runtimeEnvironment));
}
_next = next; _next = next;
_options = options.Value; _options = options.Value;
_runtimeEnvironment = runtimeEnvironment;
} }
/// <summary> /// <summary>
@ -69,13 +60,14 @@ namespace Microsoft.AspNetCore.Diagnostics
return _next(context); return _next(context);
} }
internal RuntimeInfoPageModel CreateRuntimeInfoModel() private static RuntimeInfoPageModel CreateRuntimeInfoModel()
{ {
var model = new RuntimeInfoPageModel(); var model = new RuntimeInfoPageModel();
model.Version = _runtimeEnvironment.RuntimeVersion; var runtimeEnvironment = PlatformServices.Default.Runtime;
model.OperatingSystem = _runtimeEnvironment.OperatingSystem; model.Version = runtimeEnvironment.RuntimeVersion;
model.RuntimeType = _runtimeEnvironment.RuntimeType; model.OperatingSystem = runtimeEnvironment.OperatingSystem;
model.RuntimeArchitecture = _runtimeEnvironment.RuntimeArchitecture; model.RuntimeType = runtimeEnvironment.RuntimeType;
model.RuntimeArchitecture = runtimeEnvironment.RuntimeArchitecture;
return model; return model;
} }
} }

View File

@ -23,6 +23,7 @@
"type": "build", "type": "build",
"version": "1.0.0-*" "version": "1.0.0-*"
}, },
"Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0-*",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-*", "Microsoft.AspNetCore.Http.Extensions": "1.0.0-*",
"Microsoft.AspNetCore.WebUtilities": "1.0.0-*", "Microsoft.AspNetCore.WebUtilities": "1.0.0-*",
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-*", "Microsoft.Extensions.FileProviders.Physical": "1.0.0-*",

View File

@ -23,6 +23,7 @@ using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Xunit; using Xunit;
using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame; using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame;
using Moq;
namespace Microsoft.AspNetCore.Diagnostics namespace Microsoft.AspNetCore.Diagnostics
{ {
@ -309,73 +310,12 @@ namespace Microsoft.AspNetCore.Diagnostics
(httpContext) => { return Task.FromResult(0); }, (httpContext) => { return Task.FromResult(0); },
Options.Create(options), Options.Create(options),
new LoggerFactory(), new LoggerFactory(),
new TestApplicationEnvironment(), Mock.Of<IHostingEnvironment>(),
new DiagnosticListener("Microsoft.Aspnet")); new DiagnosticListener("Microsoft.Aspnet"));
return middleware; return middleware;
} }
private class TestApplicationEnvironment : IApplicationEnvironment
{
public string ApplicationBasePath
{
get
{
return Directory.GetCurrentDirectory();
}
}
public string ApplicationName
{
get
{
throw new NotImplementedException();
}
}
public string ApplicationVersion
{
get
{
throw new NotImplementedException();
}
}
public string Configuration
{
get
{
throw new NotImplementedException();
}
}
public FrameworkName RuntimeFramework
{
get
{
throw new NotImplementedException();
}
}
public string Version
{
get
{
throw new NotImplementedException();
}
}
public object GetData(string name)
{
throw new NotImplementedException();
}
public void SetData(string name, object value)
{
throw new NotImplementedException();
}
}
private class TestFileProvider : IFileProvider private class TestFileProvider : IFileProvider
{ {
private readonly IEnumerable<string> _sourceCodeLines; private readonly IEnumerable<string> _sourceCodeLines;

View File

@ -27,42 +27,10 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
Assert.Equal(DefaultPath, options.Path.Value); Assert.Equal(DefaultPath, options.Path.Value);
} }
[Fact]
public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages()
{
// Arrage
var runtimeEnvironmentMock = new Mock<IRuntimeEnvironment>(MockBehavior.Strict);
runtimeEnvironmentMock.Setup(r => r.OperatingSystem).Returns("Windows");
runtimeEnvironmentMock.Setup(r => r.RuntimeArchitecture).Returns("x64");
runtimeEnvironmentMock.Setup(r => r.RuntimeType).Returns("clr");
runtimeEnvironmentMock.Setup(r => r.RuntimeVersion).Returns("1.0.0");
RequestDelegate next = _ =>
{
return Task.FromResult<object>(null);
};
var middleware = new RuntimeInfoMiddleware(
next,
Options.Create(new RuntimeInfoPageOptions()),
runtimeEnvironmentMock.Object);
// Act
var model = middleware.CreateRuntimeInfoModel();
// Assert
Assert.Equal("1.0.0", model.Version);
Assert.Equal("Windows", model.OperatingSystem);
Assert.Equal("clr", model.RuntimeType);
Assert.Equal("x64", model.RuntimeArchitecture);
}
[Fact] [Fact]
public async void Invoke_WithNonMatchingPath_IgnoresRequest() public async void Invoke_WithNonMatchingPath_IgnoresRequest()
{ {
// Arrange // Arrange
var runtimeEnvironmentMock = new Mock<IRuntimeEnvironment>(MockBehavior.Strict);
RequestDelegate next = _ => RequestDelegate next = _ =>
{ {
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
@ -70,8 +38,7 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
var middleware = new RuntimeInfoMiddleware( var middleware = new RuntimeInfoMiddleware(
next, next,
Options.Create(new RuntimeInfoPageOptions()), Options.Create(new RuntimeInfoPageOptions()));
runtimeEnvironmentMock.Object);
var contextMock = new Mock<HttpContext>(MockBehavior.Strict); var contextMock = new Mock<HttpContext>(MockBehavior.Strict);
contextMock contextMock
@ -89,21 +56,15 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
public async void Invoke_WithMatchingPath_ReturnsInfoPage() public async void Invoke_WithMatchingPath_ReturnsInfoPage()
{ {
// Arrange // Arrange
var runtimeEnvironmentMock = new Mock<IRuntimeEnvironment>(MockBehavior.Strict);
runtimeEnvironmentMock.Setup(r => r.OperatingSystem).Returns("Windows");
runtimeEnvironmentMock.Setup(r => r.RuntimeArchitecture).Returns("x64");
runtimeEnvironmentMock.Setup(r => r.RuntimeType).Returns("clr");
runtimeEnvironmentMock.Setup(r => r.RuntimeVersion).Returns("1.0.0");
RequestDelegate next = _ => RequestDelegate next = _ =>
{ {
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
}; };
var runtimeEnvironment = PlatformServices.Default.Runtime;
var middleware = new RuntimeInfoMiddleware( var middleware = new RuntimeInfoMiddleware(
next, next,
Options.Create(new RuntimeInfoPageOptions()), Options.Create(new RuntimeInfoPageOptions()));
runtimeEnvironmentMock.Object);
var buffer = new byte[4096]; var buffer = new byte[4096];
using (var responseStream = new MemoryStream(buffer)) using (var responseStream = new MemoryStream(buffer))
@ -123,12 +84,12 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
await middleware.Invoke(contextMock.Object); await middleware.Invoke(contextMock.Object);
// Assert // Assert
string response = Encoding.UTF8.GetString(buffer); var response = Encoding.UTF8.GetString(buffer);
Assert.Contains("<p>Runtime Version: 1.0.0</p>", response); Assert.Contains($"<p>Runtime Version: {runtimeEnvironment.RuntimeVersion}</p>", response);
Assert.Contains("<p>Operating System: Windows</p>", response); Assert.Contains($"<p>Operating System: {runtimeEnvironment.OperatingSystem}</p>", response);
Assert.Contains("<p>Runtime Architecture: x64</p>", response); Assert.Contains($"<p>Runtime Architecture: {runtimeEnvironment.RuntimeArchitecture}</p>", response);
Assert.Contains("<p>Runtime Type: clr</p>", response); Assert.Contains($"<p>Runtime Type: {runtimeEnvironment.RuntimeType}</p>", response);
} }
} }
} }