public When_saving_two_aggregates_in_parallel() { _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore), _testStore, new 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(t1, t2); }
public void Should_track_changes() { var agg = new TestAggregate(Guid.NewGuid()); _session.Add(agg); var aggregate = _session.Get<TestAggregate>(agg.Id); Assert.AreEqual(agg,aggregate); }
public When_saving_events_without_id() { _eventStore = new TestInMemoryEventStore(); _rep = new Repository(_eventStore); _aggregate = new TestAggregate(Guid.Empty); }
public void Should_throw_if_different_object_with_tracked_guid_is_added() { var aggregate = new TestAggregate(Guid.NewGuid()); var aggregate2 = new TestAggregate(aggregate.Id); _session.Add(aggregate); Assert.Throws<ConcurrencyException>(() => _session.Add(aggregate2)); }
public void Setup() { _eventStore = new TestInMemoryEventStore(); _rep = new Repository(_eventStore); _aggregate = new TestAggregate(Guid.Empty); }
public void Setup() { _testRep = new TestRepository(); _rep = new CacheRepository(_testRep, new TestInMemoryEventStore()); _aggregate = _testRep.Get<TestAggregate>(Guid.NewGuid()); _aggregate.DoSomething(); _rep.Save(_aggregate,-1); }
public When_saving_aggregate() { _testRep = new TestRepository(); _rep = new CacheRepository(_testRep, new TestInMemoryEventStore(), new CqrsMemoryCache()); _aggregate = _testRep.Get<TestAggregate>(Guid.NewGuid()); _aggregate.DoSomething(); _rep.Save(_aggregate, -1); }
public void Setup() { _eventStore = new TestInMemoryEventStore(); _rep = new Repository(_eventStore); _session = new Session(_rep); _aggregate = new TestAggregate(Guid.NewGuid()); _aggregate.DoSomething(); _rep.Save(_aggregate); }
public When_saving_stale_data() { _eventStore = new TestInMemoryEventStore(); _rep = new Repository(_eventStore); _session = new Session(_rep); _aggregate = new TestAggregate(Guid.NewGuid()); _aggregate.DoSomething(); _rep.Save(_aggregate); }
public void Should_clear_tracked_aggregates() { var agg = new TestAggregate(Guid.NewGuid()); _session.Add(agg); agg.DoSomething(); _session.Commit(); _eventStore.Events.Clear(); Assert.Throws<AggregateNotFoundException>(() => _session.Get<TestAggregate>(agg.Id)); }
public When_saving_fails() { _memoryCache = new MemoryCache(); _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 void Setup() { // This will clear the cache between runs. var cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList(); foreach (var cacheKey in cacheKeys) MemoryCache.Default.Remove(cacheKey); _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore,new TestEventPublisher()), _testStore); _rep2 = new CacheRepository(new Repository(_testStore,new TestEventPublisher()), _testStore); _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_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_aggregate() { _memoryCache = new MemoryCache(); _rep = new CacheRepository(new TestRepository(), new TestEventStore(), _memoryCache); _aggregate = _rep.Get<TestAggregate>(Guid.NewGuid()); }
public void Should_not_throw_if_object_already_tracked() { var aggregate = new TestAggregate(Guid.NewGuid()); _session.Add(aggregate); _session.Add(aggregate); }
public void Setup() { _rep = new CacheRepository(new TestRepository(), new TestEventStore()); _aggregate = _rep.Get<TestAggregate>(Guid.NewGuid()); }
public void Should_not_cache_empty_id() { var aggregate = new TestAggregate(Guid.Empty); _rep.Save(aggregate); Assert.NotEqual(aggregate, _rep.Get<TestAggregate>(Guid.Empty)); }
public When_replaying_events() { _aggregate = new TestAggregate(Guid.NewGuid()); }
public void Should_not_cache_empty_id() { var aggregate = new TestAggregate(Guid.Empty); _rep.Save(aggregate); Assert.That(_rep.Get<TestAggregate>(Guid.Empty), Is.Not.EqualTo(aggregate)); }
public void Setup() { _aggregate = new TestAggregate(Guid.NewGuid()); }
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()); }