parent
298b8baa98
commit
7e47449f85
|
|
@ -12,7 +12,6 @@ using System.Text;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.Extensions.WebEncoders;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Diagnostics.Views
|
namespace Microsoft.AspNet.Diagnostics.Views
|
||||||
{
|
{
|
||||||
|
|
@ -44,17 +43,17 @@ namespace Microsoft.AspNet.Diagnostics.Views
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Html encoder used to encode content.
|
/// Html encoder used to encode content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected HtmlEncoder HtmlEncoder { get; set; }
|
protected HtmlEncoder HtmlEncoder { get; set; } = HtmlEncoder.Default;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Url encoder used to encode content.
|
/// Url encoder used to encode content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected UrlEncoder UrlEncoder { get; set; }
|
protected UrlEncoder UrlEncoder { get; set; } = UrlEncoder.Default;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// JavaScript encoder used to encode content.
|
/// JavaScript encoder used to encode content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected JavaScriptEncoder JavaScriptEncoder { get; set; }
|
protected JavaScriptEncoder JavaScriptEncoder { get; set; } = JavaScriptEncoder.Default;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Execute an individual request
|
/// Execute an individual request
|
||||||
|
|
@ -66,9 +65,6 @@ namespace Microsoft.AspNet.Diagnostics.Views
|
||||||
Request = Context.Request;
|
Request = Context.Request;
|
||||||
Response = Context.Response;
|
Response = Context.Response;
|
||||||
Output = new StreamWriter(Response.Body, Encoding.UTF8, 4096, leaveOpen: true);
|
Output = new StreamWriter(Response.Body, Encoding.UTF8, 4096, leaveOpen: true);
|
||||||
HtmlEncoder = context.RequestServices.GetHtmlEncoder();
|
|
||||||
UrlEncoder = context.RequestServices.GetUrlEncoder();
|
|
||||||
JavaScriptEncoder = context.RequestServices.GetJavaScriptEncoder();
|
|
||||||
await ExecuteAsync();
|
await ExecuteAsync();
|
||||||
Output.Dispose();
|
Output.Dispose();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,10 @@
|
||||||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
|
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Options": "1.0.0-*",
|
"Microsoft.Extensions.Options": "1.0.0-*",
|
||||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
|
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
|
||||||
"Microsoft.Extensions.WebEncoders": "1.0.0-*",
|
|
||||||
"System.Diagnostics.DiagnosticSource": "4.0.0-*"
|
"System.Diagnostics.DiagnosticSource": "4.0.0-*"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": {
|
"net451": { },
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.Runtime": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dotnet5.4": {
|
"dotnet5.4": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.Reflection.Extensions": "4.0.1-*"
|
"System.Reflection.Extensions": "4.0.1-*"
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,9 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using Microsoft.Extensions.WebEncoders.Testing;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -159,59 +156,5 @@ namespace Microsoft.AspNet.Diagnostics.Tests
|
||||||
Assert.Contains("<td>Path2</td>", response);
|
Assert.Contains("<td>Path2</td>", response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async void Invoke_WithMatchingPath_ReturnsInfoPage_UsingCustomHtmlEncoder()
|
|
||||||
{
|
|
||||||
// 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>()),
|
|
||||||
});
|
|
||||||
|
|
||||||
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,
|
|
||||||
new RuntimeInfoPageOptions(),
|
|
||||||
libraryManagerMock.Object,
|
|
||||||
runtimeEnvironmentMock.Object);
|
|
||||||
|
|
||||||
var buffer = new byte[4096];
|
|
||||||
using (var responseStream = new MemoryStream(buffer))
|
|
||||||
{
|
|
||||||
var contextMock = new Mock<HttpContext>(MockBehavior.Strict);
|
|
||||||
contextMock
|
|
||||||
.SetupGet(c => c.Request.Path)
|
|
||||||
.Returns(new PathString("/runtimeinfo"));
|
|
||||||
contextMock
|
|
||||||
.SetupGet(c => c.Response.Body)
|
|
||||||
.Returns(responseStream);
|
|
||||||
contextMock
|
|
||||||
.SetupGet(c => c.RequestServices)
|
|
||||||
.Returns(new ServiceCollection()
|
|
||||||
.AddSingleton<HtmlEncoder>(new HtmlTestEncoder())
|
|
||||||
.BuildServiceProvider());
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await middleware.Invoke(contextMock.Object);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
string response = Encoding.UTF8.GetString(buffer);
|
|
||||||
|
|
||||||
Assert.True(response.Contains("<td>HtmlEncode[[LibInfo1]]</td>"));
|
|
||||||
Assert.True(response.Contains("<td>HtmlEncode[[1.0.0-beta1]]</td>"));
|
|
||||||
Assert.True(response.Contains("<td>HtmlEncode[[Path1]]</td>"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue