コード例 #1
0
        public void can_get_aggregate_at_version()
        {
            foreach (var repo in _repos)
            {
                var id   = Guid.NewGuid();
                var tAgg = new TestAggregate(id);
                tAgg.RaiseBy(1);
                Assert.Equal((uint)1, tAgg.CurrentAmount());
                Assert.Equal(2, tAgg.Version);
                tAgg.RaiseBy(2);
                Assert.Equal((uint)3, tAgg.CurrentAmount());
                Assert.Equal(3, tAgg.Version);

                // get latest version (v3)
                repo.Save(tAgg, Guid.NewGuid(), h => { });
                var v3Agg = repo.GetById <TestAggregate>(id);
                Assert.Equal((uint)3, v3Agg.CurrentAmount());
                Assert.Equal(3, v3Agg.Version);

                //get version v2
                var v2Agg = repo.GetById <TestAggregate>(id, 2);
                Assert.Equal((uint)1, v2Agg.CurrentAmount());
                Assert.Equal(2, v2Agg.Version);
            }
        }
コード例 #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());
                Assert.Equal(2, tAgg.Version);
                tAgg.RaiseBy(2);
                Assert.Equal((uint)3, tAgg.CurrentAmount());
                Assert.Equal(3, tAgg.Version);

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

                //Update & save original copy
                tAgg.RaiseBy(6);
                var r = repo; //copy iteration varible for closure
                Assert.Throws <AggregateException>(() => r.Save(tAgg, Guid.NewGuid(), h => { }));
            }
        }