Merge branch 'release' into dev
This commit is contained in:
commit
8de0f36bf2
|
|
@ -11,11 +11,11 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.Views;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame;
|
||||
|
||||
namespace Microsoft.AspNetCore.Diagnostics
|
||||
|
|
@ -38,13 +38,13 @@ namespace Microsoft.AspNetCore.Diagnostics
|
|||
/// <param name="next"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="loggerFactory"></param>
|
||||
/// <param name="appEnvironment"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="diagnosticSource"></param>
|
||||
public DeveloperExceptionPageMiddleware(
|
||||
RequestDelegate next,
|
||||
IOptions<DeveloperExceptionPageOptions> options,
|
||||
ILoggerFactory loggerFactory,
|
||||
IApplicationEnvironment appEnvironment,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
DiagnosticSource diagnosticSource)
|
||||
{
|
||||
if (next == null)
|
||||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Diagnostics
|
|||
_next = next;
|
||||
_options = options.Value;
|
||||
_logger = loggerFactory.CreateLogger<DeveloperExceptionPageMiddleware>();
|
||||
_fileProvider = _options.FileProvider ?? new PhysicalFileProvider(appEnvironment.ApplicationBasePath);
|
||||
_fileProvider = _options.FileProvider ?? hostingEnvironment.ContentRootFileProvider;
|
||||
_diagnosticSource = diagnosticSource;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System;
|
|||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
|
|
@ -47,8 +46,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
var runtimeEnvironment = app.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;
|
||||
return app.UseMiddleware<RuntimeInfoMiddleware>(Options.Create(options), runtimeEnvironment);
|
||||
return app.UseMiddleware<RuntimeInfoMiddleware>(Options.Create(options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,18 +18,15 @@ namespace Microsoft.AspNetCore.Diagnostics
|
|||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly RuntimeInfoPageOptions _options;
|
||||
private readonly IRuntimeEnvironment _runtimeEnvironment;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RuntimeInfoMiddleware"/> class
|
||||
/// </summary>
|
||||
/// <param name="next"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="runtimeEnvironment"></param>
|
||||
public RuntimeInfoMiddleware(
|
||||
RequestDelegate next,
|
||||
IOptions<RuntimeInfoPageOptions> options,
|
||||
IRuntimeEnvironment runtimeEnvironment)
|
||||
IOptions<RuntimeInfoPageOptions> options)
|
||||
{
|
||||
if (next == null)
|
||||
{
|
||||
|
|
@ -41,14 +38,8 @@ namespace Microsoft.AspNetCore.Diagnostics
|
|||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
if (runtimeEnvironment == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(runtimeEnvironment));
|
||||
}
|
||||
|
||||
_next = next;
|
||||
_options = options.Value;
|
||||
_runtimeEnvironment = runtimeEnvironment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -69,13 +60,14 @@ namespace Microsoft.AspNetCore.Diagnostics
|
|||
return _next(context);
|
||||
}
|
||||
|
||||
internal RuntimeInfoPageModel CreateRuntimeInfoModel()
|
||||
private static RuntimeInfoPageModel CreateRuntimeInfoModel()
|
||||
{
|
||||
var model = new RuntimeInfoPageModel();
|
||||
model.Version = _runtimeEnvironment.RuntimeVersion;
|
||||
model.OperatingSystem = _runtimeEnvironment.OperatingSystem;
|
||||
model.RuntimeType = _runtimeEnvironment.RuntimeType;
|
||||
model.RuntimeArchitecture = _runtimeEnvironment.RuntimeArchitecture;
|
||||
var runtimeEnvironment = PlatformServices.Default.Runtime;
|
||||
model.Version = runtimeEnvironment.RuntimeVersion;
|
||||
model.OperatingSystem = runtimeEnvironment.OperatingSystem;
|
||||
model.RuntimeType = runtimeEnvironment.RuntimeType;
|
||||
model.RuntimeArchitecture = runtimeEnvironment.RuntimeArchitecture;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
"type": "build",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.WebUtilities": "1.0.0-*",
|
||||
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-*",
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ using Microsoft.Extensions.Options;
|
|||
using Microsoft.Extensions.Primitives;
|
||||
using Xunit;
|
||||
using StackFrame = Microsoft.AspNetCore.Diagnostics.Views.StackFrame;
|
||||
using Moq;
|
||||
|
||||
namespace Microsoft.AspNetCore.Diagnostics
|
||||
{
|
||||
|
|
@ -309,73 +310,12 @@ namespace Microsoft.AspNetCore.Diagnostics
|
|||
(httpContext) => { return Task.FromResult(0); },
|
||||
Options.Create(options),
|
||||
new LoggerFactory(),
|
||||
new TestApplicationEnvironment(),
|
||||
Mock.Of<IHostingEnvironment>(),
|
||||
new DiagnosticListener("Microsoft.Aspnet"));
|
||||
|
||||
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 readonly IEnumerable<string> _sourceCodeLines;
|
||||
|
|
|
|||
|
|
@ -27,42 +27,10 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
|
|||
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]
|
||||
public async void Invoke_WithNonMatchingPath_IgnoresRequest()
|
||||
{
|
||||
// Arrange
|
||||
var runtimeEnvironmentMock = new Mock<IRuntimeEnvironment>(MockBehavior.Strict);
|
||||
|
||||
RequestDelegate next = _ =>
|
||||
{
|
||||
return Task.FromResult<object>(null);
|
||||
|
|
@ -70,8 +38,7 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
|
|||
|
||||
var middleware = new RuntimeInfoMiddleware(
|
||||
next,
|
||||
Options.Create(new RuntimeInfoPageOptions()),
|
||||
runtimeEnvironmentMock.Object);
|
||||
Options.Create(new RuntimeInfoPageOptions()));
|
||||
|
||||
var contextMock = new Mock<HttpContext>(MockBehavior.Strict);
|
||||
contextMock
|
||||
|
|
@ -89,21 +56,15 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
|
|||
public async void Invoke_WithMatchingPath_ReturnsInfoPage()
|
||||
{
|
||||
// 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 = _ =>
|
||||
{
|
||||
return Task.FromResult<object>(null);
|
||||
};
|
||||
var runtimeEnvironment = PlatformServices.Default.Runtime;
|
||||
|
||||
var middleware = new RuntimeInfoMiddleware(
|
||||
next,
|
||||
Options.Create(new RuntimeInfoPageOptions()),
|
||||
runtimeEnvironmentMock.Object);
|
||||
Options.Create(new RuntimeInfoPageOptions()));
|
||||
|
||||
var buffer = new byte[4096];
|
||||
using (var responseStream = new MemoryStream(buffer))
|
||||
|
|
@ -123,12 +84,12 @@ namespace Microsoft.AspNetCore.Diagnostics.Tests
|
|||
await middleware.Invoke(contextMock.Object);
|
||||
|
||||
// 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>Operating System: Windows</p>", response);
|
||||
Assert.Contains("<p>Runtime Architecture: x64</p>", response);
|
||||
Assert.Contains("<p>Runtime Type: clr</p>", response);
|
||||
Assert.Contains($"<p>Runtime Version: {runtimeEnvironment.RuntimeVersion}</p>", response);
|
||||
Assert.Contains($"<p>Operating System: {runtimeEnvironment.OperatingSystem}</p>", response);
|
||||
Assert.Contains($"<p>Runtime Architecture: {runtimeEnvironment.RuntimeArchitecture}</p>", response);
|
||||
Assert.Contains($"<p>Runtime Type: {runtimeEnvironment.RuntimeType}</p>", response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue