public async Task TestWriteVersion1ToEventStore() { A.CallTo(() => _eventStoreApi.GetAggregatesAtLatestVersion(A <Guid> .That.IsEqualTo(_datasetId))).Returns( new List <Aggregate <Feature <LineString, ExampleAttributes> > >() ); var events = new List <Event <FeatureDiff> >(); A.CallTo(() => _eventStoreApi.SaveEvent(A <Guid> .That.IsEqualTo(_datasetId), A <Event <FeatureDiff> > ._)) .Invokes((Guid id, Event <FeatureDiff> x) => events.Add(x)); await _converter.UpdateDataset(_datasetId, _version1); Assert.AreEqual(6, events.Count()); }
public async Task TestExistingFeature() { var existingAggregate = new Aggregate <Feature <Polygon, ExampleAttributes> >() { Data = new Feature <Polygon, ExampleAttributes>() { Geometry = GetGeometry <Polygon>("POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))"), Attributes = new ExampleAttributes() { Id = 2, Name = "Feature 2" } }, Id = Guid.NewGuid(), Version = 1 }; A.CallTo(() => _eventStoreApi.GetAggregatesAtLatestVersion(A <Guid> .That.IsEqualTo(_datasetId))).Returns( new List <Aggregate <Feature <Polygon, ExampleAttributes> > >() { existingAggregate }); await _readProjectionWriterWithFilter.CreateReadProjection(_datasetId); A.CallTo(() => _databaseEngine.Upsert( A <string> .That.IsEqualTo(_datasetId.ToString()), A <IEnumerable <Cell> > .That.Matches(c => CheckCellCreation(c, existingAggregate.Data, existingAggregate.Id)))).MustHaveHappenedOnceExactly(); }
public async Task UpdateDataset(Guid datasetId, IEnumerable <Feature <TGeometry, TAttributes> > newFeatures) { //Get current version (version n) of the dataset var oldFeatures = await _eventStoreApi.GetAggregatesAtLatestVersion(datasetId); //Use the new and old features to generate a list of pairs with corresponding action var changes = await _changeDetector.FindChanges(oldFeatures, newFeatures); //Create a diff for each pair that is changed, created, or deleted var events = GetDiffs(changes).ToList(); await Task.WhenAll(events.Select(@event => StoreEvent(datasetId, @event)).ToArray()); }