Fixing runtime info middleware on coreclr

Also adding more information like OS, runtime type and architecture to the info page.
This commit is contained in:
Praburaj 2015-04-16 14:43:23 -07:00
parent 3b2ded5652
commit b27c6fc1e2
10 changed files with 273 additions and 65 deletions

View File

@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity
} }
/// <summary> /// <summary>
/// &gt; k ef migration add [migration name] /// &gt; dnx . ef migration add [migration name]
/// </summary> /// </summary>
internal static string DatabaseErrorPage_AddMigrationCommand internal static string DatabaseErrorPage_AddMigrationCommand
{ {
@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity
} }
/// <summary> /// <summary>
/// &gt; k ef migration add [migration name] /// &gt; dnx . ef migration add [migration name]
/// </summary> /// </summary>
internal static string FormatDatabaseErrorPage_AddMigrationCommand() internal static string FormatDatabaseErrorPage_AddMigrationCommand()
{ {
@ -203,7 +203,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity
} }
/// <summary> /// <summary>
/// &gt; k ef migration apply /// &gt; dnx . ef migration apply
/// </summary> /// </summary>
internal static string DatabaseErrorPage_ApplyMigrationsCommand internal static string DatabaseErrorPage_ApplyMigrationsCommand
{ {
@ -211,7 +211,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity
} }
/// <summary> /// <summary>
/// &gt; k ef migration apply /// &gt; dnx . ef migration apply
/// </summary> /// </summary>
internal static string FormatDatabaseErrorPage_ApplyMigrationsCommand() internal static string FormatDatabaseErrorPage_ApplyMigrationsCommand()
{ {

View File

@ -586,6 +586,118 @@ namespace Microsoft.AspNet.Diagnostics
return GetString("ErrorPageHtml_CompilationException"); return GetString("ErrorPageHtml_CompilationException");
} }
/// <summary>
/// Operating System:
/// </summary>
internal static string RuntimeInfoPage_OperatingSystem
{
get { return GetString("RuntimeInfoPage_OperatingSystem"); }
}
/// <summary>
/// Operating System:
/// </summary>
internal static string FormatRuntimeInfoPage_OperatingSystem()
{
return GetString("RuntimeInfoPage_OperatingSystem");
}
/// <summary>
/// Runtime Architecture:
/// </summary>
internal static string RuntimeInfoPage_RuntimeArchitecture
{
get { return GetString("RuntimeInfoPage_RuntimeArchitecture"); }
}
/// <summary>
/// Runtime Architecture:
/// </summary>
internal static string FormatRuntimeInfoPage_RuntimeArchitecture()
{
return GetString("RuntimeInfoPage_RuntimeArchitecture");
}
/// <summary>
/// Runtime Type:
/// </summary>
internal static string RuntimeInfoPage_RuntimeType
{
get { return GetString("RuntimeInfoPage_RuntimeType"); }
}
/// <summary>
/// Runtime Type:
/// </summary>
internal static string FormatRuntimeInfoPage_RuntimeType()
{
return GetString("RuntimeInfoPage_RuntimeType");
}
/// <summary>
/// Could not determine the operating system.
/// </summary>
internal static string RuntimeInfoPage_OperatingSystemFail
{
get { return GetString("RuntimeInfoPage_OperatingSystemFail"); }
}
/// <summary>
/// Could not determine the operating system.
/// </summary>
internal static string FormatRuntimeInfoPage_OperatingSystemFail()
{
return GetString("RuntimeInfoPage_OperatingSystemFail");
}
/// <summary>
/// Could not determine the runtime architecture.
/// </summary>
internal static string RuntimeInfoPage_RuntimeArchitectureFail
{
get { return GetString("RuntimeInfoPage_RuntimeArchitectureFail"); }
}
/// <summary>
/// Could not determine the runtime architecture.
/// </summary>
internal static string FormatRuntimeInfoPage_RuntimeArchitectureFail()
{
return GetString("RuntimeInfoPage_RuntimeArchitectureFail");
}
/// <summary>
/// Could not determine the runtime type.
/// </summary>
internal static string RuntimeInfoPage_RuntimeTypeFail
{
get { return GetString("RuntimeInfoPage_RuntimeTypeFail"); }
}
/// <summary>
/// Could not determine the runtime type.
/// </summary>
internal static string FormatRuntimeInfoPage_RuntimeTypeFail()
{
return GetString("RuntimeInfoPage_RuntimeTypeFail");
}
/// <summary>
/// Environment:
/// </summary>
internal static string RuntimeInfoPage_Environment
{
get { return GetString("RuntimeInfoPage_Environment"); }
}
/// <summary>
/// Environment:
/// </summary>
internal static string FormatRuntimeInfoPage_Environment()
{
return GetString("RuntimeInfoPage_Environment");
}
private static string GetString(string name, params string[] formatterNames) private static string GetString(string name, params string[] formatterNames)
{ {
var value = _resourceManager.GetString(name); var value = _resourceManager.GetString(name);

View File

@ -233,4 +233,25 @@
<data name="ErrorPageHtml_CompilationException" xml:space="preserve"> <data name="ErrorPageHtml_CompilationException" xml:space="preserve">
<value>An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.</value> <value>An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.</value>
</data> </data>
<data name="RuntimeInfoPage_OperatingSystem" xml:space="preserve">
<value>Operating System:</value>
</data>
<data name="RuntimeInfoPage_RuntimeArchitecture" xml:space="preserve">
<value>Runtime Architecture:</value>
</data>
<data name="RuntimeInfoPage_RuntimeType" xml:space="preserve">
<value>Runtime Type:</value>
</data>
<data name="RuntimeInfoPage_OperatingSystemFail" xml:space="preserve">
<value>Could not determine the operating system.</value>
</data>
<data name="RuntimeInfoPage_RuntimeArchitectureFail" xml:space="preserve">
<value>Could not determine the runtime architecture.</value>
</data>
<data name="RuntimeInfoPage_RuntimeTypeFail" xml:space="preserve">
<value>Could not determine the runtime type.</value>
</data>
<data name="RuntimeInfoPage_Environment" xml:space="preserve">
<value>Environment:</value>
</data>
</root> </root>

View File

@ -25,7 +25,8 @@ namespace Microsoft.AspNet.Builder
[NotNull] RuntimeInfoPageOptions options) [NotNull] RuntimeInfoPageOptions options)
{ {
var libraryManager = builder.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager; var libraryManager = builder.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager;
return builder.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager).Invoke); var runtimeEnvironment = builder.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;
return builder.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
} }
} }
} }

