public async Task MiddlewareStartsNewId() { var contextUpdater = Substitute.For <ICorridContextUpdater>(); var context = new DefaultHttpContext(); var sut = new CorridMiddleware(_ => { contextUpdater.Received().BeginExecutionScope(); contextUpdater.DidNotReceive().EndExecutionScope(); return(Task.CompletedTask); }, contextUpdater); await sut.Invoke(context); contextUpdater.Received().EndExecutionScope(); }
public async Task MiddlewareUsesIdFromHeader() { var contextUpdater = Substitute.For <ICorridContextUpdater>(); var context = new DefaultHttpContext(); var fakeId = "ThisIsAnId"; context.Request.Headers.Append(CorridConstants.XCorrelationIdHeader, fakeId); var sut = new CorridMiddleware(_ => { contextUpdater.Received().BeginExecutionScope(Arg.Is(fakeId)); contextUpdater.DidNotReceive().EndExecutionScope(); return(Task.CompletedTask); }, contextUpdater); await sut.Invoke(context); contextUpdater.Received().EndExecutionScope(); }