public void AddCorrelationId_without_existing_correlationId_set_correlationId() { var correlationId = Guid.NewGuid().ToString("D"); var configuration = Substitute.For <IConfiguration>(); configuration[CorrelationProvider.CorrelationIdConfigKey].Returns(CorrelationProvider.DefaultCorrelationIdHeaderKey); var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); httpContextAccessor.HttpContext.Returns(new DefaultHttpContext()); var correlationIdProvider = new CorrelationProvider(configuration, httpContextAccessor); correlationIdProvider.AddCorrelationId(); httpContextAccessor.HttpContext.Request.Headers[CorrelationProvider.DefaultCorrelationIdHeaderKey].Should().NotBeNullOrEmpty(); }
public void AddCorrelationId_with_correlationId_set_does_change_correlationId() { var correlationId = Guid.NewGuid().ToString("D"); var configuration = Substitute.For <IConfiguration>(); configuration[CorrelationProvider.CorrelationIdConfigKey].Returns(CorrelationProvider.DefaultCorrelationIdHeaderKey); var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); httpContextAccessor.HttpContext.Returns(new DefaultHttpContext()); httpContextAccessor.HttpContext.Request.Headers[CorrelationProvider.DefaultCorrelationIdHeaderKey] = correlationId; var correlationIdProvider = new CorrelationProvider(configuration, httpContextAccessor); correlationIdProvider.AddCorrelationId(); httpContextAccessor.HttpContext.Request.Headers[CorrelationProvider.DefaultCorrelationIdHeaderKey].Should().BeEquivalentTo(correlationId); }