Skip to content
This repository has been archived by the owner on Dec 8, 2018. It is now read-only.

Commit

Permalink
* Remove libraries from RuntimeInfoMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrandenburg committed Jan 5, 2016
1 parent 7e47449 commit 886c33f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 211 deletions.
6 changes: 3 additions & 3 deletions samples/DeveloperExceptionPageSample/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"emitEntryPoint": true
},
"commands": {
"web": "DeveloperExceptionPageSample"
"web": "DeveloperExceptionPageSample"
},
"frameworks": {
"dnx451": {},
"dnxcore50": {}
"dnx451": { },
"dnxcore50": { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ public static IApplicationBuilder UseRuntimeInfoPage(
throw new ArgumentNullException(nameof(configureOptions));
}

var libraryManager = app.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager;
var runtimeEnvironment = app.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;
var options = new RuntimeInfoPageOptions();
configureOptions(options);

return app.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
return app.Use(next => new RuntimeInfoMiddleware(next, options, runtimeEnvironment).Invoke);
}

public static IApplicationBuilder UseRuntimeInfoPage(
Expand All @@ -64,10 +63,8 @@ public static IApplicationBuilder UseRuntimeInfoPage(
throw new ArgumentNullException(nameof(options));
}

var libraryManager = app.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager;
var runtimeEnvironment = app.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;

return app.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
return app.Use(next => new RuntimeInfoMiddleware(next, options, runtimeEnvironment).Invoke);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.PlatformAbstractions;
Expand All @@ -17,7 +16,6 @@ public class RuntimeInfoMiddleware
{
private readonly RequestDelegate _next;
private readonly RuntimeInfoPageOptions _options;
private readonly ILibraryManager _libraryManager;
private readonly IRuntimeEnvironment _runtimeEnvironment;

/// <summary>
Expand All @@ -28,7 +26,6 @@ public class RuntimeInfoMiddleware
public RuntimeInfoMiddleware(
RequestDelegate next,
RuntimeInfoPageOptions options,
ILibraryManager libraryManager,
IRuntimeEnvironment runtimeEnvironment)
{
if (next == null)
Expand All @@ -41,19 +38,13 @@ public RuntimeInfoMiddleware(
throw new ArgumentNullException(nameof(options));
}

if (libraryManager == null)
{
throw new ArgumentNullException(nameof(libraryManager));
}

if (runtimeEnvironment == null)
{
throw new ArgumentNullException(nameof(runtimeEnvironment));
}

_next = next;
_options = options;
_libraryManager = libraryManager;
_runtimeEnvironment = runtimeEnvironment;
}

Expand All @@ -78,7 +69,6 @@ public Task Invoke(HttpContext context)
internal RuntimeInfoPageModel CreateRuntimeInfoModel()
{
var model = new RuntimeInfoPageModel();
model.References = _libraryManager.GetLibraries();
model.Version = _runtimeEnvironment.RuntimeVersion;
model.OperatingSystem = _runtimeEnvironment.OperatingSystem;
model.RuntimeType = _runtimeEnvironment.RuntimeType;
Expand Down
134 changes: 3 additions & 131 deletions src/Microsoft.AspNet.Diagnostics/RuntimeInfo/Views/RuntimeInfoPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public override async Task ExecuteAsync()

#line default
#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" +
"\n</head>\r\n<body>\r\n <h2>");
WriteLiteral("</title>\r\n <style>\r\n <%$ include: RuntimeInfoPage.css % >\r\n </style>" +
"\r\n</head>\r\n<body>\r\n <h2>");
#line 30 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_Environment);

Expand Down Expand Up @@ -136,135 +136,7 @@ public override async Task ExecuteAsync()

#line default
#line hidden
WriteLiteral("</p>\r\n\r\n <h2>");
#line 39 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_Packages);

#line default
#line hidden
WriteLiteral("</h2>\r\n");
#line 40 "RuntimeInfoPage.cshtml"


#line default
#line hidden

#line 40 "RuntimeInfoPage.cshtml"
if (@Resources.RuntimeInfoPage_Packages == null)
{

#line default
#line hidden

WriteLiteral(" <h2>");
#line 42 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackagesFail);

#line default
#line hidden
WriteLiteral("</h2>\r\n");
#line 43 "RuntimeInfoPage.cshtml"
}
else
{

#line default
#line hidden

WriteLiteral(" <table>\r\n <thead>\r\n <tr>\r\n <" +
"th>");
#line 49 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackageNameColumnName);

#line default
#line hidden
WriteLiteral("</th>\r\n <th>");
#line 50 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackageVersionColumnName);

#line default
#line hidden
WriteLiteral("</th>\r\n <th>");
#line 51 "RuntimeInfoPage.cshtml"
Write(Resources.RuntimeInfoPage_PackagePathColumnName);

#line default
#line hidden
WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n");
#line 55 "RuntimeInfoPage.cshtml"


#line default
#line hidden

#line 55 "RuntimeInfoPage.cshtml"
bool even = false;

#line default
#line hidden

WriteLiteral(" ");
#line 56 "RuntimeInfoPage.cshtml"
foreach (var package in Model.References.OrderBy(package => package.Name.ToLowerInvariant()))
{

#line default
#line hidden

WriteLiteral(" <tr");
BeginWriteAttribute("class", " class=\"", 2229, "\"", 2257, 1);
#line 58 "RuntimeInfoPage.cshtml"
WriteAttributeValue("", 2237, even?"even":"odd", 2237, 20, false);

#line default
#line hidden
EndWriteAttribute();
WriteLiteral(">\r\n <td>");
#line 59 "RuntimeInfoPage.cshtml"
Write(package.Name);

#line default
#line hidden
WriteLiteral("</td>\r\n <td>");
#line 60 "RuntimeInfoPage.cshtml"
Write(package.Version);

#line default
#line hidden
WriteLiteral("</td>\r\n <td>");
#line 61 "RuntimeInfoPage.cshtml"
Write(package.Path);

#line default
#line hidden
WriteLiteral("</td>\r\n </tr>\r\n");
#line 63 "RuntimeInfoPage.cshtml"


#line default
#line hidden

#line 63 "RuntimeInfoPage.cshtml"
even = !even;

#line default
#line hidden

#line 63 "RuntimeInfoPage.cshtml"

}

#line default
#line hidden

WriteLiteral(" </tbody>\r\n </table>\r\n");
#line 67 "RuntimeInfoPage.cshtml"
}

#line default
#line hidden

WriteLiteral("</body>\r\n</html>\r\n");
WriteLiteral("</p>\r\n</body>\r\n</html>\r\n");
}
#pragma warning restore 1998
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<meta charset="utf-8" />
<title>@Resources.RuntimeInfoPage_Title</title>
<style>
<%$ include: RuntimeInfoPage.css %>
<%$ include: RuntimeInfoPage.css % >
</style>
</head>
<body>
Expand All @@ -35,35 +35,5 @@
<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)
{
<h2>@Resources.RuntimeInfoPage_PackagesFail</h2>
}
else
{
<table>
<thead>
<tr>
<th>@Resources.RuntimeInfoPage_PackageNameColumnName</th>
<th>@Resources.RuntimeInfoPage_PackageVersionColumnName</th>
<th>@Resources.RuntimeInfoPage_PackagePathColumnName</th>
</tr>
</thead>
<tbody>
@{ bool even = false; }
@foreach (var package in Model.References.OrderBy(package => package.Name.ToLowerInvariant()))
{
<tr class="@(even?"even":"odd")">
<td>@package.Name</td>
<td>@package.Version</td>
<td>@package.Path</td>
</tr>
@{ even = !even; }
}
</tbody>
</table>
}
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// 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.Extensions.PlatformAbstractions;

namespace Microsoft.AspNet.Diagnostics.Views
{
public class RuntimeInfoPageModel
Expand All @@ -15,7 +12,5 @@ public class RuntimeInfoPageModel
public string RuntimeArchitecture { get; internal set; }

public string RuntimeType { get; internal set; }

public IEnumerable<Library> References { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ public void DefaultPageOptions_HasDefaultPath()
public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages()
{
// Arrage
var libraries = new[] {
new Library("LibInfo1", string.Empty, "Path1", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>()),
new Library("LibInfo2", string.Empty, "Path2", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>())
};

var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict);
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");
Expand All @@ -53,7 +45,6 @@ public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages()
var middleware = new RuntimeInfoMiddleware(
next,
new RuntimeInfoPageOptions(),
libraryManagerMock.Object,
runtimeEnvironmentMock.Object);

// Act
Expand All @@ -64,14 +55,12 @@ public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages()
Assert.Equal("Windows", model.OperatingSystem);
Assert.Equal("clr", model.RuntimeType);
Assert.Equal("x64", model.RuntimeArchitecture);
Assert.Same(libraries, model.References);
}

[Fact]
public async void Invoke_WithNonMatchingPath_IgnoresRequest()
{
// Arrange
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict);
var runtimeEnvironmentMock = new Mock<IRuntimeEnvironment>(MockBehavior.Strict);

RequestDelegate next = _ =>
Expand All @@ -82,7 +71,6 @@ public async void Invoke_WithNonMatchingPath_IgnoresRequest()
var middleware = new RuntimeInfoMiddleware(
next,
new RuntimeInfoPageOptions(),
libraryManagerMock.Object,
runtimeEnvironmentMock.Object);

var contextMock = new Mock<HttpContext>(MockBehavior.Strict);
Expand All @@ -101,12 +89,6 @@ public async void Invoke_WithNonMatchingPath_IgnoresRequest()
public async void Invoke_WithMatchingPath_ReturnsInfoPage()
{
// Arrange
var libraryManagerMock = new Mock<ILibraryManager>(MockBehavior.Strict);
libraryManagerMock.Setup(l => l.GetLibraries()).Returns(new[] {
new Library("LibInfo1", "1.0.0-beta1", "Path1", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>()),
new Library("LibInfo2", "1.0.0-beta2", "Path2", string.Empty, Enumerable.Empty<string>(), Enumerable.Empty<AssemblyName>())
});

var runtimeEnvironmentMock = new Mock<IRuntimeEnvironment>(MockBehavior.Strict);
runtimeEnvironmentMock.Setup(r => r.OperatingSystem).Returns("Windows");
runtimeEnvironmentMock.Setup(r => r.RuntimeArchitecture).Returns("x64");
Expand All @@ -121,7 +103,6 @@ public async void Invoke_WithMatchingPath_ReturnsInfoPage()
var middleware = new RuntimeInfoMiddleware(
next,
new RuntimeInfoPageOptions(),
libraryManagerMock.Object,
runtimeEnvironmentMock.Object);

var buffer = new byte[4096];
Expand All @@ -148,12 +129,6 @@ public async void Invoke_WithMatchingPath_ReturnsInfoPage()
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("<td>LibInfo1</td>", response);
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);
}
}
}
Expand Down

0 comments on commit 886c33f

Please sign in to comment.