public void can_only_restore_once() { var rm = new TestSnapShotReadModel(_aggId, GetListener, null); // ReSharper disable once AccessToDisposedClosure AssertEx.IsOrBecomesTrue(() => rm.Count == 10); var state = rm.GetState(); rm.Dispose(); //create while forcing double restore Assert.Throws <InvalidOperationException>(() => new TestSnapShotReadModel( _aggId, GetListener, state, forceDoubleRestoreError: true)); }
public void can_get_snapshot_from_read_model() { var rm = new TestSnapShotReadModel(_aggId, GetListener, null); AssertEx.IsOrBecomesTrue(() => rm.Count == 10); var snapshot = rm.GetState(); Assert.Equal(nameof(TestSnapShotReadModel), snapshot.ModelName); Assert.Single(snapshot.Checkpoints); Assert.Equal(_stream, snapshot.Checkpoints[0].Item1); Assert.Equal(9, snapshot.Checkpoints[0].Item2); var state = snapshot.State as TestSnapShotReadModel.MyState; Assert.NotNull(state); Assert.Equal(10, state.Count); Assert.Equal(20, state.Sum); }
public void can_apply_snapshot_to_read_model() { var snapshot = new ReadModelState( nameof(TestSnapShotReadModel), new List <Tuple <string, long> > { new Tuple <string, long>(_stream, 9) }, new TestSnapShotReadModel.MyState { Count = 10, Sum = 20 }); var rm = new TestSnapShotReadModel(_aggId, GetListener, snapshot); AssertEx.IsOrBecomesTrue(() => rm.Count == 10); AssertEx.IsOrBecomesTrue(() => rm.Sum == 20); AppendEvents(1, _conn, _stream, 5); AssertEx.IsOrBecomesTrue(() => rm.Count == 11, 1000); AssertEx.IsOrBecomesTrue(() => rm.Sum == 25); }
public void can_snapshot_and_recover_read_model() { var rm = new TestSnapShotReadModel(_aggId, GetListener, null); AssertEx.IsOrBecomesTrue(() => rm.Count == 10); AssertEx.IsOrBecomesTrue(() => rm.Sum == 20); AppendEvents(1, _conn, _stream, 5); AssertEx.IsOrBecomesTrue(() => rm.Count == 11, 1000); AssertEx.IsOrBecomesTrue(() => rm.Sum == 25); var snap = rm.GetState(); rm.Dispose(); var rm2 = new TestSnapShotReadModel(_aggId, GetListener, snap); AssertEx.IsOrBecomesTrue(() => rm2.Count == 11, 1000); AssertEx.IsOrBecomesTrue(() => rm2.Sum == 25); AppendEvents(1, _conn, _stream, 5); AssertEx.IsOrBecomesTrue(() => rm2.Count == 12, 1000); AssertEx.IsOrBecomesTrue(() => rm2.Sum == 30); }
public void can_restore_state_without_checkpoints() { var snapshot = new ReadModelState( nameof(TestSnapShotReadModel), null, //no streams provided new TestSnapShotReadModel.MyState { Count = 10, Sum = 20 }); var rm = new TestSnapShotReadModel(_aggId, GetListener, snapshot); AssertEx.IsOrBecomesTrue(() => rm.Count == 10); AssertEx.IsOrBecomesTrue(() => rm.Sum == 20); //n.b. will not start listening because no streams are provided //confirm not listening AppendEvents(1, _conn, _stream, 5); AssertEx.IsOrBecomesTrue(() => rm.Count == 10, 1000); AssertEx.IsOrBecomesTrue(() => rm.Sum == 20); //can manually start rm.Start <SnapReadModelTestAggregate>(_aggId, 9, true); AssertEx.IsOrBecomesTrue(() => rm.Count == 11, 1000); AssertEx.IsOrBecomesTrue(() => rm.Sum == 25); AppendEvents(1, _conn, _stream, 5); AssertEx.IsOrBecomesTrue(() => rm.Count == 12, 1000); AssertEx.IsOrBecomesTrue(() => rm.Sum == 30); //can still get complete snapshot var snap2 = rm.GetState(); //works as expected var rm2 = new TestSnapShotReadModel(_aggId, GetListener, snap2); AssertEx.IsOrBecomesTrue(() => rm2.Count == 12, 1000); AssertEx.IsOrBecomesTrue(() => rm2.Sum == 30); AppendEvents(1, _conn, _stream, 5); AssertEx.IsOrBecomesTrue(() => rm2.Count == 13, 1000); AssertEx.IsOrBecomesTrue(() => rm2.Sum == 35); }