public void WhenCalled_ThenExecutesOnAllRegisteredMiddlewares()
        {
            int disposeCount   = 0;
            var mockMiddleware = new Mock <IMiddleware>();

            mockMiddleware
            .Setup(x => x.BeginInternalMiddlewareChange())
            .Returns(new DisposableCallback("Test", () => disposeCount++));

            var subject = new TestStore();

            subject.AddMiddleware(mockMiddleware.Object);

            var disposable1 = subject.BeginInternalMiddlewareChange();
            var disposable2 = subject.BeginInternalMiddlewareChange();

            disposable1.Dispose();
            Assert.Equal(0, disposeCount);

            disposable2.Dispose();
            Assert.Equal(1, disposeCount);
        }
        public async Task WhenIsInsideMiddlewareChange_ThenDoesNotDispatchActions()
        {
            var mockMiddleware = MockMiddlewareFactory.Create();

            var subject = new TestStore();
            await subject.InitializeAsync();

            subject.AddMiddleware(mockMiddleware.Object);

            var testAction = new TestAction();

            using (subject.BeginInternalMiddlewareChange())
            {
                subject.Dispatch(testAction);
            }

            mockMiddleware.Verify(x => x.MayDispatchAction(testAction), Times.Never);
        }