コード例 #1
0
        public void ToggleItemCompletionWithInvalidIndex()
        {
            var store = new TodoStore();

            store.Dispatch(new AddTodoAction()
            {
                text = "Learn Redux"
            });
            store.Dispatch(new AddTodoAction()
            {
                text = "Start first project"
            });
            store.Dispatch(new AddTodoAction()
            {
                text = "Ship products"
            });

            store.Dispatch(new ToggleTodoAction()
            {
                index = 3
            });                                             // No effects
            store.Dispatch(new ToggleTodoAction()
            {
                index = -1
            });                                              // No effects

            Assert.AreEqual(EVisibilityFilter.SHOW_ALL, store.GetState().visibilityFilter);
            Assert.AreEqual(3, store.GetState().todos.Count);
            Assert.AreEqual("Ship products", store.GetState().todos[2].text);
            Assert.AreEqual(false, store.GetState().todos[2].completed);
        }
コード例 #2
0
        public void StateDoNotChangeWhenReducerThrowsException()
        {
            var store = new TodoStore();

            store.Dispatch(new AddTodoAction()
            {
                text = "Learn Redux"
            });
            store.Dispatch(new AddTodoAction()
            {
                text = "Start first project"
            });
            store.Dispatch(new AddTodoAction()
            {
                text = "Ship products"
            });

            Assert.AreEqual(3, store.GetState().todos.Count);

            try {
                store.Dispatch(new BuggyAction());
                // Exception should have been thrown
                Assert.Fail();
            } catch (System.Exception exception) {
                Assert.AreEqual("BuggyAction", exception.Message);
            }

            // The state should have been reserved on destructive action
            Assert.AreEqual(3, store.GetState().todos.Count);
        }
コード例 #3
0
        public void AddFirstTodoItem()
        {
            var store = new TodoStore();

            store.Dispatch(new AddTodoAction()
            {
                text = "Learn Redux"
            });

            Assert.AreEqual(EVisibilityFilter.SHOW_ALL, store.GetState().visibilityFilter);
            Assert.AreEqual(1, store.GetState().todos.Count);
            Assert.AreEqual("Learn Redux", store.GetState().todos[0].text);
            Assert.AreEqual(false, store.GetState().todos[0].completed);
        }
コード例 #4
0
        public void ToggleVisibility()
        {
            var store = new TodoStore();

            store.Dispatch(new SetVisibilityFilterAction()
            {
                filter = EVisibilityFilter.SHOW_COMPLETED
            });
            Assert.AreEqual(EVisibilityFilter.SHOW_COMPLETED, store.GetState().visibilityFilter);
        }
コード例 #5
0
        public void AddMoreTodoItems()
        {
            var store = new TodoStore();

            store.Dispatch(new AddTodoAction()
            {
                text = "Learn Redux"
            });
            store.Dispatch(new AddTodoAction()
            {
                text = "Start first project"
            });
            store.Dispatch(new AddTodoAction()
            {
                text = "Ship products"
            });

            Assert.AreEqual(EVisibilityFilter.SHOW_ALL, store.GetState().visibilityFilter);
            Assert.AreEqual(3, store.GetState().todos.Count);
            Assert.AreEqual("Ship products", store.GetState().todos[2].text);
            Assert.AreEqual(false, store.GetState().todos[2].completed);
        }
コード例 #6
0
        public void StoreShouldHaveDefaultState()
        {
            var store = new TodoStore();

            Assert.AreEqual(null, store.GetState());
        }