diff --git a/DiagnosticsPages.sln b/DiagnosticsPages.sln index 2cd1be0150..9691d84257 100644 --- a/DiagnosticsPages.sln +++ b/DiagnosticsPages.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22013.1 +VisualStudioVersion = 14.0.22130.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{509A6F36-AD80-4A18-B5B1-717D38DFF29D}" EndProject @@ -20,6 +20,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "RuntimeInfoPageSample", "samples\RuntimeInfoPageSample\RuntimeInfoPageSample.kproj", "{CD62A191-39F5-4C86-BC1D-7731085120F5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2AF90579-B118-4583-AE88-672EFACB5BC4}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Diagnostics.Tests", "test\Microsoft.AspNet.Diagnostics.Tests\Microsoft.AspNet.Diagnostics.Tests.kproj", "{994351B4-7B2A-4139-8B72-72C5BB5CC618}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -70,6 +76,26 @@ Global {4D4A785A-ECB9-4916-A88F-0FD306EE3B74}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {4D4A785A-ECB9-4916-A88F-0FD306EE3B74}.Release|Mixed Platforms.Build.0 = Release|Any CPU {4D4A785A-ECB9-4916-A88F-0FD306EE3B74}.Release|x86.ActiveCfg = Release|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Debug|x86.ActiveCfg = Debug|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Release|Any CPU.Build.0 = Release|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {CD62A191-39F5-4C86-BC1D-7731085120F5}.Release|x86.ActiveCfg = Release|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Debug|Any CPU.Build.0 = Debug|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Debug|x86.ActiveCfg = Debug|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Release|Any CPU.ActiveCfg = Release|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Release|Any CPU.Build.0 = Release|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {994351B4-7B2A-4139-8B72-72C5BB5CC618}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -79,5 +105,7 @@ Global {68A1F0E1-ECCE-46D1-B20F-C43EE5B097DE} = {509A6F36-AD80-4A18-B5B1-717D38DFF29D} {589AC17F-9455-4764-8F82-FCD2AE58DA14} = {ACAA0157-A8C4-4152-93DE-90CCDF304087} {4D4A785A-ECB9-4916-A88F-0FD306EE3B74} = {509A6F36-AD80-4A18-B5B1-717D38DFF29D} + {CD62A191-39F5-4C86-BC1D-7731085120F5} = {ACAA0157-A8C4-4152-93DE-90CCDF304087} + {994351B4-7B2A-4139-8B72-72C5BB5CC618} = {2AF90579-B118-4583-AE88-672EFACB5BC4} EndGlobalSection EndGlobal diff --git a/samples/RuntimeInfoPageSample/RuntimeInfoPageSample.kproj b/samples/RuntimeInfoPageSample/RuntimeInfoPageSample.kproj new file mode 100644 index 0000000000..b6f401ddcb --- /dev/null +++ b/samples/RuntimeInfoPageSample/RuntimeInfoPageSample.kproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + cd62a191-39f5-4c86-bc1d-7731085120f5 + Web + RuntimeInfoPageSample + + + 2.0 + 44048 + + + \ No newline at end of file diff --git a/samples/RuntimeInfoPageSample/Startup.cs b/samples/RuntimeInfoPageSample/Startup.cs new file mode 100644 index 0000000000..7fa53965c7 --- /dev/null +++ b/samples/RuntimeInfoPageSample/Startup.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Diagnostics; +using Microsoft.AspNet.Http; + +namespace RuntimeInfoPageSample +{ + public class Startup + { + public void Configure(IApplicationBuilder app) + { + app.UseRuntimeInfoPage(); + + app.Run(context => + { + context.Response.StatusCode = 302; + context.Response.Headers["Location"] = "/runtimeinfo"; + + return Task.FromResult(0); + }); + } + } +} diff --git a/samples/RuntimeInfoPageSample/project.json b/samples/RuntimeInfoPageSample/project.json new file mode 100644 index 0000000000..d48d5c43b4 --- /dev/null +++ b/samples/RuntimeInfoPageSample/project.json @@ -0,0 +1,12 @@ +{ + "webroot" : "wwwroot", + "exclude": "wwwroot/**/*.*", + "dependencies": { + "Microsoft.AspNet.Diagnostics": "", + "Microsoft.AspNet.Server.IIS": "1.0.0-*" + }, + "frameworks" : { + "aspnet50" : { }, + "aspnetcore50" : { } + } +} diff --git a/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs b/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs index fda85f4f25..440acba3ef 100644 --- a/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs +++ b/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Diagnostics model.Environment = context; }*/ - var errorPage = new ErrorPage() { Model = model }; + var errorPage = new ErrorPage(model); await errorPage.ExecuteAsync(context); } diff --git a/src/Microsoft.AspNet.Diagnostics/NotNullAttribute.cs b/src/Microsoft.AspNet.Diagnostics/NotNullAttribute.cs new file mode 100644 index 0000000000..458df70f92 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/NotNullAttribute.cs @@ -0,0 +1,12 @@ +// 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. + +using System; + +namespace Microsoft.AspNet.Diagnostics +{ + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + internal sealed class NotNullAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Diagnostics/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..2a2e7697fc --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/Properties/AssemblyInfo.cs @@ -0,0 +1,7 @@ +// 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. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.AspNet.Diagnostics.Tests")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/Microsoft.AspNet.Diagnostics/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Diagnostics/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..acdb08b710 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/Properties/Resources.Designer.cs @@ -0,0 +1,574 @@ +// +namespace Microsoft.AspNet.Diagnostics +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class Resources + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNet.Diagnostics.Resources", typeof(Resources).GetTypeInfo().Assembly); + + /// + /// You are seeing this page because DiagnosticsPageMiddleware was added to your web application. + /// + internal static string DiagnosticsPageHtml_Information + { + get { return GetString("DiagnosticsPageHtml_Information"); } + } + + /// + /// You are seeing this page because DiagnosticsPageMiddleware was added to your web application. + /// + internal static string FormatDiagnosticsPageHtml_Information() + { + return GetString("DiagnosticsPageHtml_Information"); + } + + /// + /// Test Error Message + /// + internal static string DiagnosticsPageHtml_TestErrorMessage + { + get { return GetString("DiagnosticsPageHtml_TestErrorMessage"); } + } + + /// + /// Test Error Message + /// + internal static string FormatDiagnosticsPageHtml_TestErrorMessage() + { + return GetString("DiagnosticsPageHtml_TestErrorMessage"); + } + + /// + /// Test Error Page + /// + internal static string DiagnosticsPageHtml_TestErrorSection + { + get { return GetString("DiagnosticsPageHtml_TestErrorSection"); } + } + + /// + /// Test Error Page + /// + internal static string FormatDiagnosticsPageHtml_TestErrorSection() + { + return GetString("DiagnosticsPageHtml_TestErrorSection"); + } + + /// + /// Diagnostics Page + /// + internal static string DiagnosticsPageHtml_Title + { + get { return GetString("DiagnosticsPageHtml_Title"); } + } + + /// + /// Diagnostics Page + /// + internal static string FormatDiagnosticsPageHtml_Title() + { + return GetString("DiagnosticsPageHtml_Title"); + } + + /// + /// Cookies + /// + internal static string ErrorPageHtml_CookiesButton + { + get { return GetString("ErrorPageHtml_CookiesButton"); } + } + + /// + /// Cookies + /// + internal static string FormatErrorPageHtml_CookiesButton() + { + return GetString("ErrorPageHtml_CookiesButton"); + } + + /// + /// Enable development mode or ErrorPageOptions.ShowExceptionDetails for additional information. + /// + internal static string ErrorPageHtml_EnableShowExceptions + { + get { return GetString("ErrorPageHtml_EnableShowExceptions"); } + } + + /// + /// Enable development mode or ErrorPageOptions.ShowExceptionDetails for additional information. + /// + internal static string FormatErrorPageHtml_EnableShowExceptions() + { + return GetString("ErrorPageHtml_EnableShowExceptions"); + } + + /// + /// Environment + /// + internal static string ErrorPageHtml_EnvironmentButton + { + get { return GetString("ErrorPageHtml_EnvironmentButton"); } + } + + /// + /// Environment + /// + internal static string FormatErrorPageHtml_EnvironmentButton() + { + return GetString("ErrorPageHtml_EnvironmentButton"); + } + + /// + /// Headers + /// + internal static string ErrorPageHtml_HeadersButton + { + get { return GetString("ErrorPageHtml_HeadersButton"); } + } + + /// + /// Headers + /// + internal static string FormatErrorPageHtml_HeadersButton() + { + return GetString("ErrorPageHtml_HeadersButton"); + } + + /// + /// No cookie data. + /// + internal static string ErrorPageHtml_NoCookieData + { + get { return GetString("ErrorPageHtml_NoCookieData"); } + } + + /// + /// No cookie data. + /// + internal static string FormatErrorPageHtml_NoCookieData() + { + return GetString("ErrorPageHtml_NoCookieData"); + } + + /// + /// No header data. + /// + internal static string ErrorPageHtml_NoHeaderData + { + get { return GetString("ErrorPageHtml_NoHeaderData"); } + } + + /// + /// No header data. + /// + internal static string FormatErrorPageHtml_NoHeaderData() + { + return GetString("ErrorPageHtml_NoHeaderData"); + } + + /// + /// No QueryString data. + /// + internal static string ErrorPageHtml_NoQueryStringData + { + get { return GetString("ErrorPageHtml_NoQueryStringData"); } + } + + /// + /// No QueryString data. + /// + internal static string FormatErrorPageHtml_NoQueryStringData() + { + return GetString("ErrorPageHtml_NoQueryStringData"); + } + + /// + /// Query + /// + internal static string ErrorPageHtml_QueryButton + { + get { return GetString("ErrorPageHtml_QueryButton"); } + } + + /// + /// Query + /// + internal static string FormatErrorPageHtml_QueryButton() + { + return GetString("ErrorPageHtml_QueryButton"); + } + + /// + /// Stack + /// + internal static string ErrorPageHtml_StackButton + { + get { return GetString("ErrorPageHtml_StackButton"); } + } + + /// + /// Stack + /// + internal static string FormatErrorPageHtml_StackButton() + { + return GetString("ErrorPageHtml_StackButton"); + } + + /// + /// Internal Server Error + /// + internal static string ErrorPageHtml_Title + { + get { return GetString("ErrorPageHtml_Title"); } + } + + /// + /// Internal Server Error + /// + internal static string FormatErrorPageHtml_Title() + { + return GetString("ErrorPageHtml_Title"); + } + + /// + /// An unhandled exception occurred while processing the request. + /// + internal static string ErrorPageHtml_UnhandledException + { + get { return GetString("ErrorPageHtml_UnhandledException"); } + } + + /// + /// An unhandled exception occurred while processing the request. + /// + internal static string FormatErrorPageHtml_UnhandledException() + { + return GetString("ErrorPageHtml_UnhandledException"); + } + + /// + /// Unknown location + /// + internal static string ErrorPageHtml_UnknownLocation + { + get { return GetString("ErrorPageHtml_UnknownLocation"); } + } + + /// + /// Unknown location + /// + internal static string FormatErrorPageHtml_UnknownLocation() + { + return GetString("ErrorPageHtml_UnknownLocation"); + } + + /// + /// Value + /// + internal static string ErrorPageHtml_ValueColumn + { + get { return GetString("ErrorPageHtml_ValueColumn"); } + } + + /// + /// Value + /// + internal static string FormatErrorPageHtml_ValueColumn() + { + return GetString("ErrorPageHtml_ValueColumn"); + } + + /// + /// Variable + /// + internal static string ErrorPageHtml_VariableColumn + { + get { return GetString("ErrorPageHtml_VariableColumn"); } + } + + /// + /// Variable + /// + internal static string FormatErrorPageHtml_VariableColumn() + { + return GetString("ErrorPageHtml_VariableColumn"); + } + + /// + /// The path must start with a '/'. + /// + internal static string Exception_PathMustStartWithSlash + { + get { return GetString("Exception_PathMustStartWithSlash"); } + } + + /// + /// The path must start with a '/'. + /// + internal static string FormatException_PathMustStartWithSlash() + { + return GetString("Exception_PathMustStartWithSlash"); + } + + /// + /// Name + /// + internal static string RuntimeInfoPage_PackageNameColumnName + { + get { return GetString("RuntimeInfoPage_PackageNameColumnName"); } + } + + /// + /// Name + /// + internal static string FormatRuntimeInfoPage_PackageNameColumnName() + { + return GetString("RuntimeInfoPage_PackageNameColumnName"); + } + + /// + /// Path + /// + internal static string RuntimeInfoPage_PackagePathColumnName + { + get { return GetString("RuntimeInfoPage_PackagePathColumnName"); } + } + + /// + /// Path + /// + internal static string FormatRuntimeInfoPage_PackagePathColumnName() + { + return GetString("RuntimeInfoPage_PackagePathColumnName"); + } + + /// + /// Packages: + /// + internal static string RuntimeInfoPage_Packages + { + get { return GetString("RuntimeInfoPage_Packages"); } + } + + /// + /// Packages: + /// + internal static string FormatRuntimeInfoPage_Packages() + { + return GetString("RuntimeInfoPage_Packages"); + } + + /// + /// Could not retrieve the list of loaded packages. + /// + internal static string RuntimeInfoPage_PackagesFail + { + get { return GetString("RuntimeInfoPage_PackagesFail"); } + } + + /// + /// Could not retrieve the list of loaded packages. + /// + internal static string FormatRuntimeInfoPage_PackagesFail() + { + return GetString("RuntimeInfoPage_PackagesFail"); + } + + /// + /// Runtime Version: + /// + internal static string RuntimeInfoPage_RuntimeVersion + { + get { return GetString("RuntimeInfoPage_RuntimeVersion"); } + } + + /// + /// Runtime Version: + /// + internal static string FormatRuntimeInfoPage_RuntimeVersion() + { + return GetString("RuntimeInfoPage_RuntimeVersion"); + } + + /// + /// Could not determine the runtime version. + /// + internal static string RuntimeInfoPage_RuntimeVersionFail + { + get { return GetString("RuntimeInfoPage_RuntimeVersionFail"); } + } + + /// + /// Could not determine the runtime version. + /// + internal static string FormatRuntimeInfoPage_RuntimeVersionFail() + { + return GetString("RuntimeInfoPage_RuntimeVersionFail"); + } + + /// + /// Runtime Information + /// + internal static string RuntimeInfoPage_Title + { + get { return GetString("RuntimeInfoPage_Title"); } + } + + /// + /// Runtime Information + /// + internal static string FormatRuntimeInfoPage_Title() + { + return GetString("RuntimeInfoPage_Title"); + } + + /// + /// Welcome + /// + internal static string WelcomeHeader + { + get { return GetString("WelcomeHeader"); } + } + + /// + /// Welcome + /// + internal static string FormatWelcomeHeader() + { + return GetString("WelcomeHeader"); + } + + /// + /// Learn more about the Microsoft ASP.NET vNext components + /// + internal static string WelcomeLearnMicrosoftAspNet + { + get { return GetString("WelcomeLearnMicrosoftAspNet"); } + } + + /// + /// Learn more about the Microsoft ASP.NET vNext components + /// + internal static string FormatWelcomeLearnMicrosoftAspNet() + { + return GetString("WelcomeLearnMicrosoftAspNet"); + } + + /// + /// Browser + /// + internal static string WelcomePageImageText_Browser + { + get { return GetString("WelcomePageImageText_Browser"); } + } + + /// + /// Browser + /// + internal static string FormatWelcomePageImageText_Browser() + { + return GetString("WelcomePageImageText_Browser"); + } + + /// + /// Learn More + /// + internal static string WelcomePageImageText_LearnMore + { + get { return GetString("WelcomePageImageText_LearnMore"); } + } + + /// + /// Learn More + /// + internal static string FormatWelcomePageImageText_LearnMore() + { + return GetString("WelcomePageImageText_LearnMore"); + } + + /// + /// Light Bulb + /// + internal static string WelcomePageImageText_LightBulb + { + get { return GetString("WelcomePageImageText_LightBulb"); } + } + + /// + /// Light Bulb + /// + internal static string FormatWelcomePageImageText_LightBulb() + { + return GetString("WelcomePageImageText_LightBulb"); + } + + /// + /// Skyline + /// + internal static string WelcomePageImageText_Skyline + { + get { return GetString("WelcomePageImageText_Skyline"); } + } + + /// + /// Skyline + /// + internal static string FormatWelcomePageImageText_Skyline() + { + return GetString("WelcomePageImageText_Skyline"); + } + + /// + /// Your ASP.NET vNext application has been successfully started + /// + internal static string WelcomeStarted + { + get { return GetString("WelcomeStarted"); } + } + + /// + /// Your ASP.NET vNext application has been successfully started + /// + internal static string FormatWelcomeStarted() + { + return GetString("WelcomeStarted"); + } + + /// + /// Your ASP.NET vNext application has been successfully started. + /// + internal static string WelcomeTitle + { + get { return GetString("WelcomeTitle"); } + } + + /// + /// Your ASP.NET vNext application has been successfully started. + /// + internal static string FormatWelcomeTitle() + { + return GetString("WelcomeTitle"); + } + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNet.Diagnostics/Resources.Designer.cs b/src/Microsoft.AspNet.Diagnostics/Resources.Designer.cs deleted file mode 100644 index f6ffb8460e..0000000000 --- a/src/Microsoft.AspNet.Diagnostics/Resources.Designer.cs +++ /dev/null @@ -1,306 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.33440 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Microsoft.AspNet.Diagnostics { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Diagnostics.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to You are seeing this page because DiagnosticsPageMiddleware was added to your web application.. - /// - internal static string DiagnosticsPageHtml_Information { - get { - return ResourceManager.GetString("DiagnosticsPageHtml_Information", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Test Error Message. - /// - internal static string DiagnosticsPageHtml_TestErrorMessage { - get { - return ResourceManager.GetString("DiagnosticsPageHtml_TestErrorMessage", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Test Error Page. - /// - internal static string DiagnosticsPageHtml_TestErrorSection { - get { - return ResourceManager.GetString("DiagnosticsPageHtml_TestErrorSection", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Diagnostics Page. - /// - internal static string DiagnosticsPageHtml_Title { - get { - return ResourceManager.GetString("DiagnosticsPageHtml_Title", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Cookies. - /// - internal static string ErrorPageHtml_CookiesButton { - get { - return ResourceManager.GetString("ErrorPageHtml_CookiesButton", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Enable development mode or ErrorPageOptions.ShowExceptionDetails for additional information.. - /// - internal static string ErrorPageHtml_EnableShowExceptions { - get { - return ResourceManager.GetString("ErrorPageHtml_EnableShowExceptions", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Environment. - /// - internal static string ErrorPageHtml_EnvironmentButton { - get { - return ResourceManager.GetString("ErrorPageHtml_EnvironmentButton", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Headers. - /// - internal static string ErrorPageHtml_HeadersButton { - get { - return ResourceManager.GetString("ErrorPageHtml_HeadersButton", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to No cookie data.. - /// - internal static string ErrorPageHtml_NoCookieData { - get { - return ResourceManager.GetString("ErrorPageHtml_NoCookieData", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to No header data.. - /// - internal static string ErrorPageHtml_NoHeaderData { - get { - return ResourceManager.GetString("ErrorPageHtml_NoHeaderData", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to No QueryString data.. - /// - internal static string ErrorPageHtml_NoQueryStringData { - get { - return ResourceManager.GetString("ErrorPageHtml_NoQueryStringData", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Query. - /// - internal static string ErrorPageHtml_QueryButton { - get { - return ResourceManager.GetString("ErrorPageHtml_QueryButton", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Stack. - /// - internal static string ErrorPageHtml_StackButton { - get { - return ResourceManager.GetString("ErrorPageHtml_StackButton", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Internal Server Error. - /// - internal static string ErrorPageHtml_Title { - get { - return ResourceManager.GetString("ErrorPageHtml_Title", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to An unhandled exception occurred while processing the request.. - /// - internal static string ErrorPageHtml_UnhandledException { - get { - return ResourceManager.GetString("ErrorPageHtml_UnhandledException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unknown location. - /// - internal static string ErrorPageHtml_UnknownLocation { - get { - return ResourceManager.GetString("ErrorPageHtml_UnknownLocation", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Value. - /// - internal static string ErrorPageHtml_ValueColumn { - get { - return ResourceManager.GetString("ErrorPageHtml_ValueColumn", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Variable. - /// - internal static string ErrorPageHtml_VariableColumn { - get { - return ResourceManager.GetString("ErrorPageHtml_VariableColumn", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The path must start with a '/'.. - /// - internal static string Exception_PathMustStartWithSlash { - get { - return ResourceManager.GetString("Exception_PathMustStartWithSlash", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Welcome. - /// - internal static string WelcomeHeader { - get { - return ResourceManager.GetString("WelcomeHeader", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Learn more about the Microsoft ASP.NET vNext components. - /// - internal static string WelcomeLearnMicrosoftAspNet { - get { - return ResourceManager.GetString("WelcomeLearnMicrosoftAspNet", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Browser. - /// - internal static string WelcomePageImageText_Browser { - get { - return ResourceManager.GetString("WelcomePageImageText_Browser", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Learn More. - /// - internal static string WelcomePageImageText_LearnMore { - get { - return ResourceManager.GetString("WelcomePageImageText_LearnMore", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Light Bulb. - /// - internal static string WelcomePageImageText_LightBulb { - get { - return ResourceManager.GetString("WelcomePageImageText_LightBulb", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Skyline. - /// - internal static string WelcomePageImageText_Skyline { - get { - return ResourceManager.GetString("WelcomePageImageText_Skyline", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Your ASP.NET vNext application has been successfully started. - /// - internal static string WelcomeStarted { - get { - return ResourceManager.GetString("WelcomeStarted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Your ASP.NET vNext application has been successfully started.. - /// - internal static string WelcomeTitle { - get { - return ResourceManager.GetString("WelcomeTitle", resourceCulture); - } - } - } -} diff --git a/src/Microsoft.AspNet.Diagnostics/Resources.resx b/src/Microsoft.AspNet.Diagnostics/Resources.resx index 8212793f91..4eb16cc19c 100644 --- a/src/Microsoft.AspNet.Diagnostics/Resources.resx +++ b/src/Microsoft.AspNet.Diagnostics/Resources.resx @@ -182,6 +182,27 @@ The path must start with a '/'. + + Name + + + Path + + + Packages: + + + Could not retrieve the list of loaded packages. + + + Runtime Version: + + + Could not determine the runtime version. + + + Runtime Information + Welcome diff --git a/src/Microsoft.AspNet.Diagnostics/RuntimeInfoExtensions.cs b/src/Microsoft.AspNet.Diagnostics/RuntimeInfoExtensions.cs new file mode 100644 index 0000000000..35b2efae40 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/RuntimeInfoExtensions.cs @@ -0,0 +1,30 @@ +// 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. + +using Microsoft.AspNet.Diagnostics; +using Microsoft.AspNet.Http; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Builder +{ + public static class RuntimeInfoExtensions + { + public static IApplicationBuilder UseRuntimeInfoPage(this IApplicationBuilder builder) + { + return UseRuntimeInfoPage(builder, new RuntimeInfoPageOptions()); + } + + public static IApplicationBuilder UseRuntimeInfoPage(this IApplicationBuilder builder, string path) + { + return UseRuntimeInfoPage(builder, new RuntimeInfoPageOptions() { Path = new PathString(path) }); + } + + public static IApplicationBuilder UseRuntimeInfoPage( + [NotNull] this IApplicationBuilder builder, + [NotNull] RuntimeInfoPageOptions options) + { + var libraryManager = builder.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager; + return builder.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager).Invoke); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/RuntimeInfoMiddleware.cs b/src/Microsoft.AspNet.Diagnostics/RuntimeInfoMiddleware.cs new file mode 100644 index 0000000000..b3988d8cfb --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/RuntimeInfoMiddleware.cs @@ -0,0 +1,73 @@ +// 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. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Diagnostics.Views; +using Microsoft.AspNet.Http; +using Microsoft.Framework.Runtime; +using System.Linq; +using System.Reflection; + +namespace Microsoft.AspNet.Diagnostics +{ + /// + /// Displays information about the packages used by the application at runtime + /// + public class RuntimeInfoMiddleware + { + private readonly RequestDelegate _next; + private readonly RuntimeInfoPageOptions _options; + private readonly ILibraryManager _libraryManager; + + /// + /// Initializes a new instance of the class + /// + /// + /// + public RuntimeInfoMiddleware( + [NotNull] RequestDelegate next, + [NotNull] RuntimeInfoPageOptions options, + [NotNull] ILibraryManager libraryManager) + { + _next = next; + _options = options; + _libraryManager = libraryManager; + } + + /// + /// Process an individual request. + /// + /// + /// + public Task Invoke(HttpContext context) + { + var request = context.Request; + if (!_options.Path.HasValue || _options.Path == request.Path) + { + var model = CreateRuntimeInfoModel(); + var runtimeInfoPage = new RuntimeInfoPage(model); + return runtimeInfoPage.ExecuteAsync(context); + } + + return _next(context); + } + + internal RuntimeInfoPageModel CreateRuntimeInfoModel() + { + var model = new RuntimeInfoPageModel(); + model.References = _libraryManager.GetLibraries(); + model.Version = GetRuntimeVersion(); + + return model; + } + + private static string GetRuntimeVersion() + { + var klr = Assembly.Load(new AssemblyName("klr.host")); + var version = klr.GetCustomAttribute(); + return version?.InformationalVersion; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/RuntimeInfoPageOptions.cs b/src/Microsoft.AspNet.Diagnostics/RuntimeInfoPageOptions.cs new file mode 100644 index 0000000000..70cb7c41b6 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/RuntimeInfoPageOptions.cs @@ -0,0 +1,26 @@ +// 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. + +using Microsoft.AspNet.Http; + +namespace Microsoft.AspNet.Diagnostics +{ + /// + /// Options for the RuntimeInfoPage + /// + public class RuntimeInfoPageOptions + { + /// + /// Initializes a new instance of the class + /// + public RuntimeInfoPageOptions() + { + Path = new PathString("/runtimeinfo"); + } + + /// + /// Specifies which request path will be responded to. Exact match only. Set to null to handle all requests. + /// + public PathString Path { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cs b/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cs index cff67527bf..e07c402da0 100644 --- a/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cs +++ b/src/Microsoft.AspNet.Diagnostics/Views/ErrorPage.cs @@ -1,6 +1,3 @@ -// 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. - namespace Microsoft.AspNet.Diagnostics.Views { #line 1 "ErrorPage.cshtml" @@ -33,6 +30,11 @@ using Views { #line 6 "ErrorPage.cshtml" + public ErrorPage(ErrorPageModel model) + { + Model = model; + } + public ErrorPageModel Model { get; set; } #line default @@ -45,7 +47,7 @@ using Views #pragma warning disable 1998 public override async Task ExecuteAsync() { -#line 9 "ErrorPage.cshtml" +#line 14 "ErrorPage.cshtml" Response.StatusCode = 500; // TODO: Response.ReasonPhrase = "Internal Server Error"; @@ -57,18 +59,18 @@ using Views #line hidden WriteLiteral("\r\n\r\n( -#line 17 "ErrorPage.cshtml" + WriteAttribute("lang", Tuple.Create(" lang=\"", 499), Tuple.Create("\"", 560), + Tuple.Create(Tuple.Create("", 506), Tuple.Create( +#line 22 "ErrorPage.cshtml" CultureInfo.CurrentUICulture.TwoLetterISOLanguageName #line default #line hidden - , 422), false)); + , 506), false)); WriteLiteral(" xmlns=\"http://www.w3.org/1999/xhtml\">\r\n \r\n \r\n "); Write( -#line 20 "ErrorPage.cshtml" +#line 25 "ErrorPage.cshtml" Resources.ErrorPageHtml_Title #line default @@ -78,7 +80,7 @@ using Views WriteLiteral("\r\n \r" + +"\n\r\n\r\n

