|
5 | 5 | usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions; |
6 | 6 | usingstaticReduxSimple.Effects; |
7 | 7 | usingTodoListStore=ReduxSimple.ReduxStore<ReduxSimple.Tests.Setup.TodoListStore.TodoListState>; |
| 8 | +usingSystem; |
8 | 9 |
|
9 | 10 | namespaceReduxSimple.Tests |
10 | 11 | { |
@@ -79,5 +80,56 @@ public void CanUseEffectWithoutDispatch() |
79 | 80 | store.State.TodoList.ShouldHaveSingleItem(); |
80 | 81 | calls.ShouldBe(1); |
81 | 82 | } |
| 83 | + |
| 84 | +[Fact] |
| 85 | +publicvoidCanReplayEffectWhenExceptionOccured() |
| 86 | +{ |
| 87 | +// Arrange |
| 88 | +varinitialState=CreateInitialTodoListState(); |
| 89 | +varstore=newTodoListStore( |
| 90 | +Setup.TodoListStore.Reducers.CreateReducers(), |
| 91 | +initialState |
| 92 | +); |
| 93 | +intcalls=0; |
| 94 | + |
| 95 | +vareffectWithDispatch=CreateEffect<TodoListState>( |
| 96 | +()=>store.ObserveAction<AddTodoItemAction>() |
| 97 | +.Do(_=>calls++) |
| 98 | +.Select(_=> |
| 99 | +{ |
| 100 | +thrownewException("Too bad!"); |
| 101 | + |
| 102 | +#pragma warning disableCS0162// Unreachable code detected |
| 103 | +returnnewAddTodoItemAction |
| 104 | +{ |
| 105 | +TodoItem=newTodoItem |
| 106 | +{ |
| 107 | +Id=2, |
| 108 | +Title="Listen to side effects" |
| 109 | +} |
| 110 | +}; |
| 111 | +#pragma warning restoreCS0162// Unreachable code detected |
| 112 | +}), |
| 113 | +true |
| 114 | +); |
| 115 | + |
| 116 | +store.RegisterEffects( |
| 117 | +effectWithDispatch |
| 118 | +); |
| 119 | + |
| 120 | +// Act #1 |
| 121 | +DispatchAddTodoItemAction(store,1,"Create unit tests"); |
| 122 | + |
| 123 | +// Assert #1 |
| 124 | +store.State.TodoList?.Count.ShouldBe(1); |
| 125 | +calls.ShouldBe(1); |
| 126 | + |
| 127 | +// Act #2 |
| 128 | +DispatchAddTodoItemAction(store,3,"Create unit tests, again"); |
| 129 | + |
| 130 | +// Assert #2 |
| 131 | +store.State.TodoList?.Count.ShouldBe(2); |
| 132 | +calls.ShouldBe(2); |
| 133 | +} |
82 | 134 | } |
83 | 135 | } |