Пример #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);
            }