Пример #1
0
        public void ApplyShowForwardCallToRegisteredReducer()
        {
            Mock <IReducer <TestState> > mockIReducer = new Mock <IReducer <TestState> >();

            mockIReducer.Setup(x => x.Apply(It.IsAny <TestState>(), It.IsAny <object>())).Returns(new TestState());
            ReducerComposer <TestState> composer = new ReducerComposer <TestState>();

            composer.AddStateReducer(mockIReducer.Object);
            var result = composer.Apply(new TestState(), "");

            mockIReducer.Verify(x => x.Apply(It.IsAny <TestState>(), It.IsAny <object>()));
        }
Пример #2
0
        public void TestMultiDispatcherScope()
        {
            var reducer = new ReducerComposer <AppState>();
            Mock <IReducer <AppState> > mockReducer = new Mock <IReducer <AppState> >();

            mockReducer.Setup(x => x.Apply(It.IsAny <AppState>(), It.IsAny <object>())).Returns(() => new AppState());
            reducer.AddStateReducer(mockReducer.Object);
            Store <AppState> store = new Store <AppState>(reducer, new AppState());
            int countEvent         = 0;

            store.StateChanged += (s, e) =>
            {
                countEvent++;
            };
            using (var dispatcher = MultiDispatcher.Create(store))
            {
                dispatcher.Dispatch("1");
                dispatcher.Dispatch("2");
                dispatcher.Dispatch("3");
                using (var scope = dispatcher.BeginScope())
                {
                    scope.Dispatch("s1");
                    scope.Dispatch("s2");
                    scope.Dispatch("s3");
                }
                dispatcher.Dispatch("4");
                dispatcher.Dispatch("5");
            }
            Assert.AreEqual(2, countEvent);

            countEvent = 0;
            using (var dispatcher = MultiDispatcher.Create(store))
            {
                dispatcher.Dispatch("1");
                dispatcher.Dispatch("2");
                dispatcher.Dispatch("3");
                using (var scope = dispatcher.BeginScope())
                {
                    scope.Dispatch("s1");
                    scope.Dispatch("s2");
                    scope.Dispatch("s3");
                }
                dispatcher.Dispatch("4");
                dispatcher.Dispatch("5");
                using (var scope = dispatcher.BeginScope())
                {
                    scope.Dispatch("s1");
                    scope.Dispatch("s2");
                    scope.Dispatch("s3");
                }
            }
            Assert.AreEqual(3, countEvent);
        }
Пример #3
0
        public void CanBeUsedAsRootReducer()
        {
            Mock <IReducer <TestState> > mockIReducer = new Mock <IReducer <TestState> >();

            mockIReducer.Setup(x => x.Apply(It.IsAny <TestState>(), It.IsAny <object>())).Returns(new TestState());
            ReducerComposer <TestState> composer = new ReducerComposer <TestState>();

            composer.AddStateReducer(mockIReducer.Object);

            Store <TestState> store = new Store <TestState>(composer, new TestState());

            store.Dispatch("");
            mockIReducer.Verify(x => x.Apply(It.IsAny <TestState>(), It.IsAny <object>()));
        }
Пример #4
0
        public void TestDispatchWorksOutsideScopeOfMultiDispatcher()
        {
            var reducer = new ReducerComposer <AppState>();
            Mock <IReducer <AppState> > mockReducer = new Mock <IReducer <AppState> >();

            mockReducer.Setup(x => x.Apply(It.IsAny <AppState>(), It.IsAny <object>())).Returns(() => new AppState());
            reducer.AddStateReducer(mockReducer.Object);
            Store <AppState> store = new Store <AppState>(reducer, new AppState());
            int countEvent         = 0;

            store.StateChanged += (s, e) =>
            {
                countEvent++;
            };
            store.Dispatch("1");
            using (var dispatcher = MultiDispatcher.Create(store))
            {
                dispatcher.Dispatch("2");
            }
            store.Dispatch("3");
            Assert.AreEqual(3, countEvent);
        }
Пример #5
0
        public void TestMultipleCallsToDispatchImmediateMethodFiresTheEventSameNumberOfTimes()
        {
            var reducer = new ReducerComposer <AppState>();
            Mock <IReducer <AppState> > mockReducer = new Mock <IReducer <AppState> >();

            mockReducer.Setup(x => x.Apply(It.IsAny <AppState>(), It.IsAny <object>())).Returns(() => new AppState());
            reducer.AddStateReducer(mockReducer.Object);
            Store <AppState> store = new Store <AppState>(reducer, new AppState());
            int countEvent         = 0;

            store.StateChanged += (s, e) =>
            {
                countEvent++;
            };
            using (var dispatcher = MultiDispatcher.Create(store))
            {
                dispatcher.DispatchImmediate("1");
                dispatcher.DispatchImmediate("2");
                dispatcher.DispatchImmediate("3");
            }
            Assert.AreEqual(3, countEvent);
        }