public When_saving_fails() { _memoryCache = new CqrsMemoryCache(); _testRep = new TestRepository(); _rep = new CacheRepository(_testRep, new TestInMemoryEventStore(), _memoryCache); _aggregate = _testRep.Get<TestAggregate>(Guid.NewGuid()); _aggregate.DoSomething(); try { _rep.Save(_aggregate, 100); } catch (Exception) { } }
public When_saving_same_aggregate_in_parallel() { // New up a new Cache for each run var memoryCache = new CqrsMemoryCache(); _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore, new TestEventPublisher()), _testStore, memoryCache); _rep2 = new CacheRepository(new Repository(_testStore, new TestEventPublisher()), _testStore, memoryCache); _aggregate = new TestAggregate(Guid.NewGuid()); _rep1.Save(_aggregate); var t1 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); var t2 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep2.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep2.Save(aggregate); } }); var t3 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep2.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep2.Save(aggregate); } }); t1.Start(); t2.Start(); t3.Start(); Task.WaitAll(t1, t2, t3); }
public When_saving_two_aggregates_in_parallel() { // This will clear the cache between runs. var memoryCache = new CqrsMemoryCache(); _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore, new TestEventPublisher()), _testStore, memoryCache); _aggregate1 = new TestAggregate(Guid.NewGuid()); _aggregate2 = new TestAggregate(Guid.NewGuid()); _rep1.Save(_aggregate1); _rep1.Save(_aggregate2); var t1 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate1.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); var t2 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate2.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); t1.Start(); t2.Start(); Task.WaitAll(new[] { t1, t2 }); }
public When_getting_wrong_events_from_event_store() { _memoryCache = new CqrsMemoryCache(); _rep = new CacheRepository(new TestRepository(), new TestEventStoreWithBugs(), _memoryCache); _aggregate = _rep.Get<TestAggregate>(Guid.NewGuid()); }