Esempio n. 1
0
        public virtual async Task RetrieveVersionConstrainedSnapshot()
        {
            var eventStore = new Mock <IEventStore>();

            var nextEventId = 0L;

            eventStore.Setup(es => es.WriteEvents(It.IsAny <IList <DomainEvent> >()))
            .ReturnsAsync(() => nextEventId++);

            var item = new ConfigEnvironment(new EnvironmentIdentifier("Foo", "Bar"));

            item.Create();
            await item.WriteRecordedEvents(eventStore.Object);

            var firstSnapshot = item.CreateSnapshot();

            item.UpdateKeys(new[] { new ConfigEnvironmentKey("Foo", "1", "", "", 1) });
            await item.WriteRecordedEvents(eventStore.Object);

            var secondSnapshot = item.CreateSnapshot();

            item.UpdateKeys(new[] { new ConfigEnvironmentKey("Foo", "2", "", "", 2) });
            await item.WriteRecordedEvents(eventStore.Object);

            var thirdSnapshot = item.CreateSnapshot();

            await Store.SaveSnapshots(new[] { firstSnapshot, secondSnapshot, thirdSnapshot });

            var result = await Store.GetSnapshot(nameof(ConfigEnvironment), item.Identifier.ToString(), 1);

            Assert.False(result.IsError, "result.IsError");
            Assert.Equal(secondSnapshot, result.Data);
        }
Esempio n. 2
0
        public virtual async Task GetLatestSnapshotNumbers()
        {
            var esMock = new Mock <IEventStore>(MockBehavior.Strict);

            esMock.Setup(es => es.WriteEvents(It.IsAny <IList <DomainEvent> >()))
            .ReturnsAsync(1)
            .Verifiable("Events not written to EventStore");

            var item = new ConfigEnvironment(new EnvironmentIdentifier("Foo", "Bar"));

            item.Create();
            await item.WriteRecordedEvents(esMock.Object);

            var snapshot = item.CreateSnapshot();

            await Store.SaveSnapshots(new[] { snapshot });

            var result = await Store.GetLatestSnapshotNumbers();

            Assert.False(result.IsError, "result.IsError");
            Assert.Equal(1, result.Data);
        }