View File

@ -1,15 +1,12 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. 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;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Views; using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Runtime;
using System.Linq;
using System.Reflection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime;
namespace Microsoft.AspNet.Diagnostics namespace Microsoft.AspNet.Diagnostics
{ {
@ -21,6 +18,7 @@ namespace Microsoft.AspNet.Diagnostics
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
private readonly RuntimeInfoPageOptions _options; private readonly RuntimeInfoPageOptions _options;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
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
@ -30,11 +28,13 @@ namespace Microsoft.AspNet.Diagnostics
public RuntimeInfoMiddleware( public RuntimeInfoMiddleware(
[NotNull] RequestDelegate next, [NotNull] RequestDelegate next,
[NotNull] RuntimeInfoPageOptions options, [NotNull] RuntimeInfoPageOptions options,
[NotNull] ILibraryManager libraryManager) [NotNull] ILibraryManager libraryManager,
[NotNull] IRuntimeEnvironment runtimeEnvironment)
{ {
_next = next; _next = next;
_options = options; _options = options;
_libraryManager = libraryManager; _libraryManager = libraryManager;
_runtimeEnvironment = runtimeEnvironment;
} }
/// <summary> /// <summary>
@ -59,16 +59,11 @@ namespace Microsoft.AspNet.Diagnostics
{ {
var model = new RuntimeInfoPageModel(); var model = new RuntimeInfoPageModel();
model.References = _libraryManager.GetLibraries(); model.References = _libraryManager.GetLibraries();
model.Version = GetRuntimeVersion(); model.Version = _runtimeEnvironment.RuntimeVersion;
model.OperatingSystem = _runtimeEnvironment.OperatingSystem;
model.RuntimeType = _runtimeEnvironment.RuntimeType;
model.RuntimeArchitecture = _runtimeEnvironment.RuntimeArchitecture;
return model; return model;
} }
private static string GetRuntimeVersion()
{
var klr = Assembly.Load(new AssemblyName("dnx.host"));
var version = klr.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
return version?.InformationalVersion;
}
} }
} }

View File

