public void CreateContext_WhenValidValue_ExpectRequestCorrelationContext() { // arrange var correlationId = "valid_correlation"; var httpContext = new DefaultHttpContext { Request = { Headers = { [HttpHeaders.CorrelationId] = correlationId, } } }; var validationResult = ValidationResult.Valid; var validator = new Mock <ICorrelationValidator>(); validator .Setup(v => v.Validate(It.Is <string>(v => string.Equals(correlationId, v)))) .Returns(validationResult); // act var factory = new CorrelationContextFactory( new OptionsWrapper <CorrelatorOptions>(_baseOptions), validator.Object, _logger); var correlationContext = factory.CreateContext(httpContext); // assert var requestCorrelationContext = Assert.IsType <RequestCorrelationContext>(correlationContext); Assert.Equal(correlationId, correlationContext.CorrelationId.Value); }
public void CreateContext_WhenIncomingHeaderPresent_ExpectRequestCorrelationContext(string incomingHeader) { // arrange var correlationId = "123"; var httpContext = new DefaultHttpContext { Request = { Headers = { [incomingHeader] = correlationId, } } }; // act var factory = new CorrelationContextFactory(new OptionsWrapper <CorrelatorOptions>(_baseOptions), _logger); var correlationContext = factory.CreateContext(httpContext); // assert var requestCorrelationContext = Assert.IsType <RequestCorrelationContext>(correlationContext); Assert.Equal(correlationId, correlationContext.CorrelationId.Value); Assert.Equal(incomingHeader, requestCorrelationContext.Header); }
public void CreateContext_WhenNoFactory_ExpectEmptyCorrelationContext() { // arrange var httpContext = new DefaultHttpContext(); _baseOptions.Factory = null; // act var factory = new CorrelationContextFactory(new OptionsWrapper <CorrelatorOptions>(_baseOptions), _logger); var correlationContext = factory.CreateContext(httpContext); // assert Assert.IsType <EmptyCorrelationContext>(correlationContext); Assert.True(correlationContext.CorrelationId.IsEmpty); }
public void CreateContext_WhenGeneratingCorrelation_ExpectGeneratedCorrelationContext() { // arrange var correlationId = "123"; var httpContext = new DefaultHttpContext(); _baseOptions.Factory = _ => CorrelationId.FromString(correlationId); // act var factory = new CorrelationContextFactory(new OptionsWrapper <CorrelatorOptions>(_baseOptions), _logger); var correlationContext = factory.CreateContext(httpContext); // assert Assert.IsType <GeneratedCorrelationContext>(correlationContext); Assert.Equal(correlationId, correlationContext.CorrelationId.Value); }
public void CreateContext_WhenUnknownCorrelationHeader_ExpectEmptyCorrelationContext() { // arrange var httpContext = new DefaultHttpContext { Request = { Headers = { ["X-Yet-Another-Custom-Request-Id"] = "123", } } }; _baseOptions.Factory = null; // act var factory = new CorrelationContextFactory(new OptionsWrapper <CorrelatorOptions>(_baseOptions), _logger); var correlationContext = factory.CreateContext(httpContext); // assert Assert.IsType <EmptyCorrelationContext>(correlationContext); Assert.True(correlationContext.CorrelationId.IsEmpty); }