mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 12:10:50 +08:00 
			
		
		
		
	Feature/another look at logging (#303)
* #212 - hacked websockets proxy together * faffing around * #212 hacking away :( * #212 websockets proxy middleware working * #212 map when for webockets working * #212 some test refactor * #212 temp commit * #212 websockets proxy working, tests passing...need to do some tidying and write docs * #212 more code coverage * #212 docs for websockets * #212 updated readme * #212 tidying up after websockets refactoring * #212 tidying up after websockets refactoring * #212 tidying up after websockets refactoring * changing logging levels and logging like ms reccomends with structured data rather than strings * more faffing * more fafin * #287 ocelot logger now only takes strings as it did take params then just turned them to strings, misleading, unit tests for logger and diagnosticlogger * #287 errors now logged as they happen * #287 more detail for logs requested in issue * #287 tidy up * #287 renamed * #287 always log context id * #287 fixed me being an idiot * #287 removed crap websockets unit test that isnt a unit test * #287 removed crap websockets unit test that isnt a unit test
This commit is contained in:
		
							
								
								
									
										75
									
								
								test/Ocelot.UnitTests/Middleware/OcelotMiddlewareTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								test/Ocelot.UnitTests/Middleware/OcelotMiddlewareTests.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Moq;
 | 
			
		||||
using Ocelot.Errors;
 | 
			
		||||
using Ocelot.Logging;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Ocelot.UnitTests.Responder;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Middleware
 | 
			
		||||
{
 | 
			
		||||
    public class OcelotMiddlewareTests
 | 
			
		||||
    {
 | 
			
		||||
        private Mock<IOcelotLogger> _logger;
 | 
			
		||||
        private FakeMiddleware _middleware;
 | 
			
		||||
        private List<Error> _errors;
 | 
			
		||||
 | 
			
		||||
        public OcelotMiddlewareTests()
 | 
			
		||||
        {
 | 
			
		||||
            _errors = new List<Error>();
 | 
			
		||||
            _logger = new Mock<IOcelotLogger>();
 | 
			
		||||
            _middleware = new FakeMiddleware(_logger.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_log_error()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => GivenAnError(new AnyError()))
 | 
			
		||||
                .When(x => WhenISetTheError())
 | 
			
		||||
                .Then(x => ThenTheErrorIsLogged(1))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_log_errors()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => GivenAnError(new AnyError()))
 | 
			
		||||
                .And(x => GivenAnError(new AnyError()))
 | 
			
		||||
                .When(x => WhenISetTheErrors())
 | 
			
		||||
                .Then(x => ThenTheErrorIsLogged(2))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenISetTheErrors()
 | 
			
		||||
        {
 | 
			
		||||
            _middleware.SetPipelineError(new DownstreamContext(new DefaultHttpContext()), _errors);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheErrorIsLogged(int times)
 | 
			
		||||
        {
 | 
			
		||||
            _logger.Verify(x => x.LogWarning("blahh"), Times.Exactly(times));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenISetTheError()
 | 
			
		||||
        {
 | 
			
		||||
            _middleware.SetPipelineError(new DownstreamContext(new DefaultHttpContext()), _errors[0]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenAnError(Error error)
 | 
			
		||||
        {
 | 
			
		||||
            _errors.Add(error);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class FakeMiddleware : OcelotMiddleware
 | 
			
		||||
    {
 | 
			
		||||
        public FakeMiddleware(IOcelotLogger logger) 
 | 
			
		||||
            : base(logger)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user