"); + Write( +#line 27 "RuntimeInfoPage.cshtml" + Resources.RuntimeInfoPage_RuntimeVersion + +#line default +#line hidden + ); + + WriteLiteral("

\r\n

"); + Write( +#line 28 "RuntimeInfoPage.cshtml" + string.IsNullOrWhiteSpace(Model.Version) ? Resources.RuntimeInfoPage_RuntimeVersionFail : Model.Version + +#line default +#line hidden + ); + + WriteLiteral("

\r\n \r\n

"); + Write( +#line 30 "RuntimeInfoPage.cshtml" + Resources.RuntimeInfoPage_Packages + +#line default +#line hidden + ); + + WriteLiteral("

\r\n"); +#line 31 "RuntimeInfoPage.cshtml" + + +#line default +#line hidden + +#line 31 "RuntimeInfoPage.cshtml" + if (@Resources.RuntimeInfoPage_Packages == null) + { + +#line default +#line hidden + + WriteLiteral("

"); + Write( +#line 33 "RuntimeInfoPage.cshtml" + Resources.RuntimeInfoPage_PackagesFail + +#line default +#line hidden + ); + + WriteLiteral("

\r\n"); +#line 34 "RuntimeInfoPage.cshtml" + } + else + { + +#line default +#line hidden + + WriteLiteral(" \r\n \r\n \r\n <" + +"th>"); + Write( +#line 40 "RuntimeInfoPage.cshtml" + Resources.RuntimeInfoPage_PackageNameColumnName + +#line default +#line hidden + ); + + WriteLiteral("\r\n \r\n \r\n \r\n \r\n"); +#line 45 "RuntimeInfoPage.cshtml" + + +#line default +#line hidden + +#line 45 "RuntimeInfoPage.cshtml" + bool even = false; + +#line default +#line hidden + + WriteLiteral("\r\n"); +#line 46 "RuntimeInfoPage.cshtml" + + +#line default +#line hidden + +#line 46 "RuntimeInfoPage.cshtml" + foreach (var package in Model.References.OrderBy(package => package.Name.ToLowerInvariant())) + { + +#line default +#line hidden + + WriteLiteral(" ( +#line 48 "RuntimeInfoPage.cshtml" + even?"even":"odd" + +#line default +#line hidden + , 1502), false)); + WriteLiteral(">\r\n \r\n \r\n \r\n"); +#line 52 "RuntimeInfoPage.cshtml" + + +#line default +#line hidden + +#line 52 "RuntimeInfoPage.cshtml" + even = !even; + +#line default +#line hidden + +#line 52 "RuntimeInfoPage.cshtml" + + } + +#line default +#line hidden + + WriteLiteral(" \r\n
"); + Write( +#line 41 "RuntimeInfoPage.cshtml" + Resources.RuntimeInfoPage_PackagePathColumnName + +#line default +#line hidden + ); + + WriteLiteral("
"); + Write( +#line 49 "RuntimeInfoPage.cshtml" + package.Name + +#line default +#line hidden + ); + + WriteLiteral(""); + Write( +#line 50 "RuntimeInfoPage.cshtml" + package.Path + +#line default +#line hidden + ); + + WriteLiteral("
\r\n"); +#line 56 "RuntimeInfoPage.cshtml" + } + +#line default +#line hidden + + WriteLiteral("\r\n\r\n"); + } + #pragma warning restore 1998 + } +} diff --git a/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.cshtml b/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.cshtml new file mode 100644 index 0000000000..335a572f45 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.cshtml @@ -0,0 +1,58 @@ +@using System +@using System.Globalization +@using System.Linq +@using Microsoft.AspNet.Diagnostics +@using Microsoft.AspNet.Diagnostics.Views +@using Microsoft.Framework.Runtime; + +@functions +{ + public RuntimeInfoPage(RuntimeInfoPageModel model) + { + Model = model; + } + + public RuntimeInfoPageModel Model { get; set; } +} + + + + + @Resources.RuntimeInfoPage_Title + + + +

@Resources.RuntimeInfoPage_RuntimeVersion

+

@(string.IsNullOrWhiteSpace(Model.Version) ? Resources.RuntimeInfoPage_RuntimeVersionFail : Model.Version)

+ +

@Resources.RuntimeInfoPage_Packages

+ @if (@Resources.RuntimeInfoPage_Packages == null) + { +

@Resources.RuntimeInfoPage_PackagesFail

+ } + else + { + + + + + + + + + @{ bool even = false; } + @foreach (var package in Model.References.OrderBy(package => package.Name.ToLowerInvariant())) + { + + + + + @{ even = !even; } + } + +
@Resources.RuntimeInfoPage_PackageNameColumnName@Resources.RuntimeInfoPage_PackagePathColumnName
@package.Name@package.Path
+ } + + diff --git a/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.css b/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.css new file mode 100644 index 0000000000..0cd3e73416 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPage.css @@ -0,0 +1,29 @@ +body { + font-family: 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif; + font-size: .813em; + line-height: 1.4em; + color: #222; +} + +h1, h2, h3, h4, h5, th { + font-weight: 100; +} + +h1 { + color: #44525e; + margin: 15px 0 15px 0; +} + +h2 { + margin: 10px 5px 0 0; +} + +table .even{ + background-color: #f0f0f0; +} + +th { + font-size: 16px; +} + + diff --git a/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPageModel.cs b/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPageModel.cs new file mode 100644 index 0000000000..5c2451d807 --- /dev/null +++ b/src/Microsoft.AspNet.Diagnostics/Views/RuntimeInfoPageModel.cs @@ -0,0 +1,17 @@ +// 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. + +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Http; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Diagnostics.Views +{ + public class RuntimeInfoPageModel + { + public string Version { get; internal set; } + + public IEnumerable References { get; internal set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/project.json b/src/Microsoft.AspNet.Diagnostics/project.json index 54a20a8b19..40542d3adf 100644 --- a/src/Microsoft.AspNet.Diagnostics/project.json +++ b/src/Microsoft.AspNet.Diagnostics/project.json @@ -3,7 +3,8 @@ "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.AspNet.PipelineCore": "1.0.0-*" + "Microsoft.AspNet.PipelineCore": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "frameworks": { "aspnet50": {}, @@ -18,6 +19,7 @@ "System.IO.FileSystem": "4.0.0.0", "System.Linq": "4.0.0.0", "System.Reflection": "4.0.10.0", + "System.Reflection.Extensions": "4.0.0.0", "System.Resources.ResourceManager": "4.0.0.0", "System.Runtime": "4.0.20.0", "System.Runtime.Extensions": "4.0.10.0", diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/Microsoft.AspNet.Diagnostics.Tests.kproj b/test/Microsoft.AspNet.Diagnostics.Tests/Microsoft.AspNet.Diagnostics.Tests.kproj new file mode 100644 index 0000000000..28fb9850ad --- /dev/null +++ b/test/Microsoft.AspNet.Diagnostics.Tests/Microsoft.AspNet.Diagnostics.Tests.kproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 994351b4-7b2a-4139-8b72-72c5bb5cc618 + Library + Microsoft.AspNet.Diagnostics.Tests + + + + 2.0 + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/RuntimeInfoMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/RuntimeInfoMiddlewareTest.cs new file mode 100644 index 0000000000..4a0f522d0f --- /dev/null +++ b/test/Microsoft.AspNet.Diagnostics.Tests/RuntimeInfoMiddlewareTest.cs @@ -0,0 +1,161 @@ +// 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. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; +using Microsoft.Framework.Runtime; +#if ASPNET50 +using Moq; +#endif +using Xunit; + +namespace Microsoft.AspNet.Diagnostics.Tests +{ + public class RuntimeInfoMiddlewareTest + { + private const string DefaultPath = "/runtimeinfo"; + + [Fact] + public void DefaultPageOptions_HasDefaultPath() + { + // Arrange & act + var options = new RuntimeInfoPageOptions(); + + // Assert + Assert.Equal(DefaultPath, options.Path.Value); + } + +#if ASPNET50 + [Fact] + public void CreateRuntimeInfoModel_GetsTheVersionAndAllPackages() + { + // Arrage + var libraries = new ILibraryInformation[] { + new FakeLibraryInformation() { Name ="LibInfo1", Path = "Path1" }, + new FakeLibraryInformation() { Name ="LibInfo2", Path = "Path2" }, + }; + + var libraryManagerMock = new Mock(MockBehavior.Strict); + libraryManagerMock.Setup(l => l.GetLibraries()).Returns(libraries); + + RequestDelegate next = _ => + { + return Task.FromResult(null); + }; + + var middleware = new RuntimeInfoMiddleware( + next, + new RuntimeInfoPageOptions(), + libraryManagerMock.Object); + + // Act + var model = middleware.CreateRuntimeInfoModel(); + + // Assert + Assert.False(string.IsNullOrWhiteSpace(model.Version)); + Assert.Same(libraries, model.References); + } + + [Fact] + public async void Invoke_WithNonMatchingPath_IgnoresRequest() + { + // Arrange + var libraryManagerMock = new Mock(MockBehavior.Strict); + + RequestDelegate next = _ => + { + return Task.FromResult(null); + }; + + var middleware = new RuntimeInfoMiddleware( + next, + new RuntimeInfoPageOptions(), + libraryManagerMock.Object); + + var contextMock = new Mock(MockBehavior.Strict); + contextMock + .SetupGet(c => c.Request.Path) + .Returns(new PathString("/nonmatchingpath")); + + // Act + await middleware.Invoke(contextMock.Object); + + // Assert + contextMock.VerifyGet(c => c.Request.Path, Times.Once()); + } + + [Fact] + public async void Invoke_WithMatchingPath_ReturnsInfoPage() + { + // Arrange + var libraryManagerMock = new Mock(MockBehavior.Strict); + libraryManagerMock.Setup(l => l.GetLibraries()).Returns(new ILibraryInformation[] { + new FakeLibraryInformation() { Name ="LibInfo1", Path = "Path1" }, + new FakeLibraryInformation() { Name ="LibInfo2", Path = "Path2" }, + }); + + RequestDelegate next = _ => + { + return Task.FromResult(null); + }; + + var middleware = new RuntimeInfoMiddleware( + next, + new RuntimeInfoPageOptions(), + libraryManagerMock.Object); + + var buffer = new byte[4096]; + using (var responseStream = new MemoryStream(buffer)) + { + var contextMock = new Mock(MockBehavior.Strict); + contextMock + .SetupGet(c => c.Request.Path) + .Returns(new PathString("/runtimeinfo")); + contextMock + .SetupGet(c => c.Response.Body) + .Returns(responseStream); + + // Act + await middleware.Invoke(contextMock.Object); + + // Assert + string response = Encoding.UTF8.GetString(buffer); + + Assert.True(response.Contains("LibInfo1")); + Assert.True(response.Contains("Path1")); + Assert.True(response.Contains("LibInfo2")); + Assert.True(response.Contains("Path2")); + } + } +#endif + + private class FakeLibraryInformation : ILibraryInformation + { + public string Name { get; set; } + + public string Path { get; set; } + + public IEnumerable Dependencies + { + get + { + throw new NotImplementedException("Should not be needed by this middleware"); + } + } + + public string Type + { + get + { + throw new NotImplementedException("Should not be needed by this middleware"); + } + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/project.json b/test/Microsoft.AspNet.Diagnostics.Tests/project.json new file mode 100644 index 0000000000..00a3ceebd9 --- /dev/null +++ b/test/Microsoft.AspNet.Diagnostics.Tests/project.json @@ -0,0 +1,25 @@ +{ + "compilationOptions": { + "warningsAsErrors": true + }, + "dependencies": { + "Microsoft.AspNet.Diagnostics": "", + "Xunit.KRunner": "1.0.0-*" + }, + + "frameworks": { + "aspnet50": { + "dependencies": { + "Moq": "4.2.1312.1622" + } + }, + "aspnetcore50": { + "dependencies": { + "System.Runtime": "4.0.20.0" + } + } + }, + "commands": { + "test": "Xunit.KRunner" + } +}