Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
<Reference Include="CommonDomain.Persistence">
<HintPath>..\..\lib\CommonDomain\CommonDomain.Persistence.dll</HintPath>
</Reference>
<Reference Include="EventStore.ClientAPI">
<HintPath>..\packages\EventStore.Client.1.0.1\lib\net40\EventStore.ClientAPI.dll</HintPath>
<Reference Include="EventStore.ClientAPI, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EventStore.Client.2.0.2\lib\net40\EventStore.ClientAPI.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ private static Guid SaveTestAggregateWithoutCustomHeaders(IRepository repository
return aggregateToSave.Id;
}

private EventStoreConnection _connection;
private IEventStoreConnection _connection;
private GetEventStoreRepository _repo;

[SetUp]
public void SetUp()
{
_connection = EventStoreConnection.Create();
_connection.Connect(IntegrationTestTcpEndPoint);
_connection = EventStoreConnection.Create(IntegrationTestTcpEndPoint);
_connection.Connect();
_repo = new GetEventStoreRepository(_connection);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ public void ThrowsOnGetDeletedAggregate()
var aggregateId = SaveTestAggregateWithoutCustomHeaders(_repo, 10);

var streamName = string.Format("testAggregate-{0}", aggregateId.ToString("N"));
_connection.DeleteStream(streamName, 11);
_connection.DeleteStream(streamName, 10);

Assert.Throws<AggregateDeletedException>(() => _repo.GetById<TestAggregate>(aggregateId));
}
Expand All @@ -166,7 +166,7 @@ public void SavesCommitHeadersOnEachEvent()
d.Add("CustomHeader2", "CustomValue2");
});

var read = _connection.ReadStreamEventsForward(string.Format("aggregate-{0}", aggregateToSave.Id), 1, 20, false);
var read = _connection.ReadStreamEventsForward(string.Format("testAggregate-{0}", aggregateToSave.Id.ToString("N")), 1, 20, false);
foreach (var serializedEvent in read.Events)
{
var parsedMetadata = JObject.Parse(Encoding.UTF8.GetString(serializedEvent.OriginalEvent.Metadata));
Expand Down
4 changes: 2 additions & 2 deletions src/GetEventStoreRepository.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EventStore.Client" version="1.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
<package id="EventStore.Client" version="2.0.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
<package id="NUnit" version="2.6.2" targetFramework="net45" />
</packages>
14 changes: 7 additions & 7 deletions src/GetEventStoreRepository/GetEventStoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public class GetEventStoreRepository : IRepository

private readonly Func<Type, Guid, string> _aggregateIdToStreamName;

private readonly EventStoreConnection _eventStoreConnection;
private readonly IEventStoreConnection _eventStoreConnection;
private static readonly JsonSerializerSettings SerializerSettings;

static GetEventStoreRepository()
{
SerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None };
}

public GetEventStoreRepository(EventStoreConnection eventStoreConnection)
public GetEventStoreRepository(IEventStoreConnection eventStoreConnection)
: this(eventStoreConnection, (t, g) => string.Format("{0}-{1}", char.ToLower(t.Name[0]) + t.Name.Substring(1), g.ToString("N")))
{
}

public GetEventStoreRepository(EventStoreConnection eventStoreConnection, Func<Type, Guid, string> aggregateIdToStreamName)
public GetEventStoreRepository(IEventStoreConnection eventStoreConnection, Func<Type, Guid, string> aggregateIdToStreamName)
{
_eventStoreConnection = eventStoreConnection;
_aggregateIdToStreamName = aggregateIdToStreamName;
Expand All @@ -52,13 +52,13 @@ public TAggregate GetById<TAggregate>(Guid id, int version) where TAggregate : c
var streamName = _aggregateIdToStreamName(typeof(TAggregate), id);
var aggregate = ConstructAggregate<TAggregate>();

var sliceStart = 1; //Ignores $StreamCreated
var sliceStart = 0;
StreamEventsSlice currentSlice;
do
{
var sliceCount = sliceStart + ReadPageSize <= version
? ReadPageSize
: version - sliceStart + 1;
: version - sliceStart;

currentSlice = _eventStoreConnection.ReadStreamEventsForward(streamName, sliceStart, sliceCount, false);

Expand All @@ -72,7 +72,7 @@ public TAggregate GetById<TAggregate>(Guid id, int version) where TAggregate : c

foreach (var evnt in currentSlice.Events)
aggregate.ApplyEvent(DeserializeEvent(evnt.OriginalEvent.Metadata, evnt.OriginalEvent.Data));
} while (version >= currentSlice.NextEventNumber && !currentSlice.IsEndOfStream);
} while (version > currentSlice.NextEventNumber && !currentSlice.IsEndOfStream);

if (aggregate.Version != version && version < Int32.MaxValue)
throw new AggregateVersionException(id, typeof (TAggregate), aggregate.Version, version);
Expand Down Expand Up @@ -103,7 +103,7 @@ public void Save(IAggregate aggregate, Guid commitId, Action<IDictionary<string,
var streamName = _aggregateIdToStreamName(aggregate.GetType(), aggregate.Id);
var newEvents = aggregate.GetUncommittedEvents().Cast<object>().ToList();
var originalVersion = aggregate.Version - newEvents.Count;
var expectedVersion = originalVersion == 0 ? ExpectedVersion.NoStream : originalVersion;
var expectedVersion = originalVersion == 0 ? ExpectedVersion.NoStream : originalVersion-1;
var eventsToSave = newEvents.Select(e => ToEventData(Guid.NewGuid(), e, commitHeaders)).ToList();

if (eventsToSave.Count < WritePageSize)
Expand Down
10 changes: 6 additions & 4 deletions src/GetEventStoreRepository/GetEventStoreRepository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
<Reference Include="CommonDomain.Persistence">
<HintPath>..\..\lib\CommonDomain\CommonDomain.Persistence.dll</HintPath>
</Reference>
<Reference Include="EventStore.ClientAPI">
<HintPath>..\packages\EventStore.Client.1.0.1\lib\net40\EventStore.ClientAPI.dll</HintPath>
<Reference Include="EventStore.ClientAPI, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EventStore.Client.2.0.2\lib\net40\EventStore.ClientAPI.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/GetEventStoreRepository/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EventStore.Client" version="1.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
<package id="EventStore.Client" version="2.0.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
</packages>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>EventStore.Client</id>
<version>2.0.2</version>
<authors>Event Store LLP</authors>
<owners>Event Store LLP</owners>
<licenseUrl>http://geteventstore.com/terms/licence/bsd/</licenseUrl>
<projectUrl>http://geteventstore.com/</projectUrl>
<iconUrl>http://geteventstore.com/assets/ouro-200.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>The client API for the Event Store. Get the open source or commercial versions of the Event Store server from http://geteventstore.com</description>
<releaseNotes>Client API for version 2 of the Event Store</releaseNotes>
<copyright>Copyright 2012-2013 Event Store LLP</copyright>
</metadata>
</package>
Binary file not shown.
Loading