Пример #1
0
        public override IDisposable Subscribe(IObserver <Any> observer)
        {
            var reducer               = new PageReplaceReducer();
            var valueNode             = new ValueNode(this.Parent, this.Page);
            var stateActionWriterNode = new StateActionWriterNode(
                valueNode, "page", StoreHolder, reducer
                );

            return(stateActionWriterNode.Subscribe(observer));
        }
Пример #2
0
        public void ReduceTest()
        {
            var reducer = new PageReplaceReducer();
            var state   = new State();

            state.SetValue <PageStack>(PageConst.StateStackKey, new PageStack());
            state.SetValue <PageDefinition>(PageConst.StateDefinitionKey, new PageDefinition
            {
                PermanentScenes = new[] { "PermanentScene1" },
                PageScenes      = new[]
                {
                    new PageScene
                    {
                        Name   = "Page1",
                        Scenes = new[]
                        {
                            "Scene1",
                            "Scene2"
                        },
                    },
                    new PageScene
                    {
                        Name   = "Page2",
                        Scenes = new[]
                        {
                            "Scene1",
                            "Scene3"
                        },
                    }
                }
            });
            state.SetValue <IDictionary <string, bool> >(SceneConst.StateKey, new Dictionary <string, bool>()
            {
                { "Scene1", true },
                { "Scene2", false },
                { "Scene3", false },
                { "Scene4", true },
                { "PermanentScene1", true },
            });


            // move to page1
            {
                var page1 = new Page {
                    Name = "Page1", Data = null
                };
                var action1 = new StateAction(reducer, "page", new Any(page1));
                state = reducer.Reduce(state, action1);

                var sceneMap = state.GetValue <IDictionary <string, bool> >(SceneConst.StateKey);
                Assert.That(sceneMap.Count, Is.EqualTo(5));
                Assert.That(sceneMap["Scene1"], Is.True);
                Assert.That(sceneMap["Scene2"], Is.True);
                Assert.That(sceneMap["Scene3"], Is.False);
                Assert.That(sceneMap["Scene4"], Is.False);
                Assert.That(sceneMap["PermanentScene1"], Is.True);

                var pageStack = state.GetValue <PageStack>(PageConst.StateStackKey);
                Assert.That(pageStack.Count, Is.EqualTo(1));
                Assert.That(pageStack.Peek().Name, Is.EqualTo("Page1"));
            }

            // move to page2
            {
                var page2 = new Page {
                    Name = "Page2", Data = null
                };
                var action2 = new StateAction(reducer, "page", new Any(page2));
                state = reducer.Reduce(state, action2);

                var sceneMap = state.GetValue <IDictionary <string, bool> >(SceneConst.StateKey);
                Assert.That(sceneMap.Count, Is.EqualTo(5));
                Assert.That(sceneMap["Scene1"], Is.True);
                Assert.That(sceneMap["Scene2"], Is.False);
                Assert.That(sceneMap["Scene3"], Is.True);
                Assert.That(sceneMap["Scene4"], Is.False);
                Assert.That(sceneMap["PermanentScene1"], Is.True);

                var pageStack = state.GetValue <PageStack>(PageConst.StateStackKey);
                Assert.That(pageStack.Count, Is.EqualTo(1));
                Assert.That(pageStack.Peek().Name, Is.EqualTo("Page2"));
            }

            // assert
            {
                var action = new StateAction(reducer, "page", new Any("page"));
                Assert.Throws <ArgumentException>(() => { state = reducer.Reduce(state, action); });
            }
        }