public void WhenHeaderIsPresentExistingCorrelationContextIsAvailable()
        {
            var httpContext = new DefaultHttpContext
            {
                RequestServices = new Moq.Mock <IServiceProvider>().Object
            };
            var header = "eyJpZCI6ImNvcnJlbGF0aW9uaWQiLAoic291cmNlSWQiOiIxIiwKInNvdXJjZU5hbWUiOiJ0ZXN0bmFtZSIsCiJpbnN0YW5jZUlkIjoiMiIsCiJpbnN0YW5jZU5hbWUiOiJ0ZXN0aW5zdGFuY2UiLAp1c2VySWQiOiJ1bmtvd251c2VyIiwKImlwQWRkcmVzcyI6IjEyMy4xMjMuMTIzLjEyMyJ9";

            httpContext.Request.Headers.Add(CorrelationHeader.Key, header);

            var httpContextAccessor = new Moq.Mock <IHttpContextAccessor>();

            httpContextAccessor.SetupProperty <HttpContext>(x => x.HttpContext, httpContext);
            var applicationContext          = new Moq.Mock <IApplicationContext>().Object;
            var logger                      = new Moq.Mock <ILogger <CorrelationService> >().Object;
            var correlationContextFormatter = new Moq.Mock <ICorrelationContextFormatter>();

            correlationContextFormatter.Setup(x => x.ValidateAndSetPropertiesFromDgpHeader(header)).Returns(new CorrelationContext {
                DgpHeader = header
            });
            var correlationContext = new Moq.Mock <IScopedCorrelationContext>().Object;

            var service = new CorrelationService(httpContextAccessor.Object, applicationContext, logger, correlationContextFormatter.Object, correlationContext);
            var context = service.GetContext();


            Assert.Equal(header, context.DgpHeader);
        }
        public void WhenDuplicateHeaderCorrelationContextIsCreated()
        {
            var httpContext = new DefaultHttpContext
            {
                RequestServices = new Moq.Mock <IServiceProvider>().Object
            };

            var httpContextAccessor = new Moq.Mock <IHttpContextAccessor>();

            httpContextAccessor.SetupProperty <HttpContext>(x => x.HttpContext, httpContext);
            var applicationContext          = new Moq.Mock <IApplicationContext>().Object;
            var logger                      = new TestLogger <CorrelationService>(new List <string>());
            var correlationContextFormatter = new Moq.Mock <ICorrelationContextFormatter>();

            var service = new CorrelationService(httpContextAccessor.Object, applicationContext, logger, correlationContextFormatter.Object);
            var context = service.GetContext();

            Assert.NotNull(context.DgpHeader);
            Assert.NotNull(context.Id);
        }