예제 #1
0
        public async Task WhenCalled_ThenCallsBeforeDispatchOnAllMiddlewares()
        {
            var testAction     = new TestAction();
            var mockMiddleware = MockMiddlewareFactory.Create();
            var subject        = new TestStore();
            await subject.InitializeAsync();

            subject.AddMiddleware(mockMiddleware.Object);

            subject.Dispatch(testAction);

            mockMiddleware
            .Verify(x => x.BeforeDispatch(testAction), Times.Once);
        }
예제 #2
0
            public void ExecutesBeforeDispatchActionOnMiddlewares()
            {
                var testAction     = new TestAction();
                var mockMiddleware = MockMiddlewareFactory.Create();
                var subject        = new Store(BrowserInteropStub);

                subject.AddMiddleware(mockMiddleware.Object);

                BrowserInteropStub._TriggerPageLoaded();
                subject.Dispatch(testAction);

                mockMiddleware
                .Verify(x => x.BeforeDispatch(testAction), Times.Once);
            }
예제 #3
0
            public void ExecutesBeforeDispatchActionOnMiddlewares()
            {
                var testAction     = new TestAction();
                var mockMiddleware = MockMiddlewareFactory.Create();
                var subject        = new Store(StoreInitializer);

                subject.Initialize();
                subject.AddMiddleware(mockMiddleware.Object);

                StoreInitializer.Complete();
                subject.Dispatch(testAction);

                mockMiddleware
                .Verify(x => x.BeforeDispatch(testAction), Times.Once);
            }
예제 #4
0
            public void DoesNotSendActionToFeatures_WhenMiddlewareForbidsIt()
            {
                var testAction     = new TestAction();
                var mockFeature    = MockFeatureFactory.Create();
                var mockMiddleware = MockMiddlewareFactory.Create();

                mockMiddleware
                .Setup(x => x.MayDispatchAction(testAction))
                .Returns(false);
                var subject = new Store(BrowserInteropStub);

                BrowserInteropStub._TriggerPageLoaded();
                subject.Dispatch(testAction);

                mockFeature
                .Verify(x => x.ReceiveDispatchNotificationFromStore(testAction), Times.Never);
            }
예제 #5
0
        public async Task WhenMiddlewareForbidsIt_ThenDoesNotSendActionToFeatures()
        {
            var testAction     = new TestAction();
            var mockFeature    = MockFeatureFactory.Create();
            var mockMiddleware = MockMiddlewareFactory.Create();

            mockMiddleware
            .Setup(x => x.MayDispatchAction(testAction))
            .Returns(false);
            var subject = new TestStore();
            await subject.InitializeAsync();

            subject.Dispatch(testAction);

            mockFeature
            .Verify(x => x.ReceiveDispatchNotificationFromStore(testAction), Times.Never);
        }
예제 #6
0
        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);
        }
예제 #7
0
            public void DoesNotDispatchActions_WhenIsInsideMiddlewareChange()
            {
                var mockMiddleware = MockMiddlewareFactory.Create();

                var subject = new Store(BrowserInteropStub);

                subject.AddMiddleware(mockMiddleware.Object);

                BrowserInteropStub._TriggerPageLoaded();

                var testAction = new TestAction();

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

                mockMiddleware.Verify(x => x.MayDispatchAction(testAction), Times.Never);
            }
예제 #8
0
            public void DoesNotSendActionToFeatures_WhenMiddlewareForbidsIt()
            {
                var testAction     = new TestAction();
                var mockFeature    = MockFeatureFactory.Create();
                var mockMiddleware = MockMiddlewareFactory.Create();

                mockMiddleware
                .Setup(x => x.MayDispatchAction(testAction))
                .Returns(false);
                var subject = new Store(StoreInitializer);

                subject.Initialize();

                StoreInitializer.Complete();
                subject.Dispatch(testAction);

                mockFeature
                .Verify(x => x.ReceiveDispatchNotificationFromStore(testAction), Times.Never);
            }
예제 #9
0
            public void DoesNotDispatchActions_WhenIsInsideMiddlewareChange()
            {
                var mockMiddleware = MockMiddlewareFactory.Create();

                var subject = new Store(StoreInitializer);

                subject.Initialize();
                subject.AddMiddleware(mockMiddleware.Object);

                StoreInitializer.Complete();

                var testAction = new TestAction();

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

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