@ -70,32 +70,74 @@ using Microsoft.Framework.Runtime;
#line default #line default
#line hidden #line hidden
WriteLiteral("</title>\r\n <style>\r\n body {\r\n font-family: 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;\r\n font-size: .813em;\r\n line-height: 1.4em;\r\n color: #222;\r\n}\r\n\r\nh1, h2, h3, h4, h5, th {\r\n font-weight: 100;\r\n}\r\n\r\nh1 {\r\n color: #44525e;\r\n margin: 15px 0 15px 0;\r\n}\r\n\r\nh2 {\r\n margin: 10px 5px 0 0;\r\n}\r\n\r\ntable .even{\r\n background-color: #f0f0f0;\r\n}\r\n\r\nth {\r\n font-size: 16px;\r\n}\r\n\r\n\r\n\r\n </style>\r" + WriteLiteral("</title>\r\n <style>\r\n body {\r\n font-family: 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;\r\n font-size: .813em;\r\n line-height: 1.4em;\r\n color: #222;\r\n}\r\n\r\nh1, h2, h3, h4, h5, th {\r\n font-weight: 100;\r\n}\r\n\r\nh1 {\r\n color: #44525e;\r\n margin: 15px 0 15px 0;\r\n}\r\n\r\nh2 {\r\n margin: 10px 5px 0 0;\r\n}\r\n\r\ntable .even{\r\n background-color: #f0f0f0;\r\n}\r\n\r\nth {\r\n font-size: 16px;\r\n}\r\n\r\n\r\n\r\n </style>\r" +
"\n</head>\r\n<body>\r\n <h1>"); "\n</head>\r\n<body>\r\n <h2>");
#line 27 "RuntimeInfoPage.cshtml" #line 27 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_RuntimeVersion); Write(Resources.RuntimeInfoPage_Environment);
#line default #line default
#line hidden #line hidden
WriteLiteral("</h1>\r\n <h2>"); WriteLiteral("</h2>\r\n <p>");
#line 28 "RuntimeInfoPage.cshtml" #line 28 "RuntimeInfoPage.cshtml"
Write(string.IsNullOrWhiteSpace(Model.Version) ? Resources.RuntimeInfoPage_RuntimeVersionFail : Model.Version); Write(Resources.RuntimeInfoPage_OperatingSystem);
#line default #line default
#line hidden #line hidden
WriteLiteral("</h2>\r\n \r\n <h1>"); WriteLiteral(" ");
#line 28 "RuntimeInfoPage.cshtml"
Write(string.IsNullOrWhiteSpace(Model.OperatingSystem) ? Resources.RuntimeInfoPage_OperatingSystemFail : Model.OperatingSystem);
#line default
#line hidden
WriteLiteral("</p>\r\n \r\n <p>");
#line 30 "RuntimeInfoPage.cshtml" #line 30 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_RuntimeVersion);
#line default
#line hidden
WriteLiteral(" ");
#line 30 "RuntimeInfoPage.cshtml"
Write(string.IsNullOrWhiteSpace(Model.Version) ? Resources.RuntimeInfoPage_RuntimeVersionFail : Model.Version);
#line default
#line hidden
WriteLiteral("</p>\r\n\r\n <p>");
#line 32 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_RuntimeArchitecture);
#line default
#line hidden
WriteLiteral(" ");
#line 32 "RuntimeInfoPage.cshtml"
Write(string.IsNullOrWhiteSpace(Model.RuntimeArchitecture) ? Resources.RuntimeInfoPage_RuntimeArchitectureFail : Model.RuntimeArchitecture);
#line default
#line hidden
WriteLiteral("</p>\r\n\r\n <p>");
#line 34 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_RuntimeType);
#line default
#line hidden
WriteLiteral(" ");
#line 34 "RuntimeInfoPage.cshtml"
Write(string.IsNullOrWhiteSpace(Model.RuntimeType) ? Resources.RuntimeInfoPage_RuntimeTypeFail : Model.RuntimeType);
#line default
#line hidden
WriteLiteral("</p>\r\n \r\n <h2>");
#line 36 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_Packages); Write(Resources.RuntimeInfoPage_Packages);
#line default #line default
#line hidden #line hidden
WriteLiteral("</h1>\r\n"); WriteLiteral("</h2>\r\n");
#line 31 "RuntimeInfoPage.cshtml" #line 37 "RuntimeInfoPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 31 "RuntimeInfoPage.cshtml" #line 37 "RuntimeInfoPage.cshtml"
if (@Resources.RuntimeInfoPage_Packages == null) if (@Resources.RuntimeInfoPage_Packages == null)
{ {
@ -103,13 +145,13 @@ using Microsoft.Framework.Runtime;
#line hidden #line hidden
WriteLiteral(" <h2>"); WriteLiteral(" <h2>");
#line 33 "RuntimeInfoPage.cshtml" #line 39 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackagesFail); Write(Resources.RuntimeInfoPage_PackagesFail);
#line default #line default
#line hidden #line hidden
WriteLiteral("</h2>\r\n"); WriteLiteral("</h2>\r\n");
#line 34 "RuntimeInfoPage.cshtml" #line 40 "RuntimeInfoPage.cshtml"
} }
else else
{ {
@ -119,44 +161,44 @@ using Microsoft.Framework.Runtime;
WriteLiteral(" <table>\r\n <thead>\r\n <tr>\r\n <" + WriteLiteral(" <table>\r\n <thead>\r\n <tr>\r\n <" +
"th>"); "th>");
#line 40 "RuntimeInfoPage.cshtml" #line 46 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackageNameColumnName); Write(Resources.RuntimeInfoPage_PackageNameColumnName);
#line default #line default
#line hidden #line hidden
WriteLiteral("</th>\r\n <th>"); WriteLiteral("</th>\r\n <th>");
#line 41 "RuntimeInfoPage.cshtml" #line 47 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackageVersionColumnName); Write(Resources.RuntimeInfoPage_PackageVersionColumnName);
#line default #line default
#line hidden #line hidden
WriteLiteral("</th>\r\n <th>"); WriteLiteral("</th>\r\n <th>");
#line 42 "RuntimeInfoPage.cshtml" #line 48 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackagePathColumnName); Write(Resources.RuntimeInfoPage_PackagePathColumnName);
#line default #line default
#line hidden #line hidden
WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n"); WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n");
#line 46 "RuntimeInfoPage.cshtml" #line 52 "RuntimeInfoPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 46 "RuntimeInfoPage.cshtml" #line 52 "RuntimeInfoPage.cshtml"
bool even = false; bool even = false;
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n"); WriteLiteral("\r\n");
#line 47 "RuntimeInfoPage.cshtml" #line 53 "RuntimeInfoPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 47 "RuntimeInfoPage.cshtml" #line 53 "RuntimeInfoPage.cshtml"
foreach (var package in Model.References.OrderBy(package => package.Name.ToLowerInvariant())) foreach (var package in Model.References.OrderBy(package => package.Name.ToLowerInvariant()))
{ {
@ -164,40 +206,40 @@ using Microsoft.Framework.Runtime;
#line hidden #line hidden
WriteLiteral(" <tr"); WriteLiteral(" <tr");
WriteAttribute("class", Tuple.Create(" class=\"", 1576), Tuple.Create("\"", 1604), WriteAttribute("class", Tuple.Create(" class=\"", 2160), Tuple.Create("\"", 2188),
Tuple.Create(Tuple.Create("", 1584), Tuple.Create<System.Object, System.Int32>(even?"even":"odd", 1584), false)); Tuple.Create(Tuple.Create("", 2168), Tuple.Create<System.Object, System.Int32>(even?"even":"odd", 2168), false));
WriteLiteral(">\r\n <td>"); WriteLiteral(">\r\n <td>");
#line 50 "RuntimeInfoPage.cshtml" #line 56 "RuntimeInfoPage.cshtml"
Write(package.Name); Write(package.Name);
#line default #line default
#line hidden #line hidden
WriteLiteral("</td>\r\n <td>"); WriteLiteral("</td>\r\n <td>");
#line 51 "RuntimeInfoPage.cshtml" #line 57 "RuntimeInfoPage.cshtml"
Write(package.Version); Write(package.Version);
#line default #line default
#line hidden #line hidden
WriteLiteral("</td>\r\n <td>"); WriteLiteral("</td>\r\n <td>");
#line 52 "RuntimeInfoPage.cshtml" #line 58 "RuntimeInfoPage.cshtml"
Write(package.Path); Write(package.Path);
#line default #line default
#line hidden #line hidden
WriteLiteral("</td>\r\n </tr>\r\n"); WriteLiteral("</td>\r\n </tr>\r\n");
#line 54 "RuntimeInfoPage.cshtml" #line 60 "RuntimeInfoPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 54 "RuntimeInfoPage.cshtml" #line 60 "RuntimeInfoPage.cshtml"
even = !even; even = !even;
#line default #line default
#line hidden #line hidden
#line 54 "RuntimeInfoPage.cshtml" #line 60 "RuntimeInfoPage.cshtml"
} }
@ -205,7 +247,7 @@ using Microsoft.Framework.Runtime;
#line hidden #line hidden
WriteLiteral(" </tbody>\r\n </table>\r\n"); WriteLiteral(" </tbody>\r\n </table>\r\n");
#line 58 "RuntimeInfoPage.cshtml" #line 64 "RuntimeInfoPage.cshtml"
} }
#line default #line default

