public void RepeatedEntryAndMatchingxitDecrementsToMinusOne()
        {
            // Arrange
            Mock <ICommandCorrelationIdProvider>     correlationIdProvider    = new Mock <ICommandCorrelationIdProvider>();
            Mock <ICommandDispatchContextEnrichment> commandContextEnrichment = new Mock <ICommandDispatchContextEnrichment>();

            correlationIdProvider.Setup(x => x.Create()).Returns("someid");
            AsyncLocalCommandScopeManager manager = new AsyncLocalCommandScopeManager(correlationIdProvider.Object, commandContextEnrichment.Object);

            // Act
            ICommandDispatchContext dispatchContext = manager.Enter();

            manager.Enter();
            manager.Enter();
            manager.Exit();
            manager.Exit();
            manager.Exit();

            // Assert
            Assert.Equal(-1, dispatchContext.Depth);
        }
        public void EntryAfterFinalExitCreatesNewContext()
        {
            // Arrange
            Mock <ICommandCorrelationIdProvider>     correlationIdProvider    = new Mock <ICommandCorrelationIdProvider>();
            Mock <ICommandDispatchContextEnrichment> commandContextEnrichment = new Mock <ICommandDispatchContextEnrichment>();

            correlationIdProvider.Setup(x => x.Create()).Returns(() => Guid.NewGuid().ToString());
            AsyncLocalCommandScopeManager manager = new AsyncLocalCommandScopeManager(correlationIdProvider.Object, commandContextEnrichment.Object);

            // Act
            ICommandDispatchContext initialDispatchContext = manager.Enter();

            manager.Exit();
            ICommandDispatchContext secondDispatchContext = manager.Enter();

            // Assert
            Assert.NotEqual(initialDispatchContext, secondDispatchContext);
            Assert.NotEqual(initialDispatchContext.CorrelationId, secondDispatchContext.CorrelationId);
        }