Example #1
0
        public void can_get_aggregate_at_version()
        {
            foreach (var repo in _repos)
            {
                var id = Guid.NewGuid();
                Assert.Throws <InvalidOperationException>(() => repo.GetById <TestAggregate>(id, 0));
                var tAgg = new TestAggregate(id);
                tAgg.RaiseBy(1);
                Assert.Equal((uint)1, tAgg.CurrentAmount());
                tAgg.RaiseBy(2);
                Assert.Equal((uint)3, tAgg.CurrentAmount());
                // get latest version (v3)
                repo.Save(tAgg);
                var v3Agg = repo.GetById <TestAggregate>(id);
                Assert.Equal((uint)3, v3Agg.CurrentAmount());

                //get version v2
                var v2Agg = repo.GetById <TestAggregate>(id, 2);
                Assert.Equal((uint)1, v2Agg.CurrentAmount());
            }
        }
Example #2
0
        public void will_throw_concurrency_exception()
        {
            foreach (var repo in _repos)
            {
                var id   = Guid.NewGuid();
                var tAgg = new TestAggregate(id);
                tAgg.RaiseBy(1);
                Assert.Equal((uint)1, tAgg.CurrentAmount());

                tAgg.RaiseBy(2);
                Assert.Equal((uint)3, tAgg.CurrentAmount());

                // get latest version (v3) then update & save
                repo.Save(tAgg);
                var v3Agg = repo.GetById <TestAggregate>(id);
                v3Agg.RaiseBy(2);
                repo.Save(v3Agg);

                //Update & save original copy
                tAgg.RaiseBy(6);
                var r = repo; //copy iteration varible for closure
                Assert.Throws <WrongExpectedVersionException>(() => r.Save(tAgg));
            }
        }
Example #3
0
        public void can_multiple_update_and_save_multiple_aggregates()
        {
            foreach (var repo in _repos)
            {
                var id1  = Guid.NewGuid();
                var tAgg = new TestAggregate(id1);
                tAgg.RaiseBy(1);
                tAgg.RaiseBy(2);
                tAgg.RaiseBy(3);
                repo.Save(tAgg);
                var loadedAgg1 = repo.GetById <TestAggregate>(id1);
                Assert.True(tAgg.CurrentAmount() == loadedAgg1.CurrentAmount());

                var id2   = Guid.NewGuid();
                var tAgg2 = new TestAggregate(id2);
                tAgg2.RaiseBy(4);
                tAgg2.RaiseBy(5);
                tAgg2.RaiseBy(6);
                repo.Save(tAgg2);
                var loadedAgg2 = repo.GetById <TestAggregate>(id2);
                Assert.True(tAgg2.CurrentAmount() == loadedAgg2.CurrentAmount());
            }
        }