public async Task EnsureUpdatesAreExecutedOneAfterTheOther() { // arrange var entityStore = new EntityStore(); var entityId = new EntityId(nameof(MockEntity), 1); List <string> updated = new(); ulong version = 0; entityStore.Watch().Subscribe(update => { updated.Add( entityStore.GetEntities <MockEntity>(update.UpdatedEntityIds).Single().Foo !); version = update.Version; }); // act Task task1 = BeginUpdate(entityStore, "abc"); Task task2 = BeginUpdate(entityStore, "def"); await Task.WhenAll(task1, task2); // assert Assert.Collection( updated, item => { Assert.Equal("abc", item); }, item => { Assert.Equal("def", item); }); Assert.Equal(2ul, version); Task BeginUpdate(IEntityStore entityStore, string foo) { IEntityUpdateSession session = entityStore.BeginUpdate(); return(Task.Run(async() => { await Task.Delay(50); MockEntity entity = entityStore.GetOrCreate <MockEntity>(entityId); entity.Foo = foo; session.Dispose(); })); } }
private (GetHeroResult, GetHeroResultInfo) BuildData(JsonElement obj) { using IEntityUpdateSession session = _entityStore.BeginUpdate(); var entityIds = new HashSet <EntityId>(); // store updates ... EntityId heroId = UpdateHeroEntity(obj.GetProperty("hero"), entityIds); // build result var resultInfo = new GetHeroResultInfo( heroId, DeserializeNonNullString(obj, "version"), entityIds, session.Version); return(_resultDataFactory.Create(resultInfo), resultInfo); }