public void Test__Base() { // Arrange var initialState = new State(); var redux = ReduxBuilder.New <State, ActionEnums>() .WithInitialState(initialState) .WithErrorHandler((state, action, exception) => { }) .WithMiddleware(x => x) .Build(); // Act, Assert Assert.Equal(initialState, redux.CurrentState); Assert.Single(redux.States); Assert.Contains(redux.States.Select(x => x.Key), x => x == initialState); }
public async Task Test__Reducers() { // Arrange var initialState = new State(); var redux = ReduxBuilder.New <State, ActionEnums>() .WithInitialState(initialState) .WithErrorHandler((state, action, exception) => { }) .WithMiddleware(state => state) .WithReducer <AddAction>(ActionEnums.Add, (state, addAction) => { // ReSharper disable once ConvertToLambdaExpression return(new State { Values = state.Values.Add(addAction.Value) }); }) .WithReducer <DeleteAction>(ActionEnums.Delete, (state, deleteAction) => { // ReSharper disable once ConvertToLambdaExpression return(new State { Values = state.Values.Remove(deleteAction.Value) }); }) .Build(); // Act await redux.Dispatch(new AddAction { Value = "Item1" }); await redux.Dispatch(new DeleteAction { Value = "Item1" }); await redux.Dispatch(new AddAction { Value = "Item2" }); // Assert Assert.Single(redux.CurrentState.Values); Assert.Equal(4, redux.States.Count); Assert.Equal("Item2", redux.CurrentState.Values.First()); }