Skip to content

Commit

Permalink
build.
Browse files Browse the repository at this point in the history
  • Loading branch information
Slacquer committed Mar 16, 2019
1 parent ef5ebdd commit c03bab0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
20 changes: 13 additions & 7 deletions APIBlox.NetCore.EventStore/EventStoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ public EventStoreService(IEventStoreRepository<TModel> repo)
throw new ArgumentException("You must supply events.", nameof(events));

var updating = expectedVersion.HasValue;
RootDocument root;

var root = await ReadRootAsync(streamId, cancellationToken);

if (root is null && expectedVersion.HasValue)
throw new DataAccessException($"Stream '{streamId}' wasn't found.");

if (!(root is null) && !(expectedVersion.HasValue))
throw new DocumentConcurrencyException($"Stream '{streamId}' exists, therefore you must specify an expected version.");

var docs = new List<EventStoreDocument>();

if (updating)
{
root = await ReadRootAsync(streamId, cancellationToken);

if (root.Version != expectedVersion)
throw new DocumentConcurrencyException(
$"Expected stream '{streamId}' to have version {expectedVersion.Value} but is {root.Version}."
Expand All @@ -55,15 +61,15 @@ public EventStoreService(IEventStoreRepository<TModel> repo)

var curVersion = root.Version;
root.Version += events.Length;

for (long i = 0; i < events.Length; i++)
docs.Add(BuildEventDoc(events[i], streamId, ++curVersion));

await Repository.AddAsync(docs.ToArray(), cancellationToken);

if (updating)
await Repository.UpdateAsync(root, cancellationToken);

return new EventStreamModel
{
StreamId = streamId,
Expand Down Expand Up @@ -113,7 +119,7 @@ public EventStoreService(IEventStoreRepository<TModel> repo)
DataType = @event.Data.GetType().AssemblyQualifiedName,
Data = @event.Data
};

return document;
}

Expand All @@ -127,7 +133,7 @@ public EventStoreService(IEventStoreRepository<TModel> repo)
DataType = snapshot.Data.GetType().AssemblyQualifiedName,
Data = snapshot.Data
};

return document;
}
}
Expand Down
9 changes: 2 additions & 7 deletions APIBlox.NetCore.EventStore/ReadOnlyEventStoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@ public ReadOnlyEventStoreService(IEventStoreRepository<TModel> repo)
d => d.StreamId == streamId && d.DocumentType == DocumentType.Root,
cancellationToken
);

var ret = result.FirstOrDefault();

if (ret is null)
throw new DataAccessException($"Stream '{streamId}' wasn't found");

return ret;

return result.FirstOrDefault();
}


Expand Down
6 changes: 3 additions & 3 deletions SlnTests/APIBlox.NetCore.EventStore/InMemoryRepoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// var repo = new MongoDbRepository<DummyAggregate>(ctx, new JsonSerializerSettings());

// IEventStoreService<DummyAggregate> svc = new EventStoreService<DummyAggregate>(repo);

// return svc;
// }

Expand Down Expand Up @@ -110,7 +110,7 @@
// Assert.True(result.StreamId == agg.StreamId);
// Assert.Null(result.Snapshot);
// Assert.NotNull(result.Events);

// agg.Children = new List<Child>
// {
// new Child{ Foo="aaa", Bar=123},
Expand All @@ -127,7 +127,7 @@
// result = await svc.ReadEventStreamAsync(agg.StreamId, includeEvents: true);

// Assert.True(result.Version == 5);
// Assert.True(result.Events.Length == 1,$"length is {result.Events.Length}");
// Assert.True(result.Events.Length == 1, $"length is {result.Events.Length}");
// Assert.NotNull(result.Snapshot);
// Assert.NotNull(result.Snapshot.Data as DummyAggregate);

Expand Down
12 changes: 12 additions & 0 deletions releaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
_March 16th, 2019_ **v1.0.110**
- Potential bug with event store service where you are allowed to write to
a stream without specifying the version. When the stream exists, it would
overwrite the 1st entry. Now will throw error if stream root exists but
you have not specified an expectedVersion.

Thanks,
_Slacquer_

<br>
<br>

_March 16th, 2019_ **v1.0.109**
- ServiceCollection extensions had incorrect namespace.

Expand Down

0 comments on commit c03bab0

Please sign in to comment.