public void ThrowException_NullClientIdGenerator() { var accessor = new TrafficCometMiddlewaresAccessor(); var logWriter = ITrafficLogWriterMockFactory.CreateMockObject(); var requestReadMiddleware = TrafficCometMiddlewareMockFactory.CreateMockObject(out HttpContext httpContext); var trafficLogFactory = ITrafficLogFactoryMockFactory.CreateMockObject(MockStaticData.MockLog); var traceIdGenerator = ITraceIdGeneratorMockFactory.CreateObjectMock(MockStaticData.TraceId); Assert.ThrowsAsync <ArgumentNullException>(() => requestReadMiddleware.Invoke(httpContext, accessor, logWriter, trafficLogFactory, traceIdGenerator, null)); }
internal async Task RunMiddlewareWithConfiguration(TrafficCometMiddlewareConfig config, string requestPath = null) { var accessor = new TrafficCometMiddlewaresAccessor(); var logWriter = ITrafficLogWriterMockFactory.CreateMockObject(); var trafficCometMiddleware = TrafficCometMiddlewareMockFactory.CreateMockObject(out HttpContext httpContext, config, requestPath); var trafficLogFactory = ITrafficLogFactoryMockFactory.CreateMockObject(MockStaticData.MockLog); var traceIdGenerator = ITraceIdGeneratorMockFactory.CreateObjectMock(MockStaticData.TraceId); var clientIdGenerator = IClientUniqueIdGeneratorMockFactory.CreateMockObject(MockStaticData.UserUniqueId); await trafficCometMiddleware.Invoke(httpContext, accessor, logWriter, trafficLogFactory, traceIdGenerator, clientIdGenerator); Assert.True(accessor.IgnoreWholeRequest); }
public async Task SuccessfullyRun() { var accessor = new TrafficCometMiddlewaresAccessor(); var logWriter = ITrafficLogWriterMockFactory.CreateMockObject(); var trafficCometMiddleware = TrafficCometMiddlewareMockFactory.CreateMockObject(out HttpContext httpContext); var trafficLogFactory = ITrafficLogFactoryMockFactory.CreateMockObject(MockStaticData.MockLog); var traceIdGenerator = ITraceIdGeneratorMockFactory.CreateObjectMock(MockStaticData.TraceId); var clientIdGenerator = IClientUniqueIdGeneratorMockFactory.CreateMockObject(MockStaticData.UserUniqueId); await trafficCometMiddleware.Invoke(httpContext, accessor, logWriter, trafficLogFactory, traceIdGenerator, clientIdGenerator); Assert.Null(accessor.ResponseBody); Assert.Null(accessor.RequestBody); Assert.False(accessor.IgnoreWholeRequest); Assert.AreEqual(accessor.TraceId, MockStaticData.TraceId); Assert.AreEqual(accessor.ClientUniqueId, MockStaticData.UserUniqueId); Assert.NotNull(httpContext.Response.Body); Assert.AreEqual(httpContext.Response.Body.Position, 0L); Assert.NotNull(httpContext.Request.Body); Assert.AreEqual(httpContext.Request.Body.Position, 0L); }