View File

@ -24,10 +24,16 @@
</style> </style>
</head> </head>
<body> <body>
<h1>@Resources.RuntimeInfoPage_RuntimeVersion</h1> <h2>@Resources.RuntimeInfoPage_Environment</h2>
<h2>@(string.IsNullOrWhiteSpace(Model.Version) ? Resources.RuntimeInfoPage_RuntimeVersionFail : Model.Version)</h2> <p>@Resources.RuntimeInfoPage_OperatingSystem @(string.IsNullOrWhiteSpace(Model.OperatingSystem) ? Resources.RuntimeInfoPage_OperatingSystemFail : Model.OperatingSystem)</p>
<h1>@Resources.RuntimeInfoPage_Packages</h1> <p>@Resources.RuntimeInfoPage_RuntimeVersion @(string.IsNullOrWhiteSpace(Model.Version) ? Resources.RuntimeInfoPage_RuntimeVersionFail : Model.Version)</p>
<p>@Resources.RuntimeInfoPage_RuntimeArchitecture @(string.IsNullOrWhiteSpace(Model.RuntimeArchitecture) ? Resources.RuntimeInfoPage_RuntimeArchitectureFail : Model.RuntimeArchitecture)</p>
<p>@Resources.RuntimeInfoPage_RuntimeType @(string.IsNullOrWhiteSpace(Model.RuntimeType) ? Resources.RuntimeInfoPage_RuntimeTypeFail : Model.RuntimeType)</p>
<h2>@Resources.RuntimeInfoPage_Packages</h2>
@if (@Resources.RuntimeInfoPage_Packages == null) @if (@Resources.RuntimeInfoPage_Packages == null)
{ {
<h2>@Resources.RuntimeInfoPage_PackagesFail</h2> <h2>@Resources.RuntimeInfoPage_PackagesFail</h2>

View File

@ -1,9 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. 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;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
namespace Microsoft.AspNet.Diagnostics.Views namespace Microsoft.AspNet.Diagnostics.Views
@ -12,6 +10,12 @@ namespace Microsoft.AspNet.Diagnostics.Views
{ {
public string Version { get; internal set; } public string Version { get; internal set; }
public string OperatingSystem { get; internal set; }
public string RuntimeArchitecture { get; internal set; }
public string RuntimeType { get; internal set; }
public IEnumerable<ILibraryInformation> References { get; internal set; } public IEnumerable<ILibraryInformation> References { get; internal set; }
} }
} }

