protected async Task <ThingySnapshot> LoadSnapshotAsync(ThingyId thingyId)
        {
            var snapshotContainer = await SnapshotStore.LoadSnapshotAsync <ThingyAggregate, ThingyId, ThingySnapshot>(
                thingyId,
                CancellationToken.None)
                                    .ConfigureAwait(false);

            return((ThingySnapshot)snapshotContainer?.Snapshot);
        }
Exemple #2
0
        public async Task Should_load_snapshot_in_snapshot_repository()
        {
            //Arrange
            var stream             = "stream";
            var descriptor         = new SnapshotDescriptor("aaa", "", stream, 5);
            var snapshotRepository = new Mock <ISnapshotRepository>();

            snapshotRepository.Setup(x => x.LoadSnapshotAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(descriptor));

            var eventSerDes = new Mock <IEventStoreSerDes>();
            var sut         = new SnapshotStore(snapshotRepository.Object, eventSerDes.Object, Mock.Of <ILogger <SnapshotStore> >());

            //Act
            var snapshot = await sut.LoadSnapshotAsync(stream, It.IsAny <CancellationToken>());

            //Assert
            snapshotRepository.Verify(er => er.LoadSnapshotAsync(stream, It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task OldSnapshotsAreUpgradedToLatestVersionAndHaveCorrectMetadata()
        {
            // Arrange
            var thingyId         = A <ThingyId>();
            var pingIds          = Many <PingId>();
            var expectedVersion  = pingIds.Count;
            var thingySnapshotV1 = new ThingySnapshotV1(pingIds);

            await StoreSnapshotAsync(thingyId, expectedVersion, thingySnapshotV1).ConfigureAwait(false);

            // Act
            var snapshotContainer = await SnapshotStore.LoadSnapshotAsync <ThingyAggregate, ThingyId, ThingySnapshot>(
                thingyId,
                CancellationToken.None)
                                    .ConfigureAwait(false);

            // Assert
            snapshotContainer.Snapshot.Should().BeOfType <ThingySnapshot>();
            snapshotContainer.Metadata.AggregateId.Should().Be(thingyId.Value);
            snapshotContainer.Metadata.AggregateName.Should().Be("ThingyAggregate");
            snapshotContainer.Metadata.AggregateSequenceNumber.Should().Be(expectedVersion);
            snapshotContainer.Metadata.SnapshotName.Should().Be("thingy");
            snapshotContainer.Metadata.SnapshotVersion.Should().Be(1);
        }