コード例 #1
0
        public void Apply_KeepsHighestVersion()
        {
            const int  version   = 420;
            IAggregate aggregate = new TestAggregate();
            var        event1    = new MockEvent {
                Version = version
            };
            var event2 = new MockEvent {
                Version = version - 69
            };

            aggregate.Apply(event1);
            aggregate.Apply(event2);

            Assert.Equal(version, aggregate.Version);
        }
コード例 #2
0
        public void Can_apply_supported_event_to_aggregate()
        {
            var aggregate = new TestAggregate();

            Assert.AreEqual(0, aggregate.Number);

            aggregate.Apply(new NumberIncreased(2));

            Assert.AreEqual(2, aggregate.Number);
        }
コード例 #3
0
        public void Apply_SetsVersion()
        {
            const int  version   = 69;
            IAggregate aggregate = new TestAggregate();
            var        @event    = new MockEvent {
                Version = version
            };

            aggregate.Apply(@event);

            Assert.Equal(version, aggregate.Version);
        }
コード例 #4
0
        public void Update_updates_the_aggregate_in_mongo_collection()
        {
            //Given
            var testAggregate = new TestAggregate(1);

            Collection.InsertMany(new[] { testAggregate, /*noise*/ new TestAggregate(666) });

            //When
            Collection.Find(aggregate => aggregate.Id == testAggregate.Id).Count().ShouldBe(1);

            testAggregate.Apply(new NumberChanged(999));

            _repository.Update(testAggregate);
            var result = Collection.Find(aggregate => aggregate.Id == testAggregate.Id).Single();

            //Then
            result.Id.ShouldBe(testAggregate.Id);
            result.Number.ShouldBe(testAggregate.Number);
        }