예제 #1
0
        public void When_ActionDispatched_Should_ReduceState()
        {
            // Arrange
            var initialState = new object();
            var reducedState = new object();
            var store        = new Store <object>(Reducers.Return(reducedState), initialState);

            // Act
            store.Dispatch(null);

            // Assert
            Assert.That(store.State, Is.SameAs(reducedState));
        }
예제 #2
0
        public void When_StateChanged_Should_PassNewStateInEvent()
        {
            // Arrange
            var    newState   = new object();
            object eventState = null;
            var    store      = new Store <object>(Reducers.Return(newState), new object());

            store.StateChanged += state => eventState = state;

            // Act
            store.Dispatch(null);

            // Assert
            Assert.That(eventState, Is.SameAs(newState));
        }
예제 #3
0
        public void Listener_Should_GetStateBeforeAction()
        {
            // Arrange
            var    initialState            = new object();
            var    newState                = new object();
            object stateReceivedByListener = null;

            var listener           = new Listener <object>((action, state, dispatcher) => stateReceivedByListener = state);
            var listenerMiddleware = new ListenerMiddleware <object>();

            listenerMiddleware.ActionReceived += listener;
            var store = new Store <object>(Reducers.Return(newState), initialState, listenerMiddleware.CreateMiddleware);

            // Act
            store.Dispatch(null);

            // Assert
            Assert.That(stateReceivedByListener, Is.SameAs(initialState));
        }