public async Task TestReplayRecorder() { // Add a recorder middleware to enable hot reload by replaying previously recorded actions: var recorder = new ReplayRecorder <string>(); var recMiddleware = recorder.CreateMiddleware(); // Test that exceptions are thrown if ReplayStore is not yet ready to use: await Assert.ThrowsAsync <NullReferenceException>(async() => { await recorder.ReplayStore(); }); var store = new DataStore <string>(StateReducer, "", recMiddleware); await recorder.ReplayStore(); // Does nothing but does not throw an exception // Test that exceptions are thrown if an invalid nrOfActionsToReplay is passed into ReplayStore(): await Assert.ThrowsAsync <ArgumentException>(async() => { await recorder.ReplayStore(delayBetweenStepsInMs: 0, nrOfActionsToReplay: 1); }); // Test that Replay does not change the recorder.recordedActionsCount: Assert.Equal(0, recorder.recordedActionsCount); store.Dispatch("1"); // Dispatch a first event Assert.Equal(1, recorder.recordedActionsCount); // Now the count must be 1 await recorder.ReplayStore(); Assert.Equal(1, recorder.recordedActionsCount); // Recorded actions still 1 after replay }
private async Task TestReplayRecorderOnNewStore(ReplayRecorder <MyAppState1> recorder, MyAppState1 finalStateOfFirstStore) { var t = Log.MethodEntered("TestReplayRecorderOnNewStore"); // Connect the recorder to the new store: var recMiddleware = recorder.CreateMiddleware(); var undoable = new UndoRedoReducer <MyAppState1>(); var logging = Middlewares.NewLoggingMiddleware <MyAppState1>(); var data2 = new MyAppState1(null, null, 0); var store2 = new DataStore <MyAppState1>(undoable.Wrap(MyReducers1.ReduceMyAppState1), data2, logging, recMiddleware); store2.storeName = "Store 2"; // Replaying the recorder will now fill the second store with the same actions: await recorder.ReplayStore(); AssertEqualJson(finalStateOfFirstStore, store2.GetState()); Log.MethodDone(t); }
private async Task TestReplayRecorder(ReplayRecorder <MyAppState1> recorder, IDataStore <MyAppState1> store) { var t = Log.MethodEntered("TestReplayRecorder"); // First remember the final state of the store: var finalState = store.GetState(); // Then reset the store so that it is in its initial state again: recorder.ResetStore(); Assert.Null(store.GetState().user); Assert.Null(store.GetState().currentWeather); // Calling ReplayStore will replay all actions stored by the recorder so that the final state is restored: await recorder.ReplayStore(); Assert.NotEqual(0, recorder.recordedActionsCount); AssertEqualJson(finalState, store.GetState()); // The recorder middleware can also replay the actions into a second store: await TestReplayRecorderOnNewStore(recorder, finalState); Log.MethodDone(t); }