Exemple #1
0
        public void Should_push_initial_state()
        {
            var sut         = new Store <int>(Reducers.PassThrough, 1);
            var spyListener = new SpyListener <int>();

            sut.SubscribeAndGetState(spyListener.Listen);

            CollectionAssert.AreEqual(new[] { 1 }, spyListener.Values);
        }
Exemple #2
0
        public void Should_only_push_the_last_state_before_subscription()
        {
            var sut         = new Store <int>(Reducers.Replace, 1);
            var spyListener = new SpyListener <int>();

            sut.Dispatch(new FakeAction <int>(2));
            sut.SubscribeAndGetState(spyListener.Listen);

            CollectionAssert.AreEqual(new[] { 2 }, spyListener.Values);
        }
Exemple #3
0
        public void Should_push_state_to_end_of_queue_on_nested_dispatch()
        {
            var sut         = new Store <int>(Reducers.Replace, 1);
            var spyListener = new SpyListener <int>();

            sut.SubscribeAndGetState(val =>
            {
                if (val < 5)
                {
                    sut.Dispatch(new FakeAction <int>(val + 1));
                }
                spyListener.Listen(val);
            });

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, spyListener.Values);
        }
Exemple #4
0
        public void Middleware_should_be_called_for_each_action_dispatched()
        {
            var numberOfCalls = 0;
            Middleware <int> spyMiddleware = store => next => action =>
            {
                numberOfCalls++;
                return(next(action));
            };

            var sut         = new Store <int>(Reducers.Replace, 1, spyMiddleware);
            var spyListener = new SpyListener <int>();

            sut.SubscribeAndGetState(spyListener.Listen);
            sut.Dispatch(new FakeAction <int>(2));

            Assert.AreEqual(1, numberOfCalls);
            CollectionAssert.AreEqual(new[] { 1, 2 }, spyListener.Values);
        }