CommonDomain Repository Sample updating to ES 3.0.3

Hello there,
i’m just trying some different approches how to implement some kind of EventStore Repository. I came across the getting-started-with-event-store example (https://github.com/EventStore/getting-started-with-event-store) with the CommonDomain Repository. But I’ve some issues get it work with ES 3.0.3 and EventStore.Client 3.0.2.

9 of 12 Tests are failing with the message: GetEventStoreRepository.AggregateNotFoundException : Aggregate ‘990cd4db-44bd-485b-b2f7-00451bfcd142’ (type TestAggregate) was not found.

What I’ve done so far.

  1. Cloned the github repository

  2. Updated the nuget package for EventStore.Client

  3. Replaced some of the methods with the async versions

  4. Run all Tests

GetEventStoreRepository.cs

Old: currentSlice = _eventStoreConnection.ReadStreamEventsForward(streamName, sliceStart, sliceCount, false);
New: currentSlice = _eventStoreConnection.ReadStreamEventsForwardAsync(streamName, sliceStart, sliceCount, false).Result;

_eventStoreConnection.AppendToStream(streamName, expectedVersion, eventsToSave);
_eventStoreConnection.AppendToStreamAsync(streamName, expectedVersion, eventsToSave);

var transaction = _eventStoreConnection.StartTransaction(streamName, expectedVersion);
var transaction = _eventStoreConnection.StartTransactionAsync(streamName, expectedVersion);

transaction.Write(pageEvents);
transaction.Result.WriteAsync(pageEvents);

transaction.Commit();
transaction.Result.CommitAsync();

``

I also made some minor changes to the GetEventStoreRepositoryIntegrationTests.cs

_connection.ConnectAsync().Wait();
_connection.ConnectAsync().Wait();

_connection.DeleteStream(streamName, 11);
_connection.DeleteStreamAsync(streamName, 11);

var read = _connection.ReadStreamEventsForward(string.Format(“aggregate-{0}”, aggregateToSave.Id), 1, 20, false);
var read = _connection.ReadStreamEventsForwardAsync(string.Format(“aggregate-{0}”, aggregateToSave.Id), 1, 20, false).Result;

``

Has anyone else tried to update the example or any suggestions what I’ve missed.

Glad for any help or suggestions!
Best regards Dirk

_eventStoreConnection.AppendToStream(streamName, expectedVersion,
eventsToSave);
_eventStoreConnection.AppendToStreamAsync(streamName,
expectedVersion, eventsToSave);

Try waiting on the async object :wink:

Thank’s a lot Greg for th prompt response. This fixed the Issue I’ve dicribed above.
I definitivly need some more study on async in .net.

But now there are two other failing tests because of an unexpected aggregate version:

[Test]

    public void CanGetSpecificVersionFromFirstPageById()

    {

        var savedId = SaveTestAggregateWithoutCustomHeaders(_repo, 100 /* excludes TestAggregateCreated */);

        var retrieved = _repo.GetById<TestAggregate>(savedId, 65);

        Assert.AreEqual(65, retrieved.AppliedEventCount);

    }

    [Test]

    public void CanGetSpecificVersionFromSubsequentPageById()

    {

        var savedId = SaveTestAggregateWithoutCustomHeaders(_repo, 500 /* excludes TestAggregateCreated */);

        var retrieved = _repo.GetById<TestAggregate>(savedId, 126);

        Assert.AreEqual(125, retrieved.AppliedEventCount);

    }

``

First one fails with:

GetEventStoreRepository.AggregateVersionException : Requested version 65 of aggregate ‘371d920d-0be6-4018-8e04-532702174d5e’ (type TestAggregate) - aggregate version is 66

Second one fails with:

GetEventStoreRepository.AggregateVersionException : Requested version 126 of aggregate ‘ef274020-888c-4dfe-9208-3c6931751607’ (type TestAggregate) - aggregate version is 127

In fact the Test Isn’t failing but the GetEventStoreRepository.cs is throwing a new AggregateVersonException in

if (aggregate.Version != version && version < Int32.MaxValue)

throw new AggregateVersionException(id, typeof (TAggregate), aggregate.Version, version);

``

Has there changed an index?

That has changed (very old version had event 0 as "stream created") so
it will be off by one errors (thats from 1.0)