public void Setup()
        {
            _eventStore = new TestInMemoryEventStore();
            _rep = new Repository(_eventStore);

            _aggregate = new TestAggregate(Guid.Empty);
        }
        public When_saving_events_without_id()
        {
            _eventStore = new TestInMemoryEventStore();
            _rep = new Repository(_eventStore);

            _aggregate = new TestAggregate(Guid.Empty);
        }
        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);
        }
Esempio n. 4
0
        public When_saving()
        {
            _eventStore = new TestInMemoryEventStore();
            _rep = new Repository(_eventStore);
            _session = new Session(_rep);

            _aggregate = new TestAggregateNoParameterLessConstructor(2);
        }
 public When_getting_aggregate_without_contructor()
 {
     _id = Guid.NewGuid();
     var eventStore = new TestInMemoryEventStore();
     _repository = new Repository(eventStore);
     var aggreagate = new TestAggregateNoParameterLessConstructor(1, _id);
     aggreagate.DoSomething();
     _repository.Save(aggreagate);
 }
 public void Setup()
 {
     _id = Guid.NewGuid();
     var eventStore = new TestInMemoryEventStore();
     _repository = new Repository(eventStore);
     var aggreagate = new TestAggregateNoParameterLessConstructor(1, _id);
     aggreagate.DoSomething();
     _repository.Save(aggreagate);
 }
Esempio n. 7
0
        public void Setup()
        {
            _eventStore = new TestInMemoryEventStore();
            _eventPublisher = new TestEventPublisher();
	        _rep = new Repository(_eventStore, _eventPublisher);
            _session = new Session(_rep);

            _aggregate = new TestAggregateNoParameterLessConstructor(2);
        }
Esempio n. 8
0
        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 Setup()
        {
            var eventStore = new TestInMemoryEventStore();
            _snapshotStore = new TestSnapshotStore();
            var snapshotStrategy = new DefaultSnapshotStrategy();
            var repository = new SnapshotRepository(_snapshotStore, snapshotStrategy, new Repository(eventStore), eventStore);
            var session = new Session(repository);

            _aggregate = session.Get<TestSnapshotAggregate>(Guid.NewGuid());
        }
Esempio n. 10
0
        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_getting_an_aggregate_with_snapshot()
        {
            var eventStore = new TestInMemoryEventStore();
            var snapshotStore = new TestSnapshotStore();
            var snapshotStrategy = new DefaultSnapshotStrategy();
            var snapshotRepository = new SnapshotRepository(snapshotStore, snapshotStrategy, new Repository(eventStore), eventStore);
            var session = new Session(snapshotRepository);

            _aggregate = session.Get<TestSnapshotAggregate>(Guid.NewGuid());
        }
        public When_saving_using_repository_with_event_publisher()
        {
            _eventStore = new TestInMemoryEventStore();
            _eventPublisher = new TestEventPublisher();
            #pragma warning disable 618
            _rep = new Repository(_eventStore, _eventPublisher);
            #pragma warning restore 618
            _session = new Session(_rep);

            _aggregate = new TestAggregateNoParameterLessConstructor(2);
        }
        public When_getting_snapshotable_aggreate()
        {
            var eventStore = new TestInMemoryEventStore();
            var eventPublisher = new TestEventPublisher();
            _snapshotStore = new TestSnapshotStore();
            var snapshotStrategy = new DefaultSnapshotStrategy();
            var repository = new SnapshotRepository(_snapshotStore, snapshotStrategy, new Repository(eventStore, eventPublisher), eventStore);
            var session = new Session(repository);

            _aggregate = session.Get<TestSnapshotAggregate>(Guid.NewGuid());
        }
 public void Setup()
 {
     var eventStore = new TestInMemoryEventStore();
     _snapshotStore = new TestSnapshotStore();
     var snapshotStrategy = new DefaultSnapshotStrategy();
     var repository = new SnapshotRepository(_snapshotStore, snapshotStrategy, new Repository(eventStore), eventStore);
     var session = new Session(repository);
     var aggregate = new TestSnapshotAggregate();
     for (var i = 0; i < 200; i++)
     {
         aggregate.DoSomething();
     }
     session.Add(aggregate);
     session.Commit();
 }
        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_a_snapshotable_aggregate()
 {
     var eventStore = new TestInMemoryEventStore();
     var eventPublisher = new TestEventPublisher();
     _snapshotStore = new TestSnapshotStore();
     var snapshotStrategy = new DefaultSnapshotStrategy();
     var repository = new SnapshotRepository(_snapshotStore, snapshotStrategy, new Repository(eventStore, eventPublisher), eventStore);
     var session = new Session(repository);
     var aggregate = new TestSnapshotAggregate();
     for (var i = 0; i < 30; i++)
     {
         aggregate.DoSomething();
     }
     session.Add(aggregate);
     session.Commit();
 }
        public When_saving_a_snapshotable_aggregate_for_each_change()
        {
            IEventStore eventStore = new TestInMemoryEventStore();
            _snapshotStore = new TestInMemorySnapshotStore();
            var snapshotStrategy = new DefaultSnapshotStrategy();
            var repository = new SnapshotRepository(_snapshotStore, snapshotStrategy, new Repository(eventStore), eventStore);
            _session = new Session(repository);
            _aggregate = new TestSnapshotAggregate();

            for (var i = 0; i < 150; i++)
            {
                _session.Add(_aggregate);
                _aggregate.DoSomething();
                _session.Commit();
            }
        }
        public void Setup()        
		{
            IEventStore eventStore = new TestInMemoryEventStore();
            var eventPublisher = new TestEventPublisher();
            _snapshotStore = new TestInMemorySnapshotStore();
            var snapshotStrategy = new DefaultSnapshotStrategy();
            var repository = new SnapshotRepository(_snapshotStore, snapshotStrategy, new Repository(eventStore, eventPublisher), eventStore);
	        _session = new Session(repository);
            _aggregate = new TestSnapshotAggregate();

            for (var i = 0; i < 20; i++)
            {
                _session.Add(_aggregate);
                _aggregate.DoSomething();
                _session.Commit();
            }
        }
        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 void SetUp()
 {
     var eventStore = new TestInMemoryEventStore();
     var eventPublisher = new TestEventPublisher();
     _session = new Session(new Repository(eventStore, eventPublisher));
 }
 public void SetUp()
 {
     var eventStore = new TestInMemoryEventStore();
     _session = new Session(new Repository(eventStore));
 }
 public When_adding_aggregates_to_repository()
 {
     var eventStore = new TestInMemoryEventStore();
     var eventPublisher = new TestEventPublisher();
     _session = new Session(new Repository(eventStore, eventPublisher));
 }
 public When_getting_aggregate_without_contructor()
 {
     var eventStore = new TestInMemoryEventStore();
     var eventPublisher = new TestEventPublisher();
     _session = new Session(new Repository(eventStore, eventPublisher));
 }