public async Task Verify_update_idempotency() { var rm = new SampleReadModelTest { Id = new TestId(1), Value = "test", Counter = 10, }; await sut.InsertAsync(new SampleAggregateCreated(), rm).ConfigureAwait(false); //now try to update counter with an event SampleAggregateTouched e = new SampleAggregateTouched(); await sut.FindAndModifyAsync(e, rm.Id, _ => _.Counter++).ConfigureAwait(false); var reloaded = await sut.FindOneByIdAsync(rm.Id).ConfigureAwait(false); Assert.That(reloaded.Counter, Is.EqualTo(11)); //idempotency on the very same event await sut.FindAndModifyAsync(e, rm.Id, _ => _.Counter++).ConfigureAwait(false); reloaded = await sut.FindOneByIdAsync(rm.Id).ConfigureAwait(false); Assert.That(reloaded.Counter, Is.EqualTo(11)); //increment on different event SampleAggregateTouched anotherEvent = new SampleAggregateTouched(); await sut.FindAndModifyAsync(anotherEvent, rm.Id, _ => _.Counter++).ConfigureAwait(false); reloaded = await sut.FindOneByIdAsync(rm.Id).ConfigureAwait(false); Assert.That(reloaded.Counter, Is.EqualTo(12)); }
public async Task Verify_population_of_basic_properties_on_find_and_modify() { var rm = CreateNew(); var evt = HandleEvent(new SampleAggregateCreated()); await sut.InsertAsync(evt, rm); var reloaded = await sut.FindOneByIdAsync(rm.Id); var evt2 = HandleEvent(new SampleAggregateTouched(), 2L); await sut.FindAndModifyAsync(evt2, rm.Id, r => r.Value += "MODIFIED", false); var reloaded2 = await sut.FindOneByIdAsync(rm.Id); Assert.That(reloaded2.CheckpointToken, Is.EqualTo(2L)); Assert.That(reloaded2.SecondaryToken, Is.GreaterThan(reloaded.SecondaryToken)); }