Created
July 18, 2014 14:32
-
-
Save wayne-o/e1d6daf85b9525364f5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Ges.Test | |
{ | |
using System.Collections; | |
using System.Net; | |
using CommonDomain; | |
using CommonDomain.Core; | |
using EventStore.ClientAPI; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113)); | |
connection.Connect(); | |
var repo = new GetEventStoreRepository.GetEventStoreRepository(connection); | |
var id = Guid.NewGuid(); | |
var testEvent = new TestAggregate(id); | |
testEvent.ProduceEvents(10); | |
repo.Save(testEvent, Guid.NewGuid(), d => { }); | |
var retrieved = repo.GetById<TestAggregate>(id); | |
} | |
} | |
public class TestAggregate : AggregateBase | |
{ | |
public int AppliedEventCount { get; private set; } | |
public void ProduceEvents(int count) | |
{ | |
for (int i = 0; i < count; i++) | |
RaiseEvent(new WoftamEvent("Woftam1-" + i, "Woftam2-" + i)); | |
} | |
public TestAggregate(Guid aggregateId) | |
: this() | |
{ | |
RaiseEvent(new TestAggregateCreated(aggregateId)); | |
} | |
private TestAggregate() | |
{ | |
Register<TestAggregateCreated>(e => Id = e.AggregateId); | |
Register<WoftamEvent>(e => AppliedEventCount++); | |
} | |
} | |
public class WoftamEvent | |
{ | |
public WoftamEvent(string property1, string property2) | |
{ | |
Property1 = property1; | |
Property2 = property2; | |
} | |
public string Property1 { get; private set; } | |
public string Property2 { get; private set; } | |
} | |
public class TestAggregateCreated | |
{ | |
public TestAggregateCreated(Guid aggregateId) | |
{ | |
AggregateId = aggregateId; | |
} | |
public Guid AggregateId { get; private set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment