public async Task Should_read_status_from_snapshot() { A.CallTo(() => snapshotStore.ReadAsync(key)) .Returns((2, 2L)); SetupEventStore(3, 2); await sut.GetSingleAsync <MyStatefulObjectWithSnapshot>(key); A.CallTo(() => eventStore.GetEventsAsync(key, 3)) .MustHaveHappened(); }
public void Should_configure_new_keys() { A.CallTo(() => store.ReadAsync(A <DomainId> ._, default)) .Returns((null !, true, 0)); var options = new OpenIddictServerOptions(); sut.Configure(options); Assert.NotEmpty(options.SigningCredentials); Assert.NotEmpty(options.EncryptionCredentials); A.CallTo(() => store.WriteAsync(A <DomainId> ._, A <DefaultKeyStore.State> ._, 0, 0, default)) .MustHaveHappenedOnceExactly(); }
public async Task Should_read_status_from_snapshot() { A.CallTo(() => snapshotStore.ReadAsync(key)) .Returns((2, 2L)); SetupEventStore(3, 2); var persistedState = -1; var persistedEvents = new List <IEvent>(); var persistence = sut.WithSnapshotsAndEventSourcing(None.Type, key, (int x) => persistedState = x, x => persistedEvents.Add(x.Payload)); await persistence.ReadAsync(); A.CallTo(() => eventStore.QueryAsync(key, 3)) .MustHaveHappened(); }
public async Task Should_generate_signing_credentials_once() { A.CallTo(() => store.ReadAsync(A <Guid> ._)) .Returns((null !, 0)); var credentials1 = await sut.GetSigningCredentialsAsync(); var credentials2 = await sut.GetSigningCredentialsAsync(); Assert.Same(credentials1, credentials2); A.CallTo(() => store.ReadAsync(A <Guid> ._)) .MustHaveHappenedOnceExactly(); A.CallTo(() => store.WriteAsync(A <Guid> ._, A <DefaultKeyStore.State> ._, 0, 0)) .MustHaveHappenedOnceExactly(); }
public async Task Should_read_from_store() { statefulObject.ExpectedVersion = 1; A.CallTo(() => snapshotStore.ReadAsync(key)) .Returns((123, 1)); var actualObject = await sut.GetSingleAsync <MyStatefulObject, string>(key); Assert.Same(statefulObject, actualObject); Assert.NotNull(cache.Get <object>(key)); Assert.Equal(123, statefulObject.State); }
public async Task Should_read_from_store() { A.CallTo(() => snapshotStore.ReadAsync(key)) .Returns((20, 10)); var persistedState = 0; var persistence = sut.WithSnapshots <object, int, string>(key, x => persistedState = x); await persistence.ReadAsync(); Assert.Equal(10, persistence.Version); Assert.Equal(20, persistedState); }
public async Task Should_read_from_store() { A.CallTo(() => snapshotStore.ReadAsync(key)) .Returns((20, true, 10)); var persistedState = Save.Snapshot(0); var persistence = sut.WithSnapshots(None.Type, key, persistedState.Write); await persistence.ReadAsync(); Assert.Equal(10, persistence.Version); Assert.Equal(20, persistedState.Value); }
public async Task Should_read_read_from_snapshot_store() { A.CallTo(() => snapshotStore.ReadAsync(key, A <CancellationToken> ._)) .Returns(("2", true, 2L)); SetupEventStore(3, 2); var persistedState = Save.Snapshot(string.Empty); var persistedEvents = Save.Events(); var persistence = sut.WithSnapshotsAndEventSourcing(None.Type, key, persistedState.Write, persistedEvents.Write); await persistence.ReadAsync(); Assert.False(persistence.IsSnapshotStale); A.CallTo(() => eventStore.QueryAsync(key.ToString(), 3, A <CancellationToken> ._)) .MustHaveHappened(); }
private async Task ReadSnapshotAsync() { if (UseSnapshots()) { var(state, position) = await snapshotStore.ReadAsync(ownerKey); if (position < EtagVersion.Empty) { position = EtagVersion.Empty; } versionSnapshot = position; versionEvents = position; if (applyState != null && position >= 0) { applyState(state); } } }
public async Task Should_read_status_from_snapshot() { A.CallTo(() => snapshotStore.ReadAsync(key)) .Returns((2, 2L)); SetupEventStore(3, 2); var persistedState = Save.Snapshot(-1); var persistedEvents = Save.Events(); var persistence = sut.WithSnapshotsAndEventSourcing(None.Type, key, persistedState.Write, persistedEvents.Write); await persistence.ReadAsync(); A.CallTo(() => eventStore.QueryAsync(key, 3)) .MustHaveHappened(); }