public async Task SaveCorrelationIdMustNotBeBeforeSaveClientTenantConfiguration()
        {
            const string url = "https://v-mock.org/v2/smoke-testing-company/ver";

#if NETCOREAPP
            var innerHandler  = new SaveClientTenantConfiguration(async ctx => await Task.CompletedTask, new Mock <ILeverServiceConfiguration>().Object);
            var middleHandler =
                new SaveClientTenant(innerHandler.InvokeAsync, SaveClientTenant.LegacyVersionPrefix);
            var outerHandler =
                new SaveCorrelationId(middleHandler.InvokeAsync);
            var context = new DefaultHttpContext();
            SetRequest(context, url);
#else
            var outerHandler = new SaveCorrelationId
            {
                InnerHandler = new SaveClientTenant(SaveClientTenant.LegacyVersionPrefix)
                {
                    InnerHandler = new SaveClientTenantConfiguration(new Mock <ILeverServiceConfiguration>().Object)
                    {
                        InnerHandler = new GetContextTestHandler()
                        {
                            InnerHandler = new Mock <HttpMessageHandler>().Object
                        }
                    }
                }
            };
            var invoker = new HttpMessageInvoker(outerHandler);
            var request = new HttpRequestMessage(HttpMethod.Get, url);
#endif

            try
            {
#if NETCOREAPP
                await outerHandler.InvokeAsync(context);
#else
                await invoker.SendAsync(request, CancellationToken.None);
#endif
                Assert.Fail("Expected an exception");
            }
            catch (FulcrumContractException e)
            {
                Assert.IsTrue(e.Message.Contains("must not precede"));
            }
            catch (Exception e)
            {
                Assert.Fail(
                    $"Expected an exception of type {nameof(FulcrumContractException)}, but caught exception {e.GetType().FullName}");
            }
        }
        public async Task SavedConfigurationWhenLoggingWithNoCorrelationId()
        {
            // Simulate a pipe of DelegatingHandlers where SaveConfiguration happens first
#if NETCOREAPP
            var innerHandler = new SaveCorrelationId(async context =>
            {
                _foundClientTenant  = FulcrumApplication.Context.ClientTenant;
                _foundCorrelationId = FulcrumApplication.Context.CorrelationId;
                await Task.CompletedTask;
            });
            var middleHandler = new SaveClientTenantConfiguration(innerHandler.InvokeAsync, new Mock <ILeverServiceConfiguration>().Object);
            var outerHandler  =
                new SaveClientTenant(middleHandler.InvokeAsync, SaveClientTenant.LegacyVersionPrefix);
#else
            var outerHandler = new SaveClientTenant(SaveClientTenant.LegacyVersionPrefix)
            {
                InnerHandler = new SaveClientTenantConfiguration(new Mock <ILeverServiceConfiguration>().Object)
                {
                    InnerHandler = new SaveCorrelationId
                    {
                        InnerHandler = new GetContextTestHandler()
                        {
                            InnerHandler = new Mock <HttpMessageHandler>().Object
                        }
                    }
                }
            };
#endif

            // Define Organization/Environment for the uri path
            const string org = "my-org";
            const string env = "prd";

            // Invoke a request and get back the tenant that was logged on
            var loggedTenant = await SavedConfigurationPlayingWithSaveCorrelationId(
#if NETCOREAPP
                outerHandler.InvokeAsync,
#else
                outerHandler,
#endif
                org, env);

            Assert.IsNotNull(_foundCorrelationId, "CorrelationId should have been created");
            Assert.AreEqual(_foundClientTenant, loggedTenant,
                            $"Expected the tenant on the value provider ('{_foundClientTenant}') to equal the logged tenant ('{loggedTenant}')");
        }