コード例 #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 => { }));
            }
        }
コード例 #3
0
        public void can_get_by_stream()
        {
            foreach (var repo in _repos)
            {
                var r = repo as MockEventStoreRepository;
                if (r == null)
                {
                    continue;
                }
                var q = new TestQueue();
                r.Subscribe(q);

                var id1  = Guid.NewGuid();
                var tAgg = new TestAggregate(id1);
                tAgg.RaiseBy(1);
                tAgg.RaiseBy(2);
                tAgg.RaiseBy(3);
                repo.Save(tAgg, Guid.NewGuid(), h => { });

                var id2   = Guid.NewGuid();
                var tAgg2 = new TestAggregate(id2);
                tAgg2.RaiseBy(4);
                tAgg2.RaiseBy(5);
                tAgg2.RaiseBy(6);
                repo.Save(tAgg2, Guid.NewGuid(), h => { });

                Assert.Equal(8, q.Messages.Count);
                var bus = new InMemoryBus("all");
                var q2  = new TestQueue(bus);
                r.ReplayStreamOnto(bus, $"testAggregate-{id1.ToString("N")}");
                q2.Messages
                .AssertNext <TestAggregateMessages.NewAggregate>(
                    correlationId: id1)
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 1, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 2, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 3, "Event mismatch wrong amount");

                r.ReplayStreamOnto(bus, $"testAggregate-{id2.ToString("N")}");
                q2.Messages
                .AssertNext <TestAggregateMessages.NewAggregate>(
                    correlationId: id2)
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 4, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 5, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 6, "Event mismatch wrong amount")
                .AssertEmpty();
            }
        }
コード例 #4
0
 public void ThrowsOnRequestingSpecificVersionHigherThanExists()
 {
     foreach (var repo in _repos)
     {
         var id   = Guid.NewGuid();
         var tAgg = new TestAggregate(id);
         tAgg.RaiseBy(1);
         tAgg.RaiseBy(1);
         tAgg.RaiseBy(1);
         tAgg.RaiseBy(1); //v4
         repo.Save(tAgg, Guid.NewGuid(), h => { });
         Assert.Throws <AggregateVersionException>(() => repo.GetById <TestAggregate>(id, 50));
     }
 }
コード例 #5
0
        public void can_subscribe_to_all()
        {
            foreach (var repo in _repos)
            {
                var r = repo as MockEventStoreRepository;
                if (r == null)
                {
                    continue;
                }
                var q = new TestQueue();
                r.Subscribe(q);

                var id   = Guid.NewGuid();
                var tAgg = new TestAggregate(id);
                tAgg.RaiseBy(1);
                tAgg.RaiseBy(1);
                tAgg.RaiseBy(1);
                repo.Save(tAgg, Guid.NewGuid(), h => { });

                Assert.Equal(4, q.Messages.Count);
            }
        }
コード例 #6
0
        public void can_get_by_category()
        {
            foreach (var repo in _repos)
            {
                var r = repo as MockEventStoreRepository;
                if (r == null)
                {
                    continue;
                }
                var q = new TestQueue();
                r.Subscribe(q);

                var id1  = Guid.NewGuid();
                var tAgg = new TestAggregate(id1);
                tAgg.RaiseBy(1);
                tAgg.RaiseBy(2);
                tAgg.RaiseBy(3);
                repo.Save(tAgg, Guid.NewGuid(), h => { });

                var id3   = Guid.NewGuid();
                var tAgg3 = new TestWoftamAggregate(id3);
                tAgg3.ProduceEvents(3);
                repo.Save(tAgg3, Guid.NewGuid(), h => { });

                var id2   = Guid.NewGuid();
                var tAgg2 = new TestAggregate(id2);
                tAgg2.RaiseBy(4);
                tAgg2.RaiseBy(5);
                tAgg2.RaiseBy(6);
                repo.Save(tAgg2, Guid.NewGuid(), h => { });



                Assert.Equal(12, q.Messages.Count);
                var bus = new InMemoryBus("all");
                var q2  = new TestQueue(bus);
                r.ReplayCategoryOnto(bus, "testAggregate");
                q2.Messages
                .AssertNext <TestAggregateMessages.NewAggregate>(
                    correlationId: id1)
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 1, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 2, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 3, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.NewAggregate>(
                    correlationId: id2)
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 4, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 5, "Event mismatch wrong amount")
                .AssertNext <TestAggregateMessages.Increment>(
                    m => m.Amount == 6, "Event mismatch wrong amount")
                .AssertEmpty();
                r.ReplayCategoryOnto(bus, "testWoftamAggregate");
                q2.Messages
                .AssertNext <TestWoftamAggregateCreated>(
                    correlationId: id3)
                .AssertNext <WoftamEvent>(
                    correlationId: Guid.Empty)
                .AssertNext <WoftamEvent>(
                    correlationId: Guid.Empty)
                .AssertNext <WoftamEvent>(
                    correlationId: Guid.Empty)
                .AssertEmpty();
            }
        }