Beispiel #1
0
        public async Task GetsSameAggregateOnGet()
        {
            await _rep.SaveAsync(_aggregate, -1);

            var aggregate = _rep.GetAsync <TestAggregate>(_aggregate.Id).Result;

            Assert.AreEqual(_aggregate, aggregate);
        }
        public async Task DistributesEventsCorrectly()
        {
            var aggregate1 = await _rep1.GetAsync <TestAggregate>(_aggregate2.Id);

            Assert.AreEqual(100, aggregate1.DidSomethingCount);

            var aggregate2 = await _rep1.GetAsync <TestAggregate>(_aggregate2.Id);

            Assert.AreEqual(100, aggregate2.DidSomethingCount);
        }
Beispiel #3
0
        public SaveSameAggregateInParallelTest()
        {
            var memoryCache = new MemoryCache();

            _testStore = new TestInMemoryEventStore();
            _rep1      = new CacheRepository(new Repository(_testStore), _testStore, memoryCache);
            _rep2      = new CacheRepository(new Repository(_testStore), _testStore, memoryCache);

            _aggregate = new TestAggregate(Guid.NewGuid().ToString());

            _rep1.SaveAsync(_aggregate).Wait();

            var t1 = new Task(() =>
            {
                for (var i = 0; i < 100; i++)
                {
                    var aggregate = _rep1.GetAsync <TestAggregate>(_aggregate.Id).Result;
                    aggregate.DoSomething();
                    _rep1.SaveAsync(aggregate).Wait();
                }
            });

            var t2 = new Task(() =>
            {
                for (var i = 0; i < 100; i++)
                {
                    var aggregate = _rep2.GetAsync <TestAggregate>(_aggregate.Id).Result;
                    aggregate.DoSomething();
                    _rep2.SaveAsync(aggregate).Wait();
                }
            });
            var t3 = new Task(() =>
            {
                for (var i = 0; i < 100; i++)
                {
                    var aggregate = _rep2.GetAsync <TestAggregate>(_aggregate.Id).Result;
                    aggregate.DoSomething();
                    _rep2.SaveAsync(aggregate).Wait();
                }
            });

            t1.Start();
            t2.Start();
            t3.Start();

            Task.WaitAll(t1, t2, t3);
        }
        public async Task GetsSameAggregateFromDifferentCacheRespository()
        {
            var rep       = new CacheRepository(new TestRepository(), new TestInMemoryEventStore(), _memoryCache);
            var aggregate = await rep.GetAsync <TestAggregate>(_aggregate.Id);

            Assert.AreEqual(_aggregate.DidSomethingCount, aggregate.DidSomethingCount);
            Assert.AreEqual(_aggregate.Id, aggregate.Id);
            Assert.AreEqual(_aggregate.Version, aggregate.Version);
        }
        public SaveTwoAggregatesInParallel()
        {
            _testStore = new TestInMemoryEventStore();
            _rep1      = new CacheRepository(new Repository(_testStore), _testStore, new MemoryCache());

            var aggregate1 = new TestAggregate(Guid.NewGuid().ToString());

            _aggregate2 = new TestAggregate(Guid.NewGuid().ToString());

            _rep1.SaveAsync(aggregate1).Wait();
            _rep1.SaveAsync(_aggregate2).Wait();

            var t1 = new Task(() =>
            {
                for (var i = 0; i < 100; i++)
                {
                    var aggregate = _rep1.GetAsync <TestAggregate>(aggregate1.Id).Result;
                    aggregate.DoSomething();
                    _rep1.SaveAsync(aggregate).Wait();
                }
            });

            var t2 = new Task(() =>
            {
                for (var i = 0; i < 100; i++)
                {
                    var aggregate = _rep1.GetAsync <TestAggregate>(_aggregate2.Id).Result;
                    aggregate.DoSomething();
                    _rep1.SaveAsync(aggregate).Wait();
                }
            });

            t1.Start();
            t2.Start();

            Task.WaitAll(t1, t2);
        }