From 48d3c63f7058a0527a36fe4176ec9067cf73c857 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 23 Feb 2016 08:20:33 +0000 Subject: [PATCH] TestHelper classes for shared types --- .../ChunkedRequestTests.cs | 40 ------------------- .../EngineTests.cs | 39 ------------------ .../PassThroughConnectionFilter.cs | 19 +++++++++ .../TestHelpers/TestApplicationErrorLogger.cs | 35 ++++++++++++++++ 4 files changed, 54 insertions(+), 79 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 82036269a4..9408c44b14 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -1,18 +1,13 @@ // 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; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.Extensions.Logging; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -437,41 +432,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } - - private class TestApplicationErrorLogger : ILogger - { - // Application errors are logged using 13 as the eventId. - private const int ApplicationErrorEventId = 13; - - public int ApplicationErrorsLogged { get; set; } - - public IDisposable BeginScopeImpl(object state) - { - return new Disposable(() => { }); - } - - public bool IsEnabled(LogLevel logLevel) - { - return true; - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - if (eventId.Id == ApplicationErrorEventId) - { - ApplicationErrorsLogged++; - } - } - } - - private class PassThroughConnectionFilter : IConnectionFilter - { - public Task OnConnectionAsync(ConnectionFilterContext context) - { - context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); - return TaskUtilities.CompletedTask; - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 9406282898..2a4e788c58 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Linq; -using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; @@ -12,11 +11,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; -using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.Logging; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -1024,38 +1018,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(registrationWh.Wait(1000)); } } - - private class TestApplicationErrorLogger : ILogger - { - public int ApplicationErrorsLogged { get; set; } - - public IDisposable BeginScopeImpl(object state) - { - return new Disposable(() => { }); - } - - public bool IsEnabled(LogLevel logLevel) - { - return true; - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - // Application errors are logged using 13 as the eventId. - if (eventId.Id == 13) - { - ApplicationErrorsLogged++; - } - } - } - - private class PassThroughConnectionFilter : IConnectionFilter - { - public Task OnConnectionAsync(ConnectionFilterContext context) - { - context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); - return TaskUtilities.CompletedTask; - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs new file mode 100644 index 0000000000..2342536d3c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs @@ -0,0 +1,19 @@ +// 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.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + + public class PassThroughConnectionFilter : IConnectionFilter + { + public Task OnConnectionAsync(ConnectionFilterContext context) + { + context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); + return TaskUtilities.CompletedTask; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs new file mode 100644 index 0000000000..f6e7f04169 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -0,0 +1,35 @@ +// 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; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class TestApplicationErrorLogger : ILogger + { + // Application errors are logged using 13 as the eventId. + private const int ApplicationErrorEventId = 13; + + public int ApplicationErrorsLogged { get; set; } + + public IDisposable BeginScopeImpl(object state) + { + return new Disposable(() => { }); + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + if (eventId.Id == ApplicationErrorEventId) + { + ApplicationErrorsLogged++; + } + } + } +}