View File

@ -54,9 +54,6 @@ namespace PageGenerator
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("{0} files successfully generated.", fileCount); Console.WriteLine("{0} files successfully generated.", fileCount);
Console.WriteLine(); Console.WriteLine();
Console.Write("Press enter to close application...");
Console.ReadLine();
} }
private static IEnumerable<string> GetCshtmlFiles(string path) private static IEnumerable<string> GetCshtmlFiles(string path)

View File

@ -46,6 +46,12 @@ namespace Microsoft.AspNet.Diagnostics.Tests
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict); var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict);
libraryManagerMock.Setup(l => l.GetLibraries()).Returns(libraries); libraryManagerMock.Setup(l => l.GetLibraries()).Returns(libraries);
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);
@ -54,13 +60,17 @@ namespace Microsoft.AspNet.Diagnostics.Tests
var middleware = new RuntimeInfoMiddleware( var middleware = new RuntimeInfoMiddleware(
next, next,
new RuntimeInfoPageOptions(), new RuntimeInfoPageOptions(),
libraryManagerMock.Object); libraryManagerMock.Object,
runtimeEnvironmentMock.Object);
// Act // Act
var model = middleware.CreateRuntimeInfoModel(); var model = middleware.CreateRuntimeInfoModel();
// Assert // Assert
Assert.False(string.IsNullOrWhiteSpace(model.Version)); Assert.Equal("1.0.0", model.Version);
Assert.Equal("Windows", model.OperatingSystem);
Assert.Equal("clr", model.RuntimeType);
Assert.Equal("x64", model.RuntimeArchitecture);
Assert.Same(libraries, model.References); Assert.Same(libraries, model.References);
} }
@ -69,6 +79,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests
{ {
// Arrange // Arrange
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict); var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict);
var runtimeEnvironmentMock = new Mock<IRuntimeEnvironment>(MockBehavior.Strict);
RequestDelegate next = _ => RequestDelegate next = _ =>
{ {
@ -78,7 +89,8 @@ namespace Microsoft.AspNet.Diagnostics.Tests
var middleware = new RuntimeInfoMiddleware( var middleware = new RuntimeInfoMiddleware(
next, next,
new RuntimeInfoPageOptions(), new RuntimeInfoPageOptions(),
libraryManagerMock.Object); libraryManagerMock.Object,
runtimeEnvironmentMock.Object);
var contextMock = new Mock<HttpContext>(MockBehavior.Strict); var contextMock = new Mock<HttpContext>(MockBehavior.Strict);
contextMock contextMock
@ -102,6 +114,12 @@ namespace Microsoft.AspNet.Diagnostics.Tests
new FakeLibraryInformation() { Name ="LibInfo2", Version = "1.0.0-beta2", Path = "Path2" }, new FakeLibraryInformation() { Name ="LibInfo2", Version = "1.0.0-beta2", Path = "Path2" },
}); });
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);
@ -110,7 +128,8 @@ namespace Microsoft.AspNet.Diagnostics.Tests
var middleware = new RuntimeInfoMiddleware( var middleware = new RuntimeInfoMiddleware(
next, next,
new RuntimeInfoPageOptions(), new RuntimeInfoPageOptions(),
libraryManagerMock.Object); libraryManagerMock.Object,
runtimeEnvironmentMock.Object);
var buffer = new byte[4096]; var buffer = new byte[4096];
using (var responseStream = new MemoryStream(buffer)) using (var responseStream = new MemoryStream(buffer))
@ -132,12 +151,16 @@ namespace Microsoft.AspNet.Diagnostics.Tests
// Assert // Assert
string response = Encoding.UTF8.GetString(buffer); string response = Encoding.UTF8.GetString(buffer);
Assert.True(response.Contains("<td>LibInfo1</td>")); Assert.Contains("<p>Runtime Version: 1.0.0</p>", response);
Assert.True(response.Contains("<td>1.0.0-beta1</td>")); Assert.Contains("<p>Operating System: Windows</p>", response);
Assert.True(response.Contains("<td>Path1</td>")); Assert.Contains("<p>Runtime Architecture: x64</p>", response);
Assert.True(response.Contains("<td>LibInfo2</td>")); Assert.Contains("<p>Runtime Type: clr</p>", response);
Assert.True(response.Contains("<td>1.0.0-beta2</td>")); Assert.Contains("<td>LibInfo1</td>", response);
Assert.True(response.Contains("<td>Path2</td>")); Assert.Contains("<td>1.0.0-beta1</td>", response);
Assert.Contains("<td>Path1</td>", response);
Assert.Contains("<td>LibInfo2</td>", response);
Assert.Contains("<td>1.0.0-beta2</td>", response);
Assert.Contains("<td>Path2</td>", response);
} }
} }
@ -150,6 +173,12 @@ namespace Microsoft.AspNet.Diagnostics.Tests
new FakeLibraryInformation() { Name ="LibInfo1", Version = "1.0.0-beta1", Path = "Path1" }, new FakeLibraryInformation() { Name ="LibInfo1", Version = "1.0.0-beta1", Path = "Path1" },
}); });
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);
@ -158,7 +187,8 @@ namespace Microsoft.AspNet.Diagnostics.Tests
var middleware = new RuntimeInfoMiddleware( var middleware = new RuntimeInfoMiddleware(
next, next,
new RuntimeInfoPageOptions(), new RuntimeInfoPageOptions(),
libraryManagerMock.Object); libraryManagerMock.Object,
runtimeEnvironmentMock.Object);
var buffer = new byte[4096]; var buffer = new byte[4096];
using (var responseStream = new MemoryStream(buffer)) using (var responseStream = new MemoryStream(buffer))