public async Task NonAggregateEvent_Shouldnt_Be_Persisted_If_User_Configure_It() { try { DeleteAll(); var store = new EFEventStore(GetOptions(shouldPersisteNonAggregateEvt: false)); await store.StoreDomainEventAsync(new NonAggEvent()); using (var ctx = GetContext()) { ctx.Set <Event>().AsNoTracking().Count().Should().Be(0); } } finally { DeleteAll(); } }
public async Task StoreRangeDomainEvent_Snapshot(int numberEvents, bool useBuffer) { var store = new EFEventStore( GetConfig( new BasicSnapshotBehaviorProvider(new Dictionary <Type, ISnapshotBehavior>() { { typeof(TestEvent), new NumericSnapshotBehavior(10) } }), bufferInfo: useBuffer?BufferInfo.Default: BufferInfo.Disabled)); for (int i = 0; i < numberEvents; i++) { await store.StoreDomainEventAsync( new TestEvent(Guid.NewGuid(), AggregateId) { AggregateIntValue = 1, AggregateStringValue = "test" }); } }
public async Task SnapshotBehavior_Generic_StoreDomainEventAsync_CreateSnapshot_Archive_In_DifferentTable() { _snapshotProviderMock.Setup(m => m.GetBehaviorForEventType(typeof(AggregateSnapshotEvent))) .Returns(new NumericSnapshotBehavior(10)); try { DeleteAll(); Guid aggId = Guid.NewGuid(); var store = new EFEventStore(GetOptions(behavior: SnapshotEventsArchiveBehavior.StoreToNewTable)); for (int i = 0; i < 11; i++) { await store.StoreDomainEventAsync(new AggregateSnapshotEvent(aggId)); } using (var ctx = GetContext()) { ctx.Set <Event>().ToList().Where(c => c.HashedAggregateId == aggId.ToJson(true).GetHashCode()).Count().Should().Be(1); ctx.Set <ArchiveEvent>().ToList().Where(c => c.HashedAggregateId == aggId.ToJson(true).GetHashCode()).Count().Should().Be(10); var evt = ctx.Set <Event>().FirstOrDefault(); evt.Should().NotBeNull(); evt.HashedAggregateId.Should().Be(aggId.ToJson(true).GetHashCode()); evt.Sequence.Should().Be(11); evt.EventData.Should().NotBeNullOrWhiteSpace(); ctx.Set <Snapshot>().Count().Should().Be(1); var snap = ctx.Set <Snapshot>().FirstOrDefault(); snap.Should().NotBeNull(); evt.HashedAggregateId.Should().Be(aggId.ToJson(true).GetHashCode()); snap.AggregateType.Should().Be(typeof(AggregateSnapshot).AssemblyQualifiedName); var agg = await new EFEventStore(GetOptions()).GetRehydratedAggregateAsync <AggregateSnapshot>(aggId); agg.Should().NotBeNull(); agg.AggIncValue.Should().Be(11); } } finally { DeleteAll(); } }