public void When_starting_correlationContext_when_another_context_is_active_should_start_new()
            {
                const string parentContextId = nameof(parentContextId);
                const string innerContextId  = nameof(innerContextId);

                _sut.Correlate(parentContextId,
                               () =>
                {
                    CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext;
                    parentContext.Should().NotBeNull();
                    parentContext.CorrelationId.Should().Be(parentContextId);

                    _sut.Correlate(innerContextId,
                                   () =>
                    {
                        CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext;
                        innerContext.Should().NotBeNull();
                        innerContext.Should().NotBe(parentContext);
                        innerContext.CorrelationId.Should().Be(innerContextId);
                    });

                    _correlationContextAccessor.CorrelationContext.Should().NotBeNull();

                    _correlationContextAccessor.CorrelationContext
                    .CorrelationId
                    .Should()
                    .Be(parentContextId);
                });
            }
            public Task When_starting_correlationContext_when_another_context_is_active_should_start_new()
            {
                const string parentContextId = nameof(parentContextId);
                const string innerContextId  = nameof(innerContextId);

                return(_sut.CorrelateAsync(parentContextId,
                                           async() =>
                {
                    CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext;
                    parentContext.Should().NotBeNull();
                    parentContext.CorrelationId.Should().Be(parentContextId);

                    await _sut.CorrelateAsync(innerContextId,
                                              () =>
                    {
                        CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext;
                        innerContext.Should().NotBeNull();
                        innerContext.Should().NotBe(parentContext);
                        innerContext.CorrelationId.Should().Be(innerContextId);

                        return Task.CompletedTask;
                    });

                    _correlationContextAccessor.CorrelationContext.Should().NotBeNull();

                    _correlationContextAccessor.CorrelationContext
                    .CorrelationId
                    .Should()
                    .Be(parentContextId);
                }));
            }
            public Task When_starting_correlationContext_with_legacy_ctor_when_another_context_is_active_should_not_throw()
            {
                const string parentContextId = nameof(parentContextId);

#pragma warning disable 618 // justification, covering legacy implementation (pre v3.0)
                var sut = new CorrelationManager(
                    new CorrelationContextFactory(_correlationContextAccessor),
                    _correlationIdFactoryMock.Object,
                    new NullLogger <CorrelationManager>()
                    );
#pragma warning restore 618

                return(sut.CorrelateAsync(parentContextId,
                                          async() =>
                {
                    CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext;
                    parentContext.Should().NotBeNull();
                    parentContext.CorrelationId.Should().Be(parentContextId);

                    await sut.CorrelateAsync(() =>
                    {
                        CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext;
                        innerContext.Should().NotBeNull().And.NotBe(parentContext);
                        innerContext.CorrelationId.Should().NotBe(parentContextId);

                        return Task.CompletedTask;
                    });
                }));
            }
            public void When_starting_correlationContext_inside_running_context_without_specifying_should_reuse()
            {
                _sut.Correlate(() =>
                {
                    CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext;

                    _sut.Correlate(() =>
                    {
                        CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext;
                        innerContext.Should()
                        .NotBe(parentContext)
                        .And.BeEquivalentTo(parentContext);
                    });
                });
            }
            public Task When_starting_correlationContext_inside_running_context_without_specifying_should_reuse()
            {
                return(_sut.CorrelateAsync(async() =>
                {
                    CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext;

                    await _sut.CorrelateAsync(() =>
                    {
                        CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext;
                        innerContext.Should()
                        .NotBe(parentContext)
                        .And.BeEquivalentTo(parentContext);

                        return Task.CompletedTask;
                    });
                }));
            }