mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 13:30:49 +08:00 
			
		
		
		
	added happy path tests for more middlewares
This commit is contained in:
		@@ -12,6 +12,7 @@
 | 
			
		||||
        private readonly RequestDelegate _next;
 | 
			
		||||
        private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
 | 
			
		||||
        private readonly IRouteRequiresAuthentication _requiresAuthentication;
 | 
			
		||||
 | 
			
		||||
        public AuthenticationMiddleware(RequestDelegate next, 
 | 
			
		||||
            IScopedRequestDataRepository scopedRequestDataRepository, 
 | 
			
		||||
            IRouteRequiresAuthentication requiresAuthentication) 
 | 
			
		||||
 
 | 
			
		||||
@@ -4,11 +4,11 @@ using Ocelot.Library.Infrastructure.Responses;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Library.Middleware
 | 
			
		||||
{
 | 
			
		||||
    public class OcelotMiddleware
 | 
			
		||||
    public abstract class OcelotMiddleware
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IScopedRequestDataRepository _scopedRequestDataRepository;
 | 
			
		||||
 | 
			
		||||
        public OcelotMiddleware(IScopedRequestDataRepository scopedRequestDataRepository)
 | 
			
		||||
        protected OcelotMiddleware(IScopedRequestDataRepository scopedRequestDataRepository)
 | 
			
		||||
        {
 | 
			
		||||
            _scopedRequestDataRepository = scopedRequestDataRepository;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
using Microsoft.AspNetCore.Builder;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Library.Middleware
 | 
			
		||||
{
 | 
			
		||||
    public static class RequestLoggerExtensions
 | 
			
		||||
    {
 | 
			
		||||
        public static IApplicationBuilder UseRequestLogger(this IApplicationBuilder builder)
 | 
			
		||||
        {
 | 
			
		||||
            return builder.UseMiddleware<RequestLoggerMiddleware>();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
} 
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Library.Middleware
 | 
			
		||||
{
 | 
			
		||||
    public class RequestLoggerMiddleware
 | 
			
		||||
    {
 | 
			
		||||
        private readonly RequestDelegate _next;
 | 
			
		||||
        private readonly ILogger _logger;
 | 
			
		||||
 | 
			
		||||
        public RequestLoggerMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
 | 
			
		||||
        {
 | 
			
		||||
            _next = next;
 | 
			
		||||
            _logger = loggerFactory.CreateLogger<RequestLoggerMiddleware>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task Invoke(HttpContext context)
 | 
			
		||||
        {
 | 
			
		||||
            _logger.LogInformation("Handling request: " + context.Request.Path);
 | 
			
		||||
            await _next.Invoke(context);
 | 
			
		||||
            _logger.LogInformation("Finished handling request.");
 | 
			
		||||
        }
 | 
			
		||||
    } 
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user