コード例 #1
0
        public async Task Can_Modify_Aggregate()
        {
            // PREPARE
            var @event = new TestAggregateCreated
            {
                TestAggregateId = 332,
                Name            = "ddsd"
            };

            var aggregate = new TestAggregate();
            await aggregate.Initialize(GetEvents(@event), Task.FromResult(3333));

            // RUN
            aggregate.ChangeName("changed name");

            // ASSERT
            Assert.True(aggregate.HasChanges());
            Assert.Equal("332", aggregate.AggregateId);
            Assert.Equal(3333, aggregate.AggregateVersion);
            var changes = aggregate.GetChanges();

            Assert.Single(changes);
            var nameChanged = (TestAggregateNameChanged)changes.Single();

            Assert.Equal(332, nameChanged.TestAggregateId);
            Assert.Equal("ddsd", nameChanged.PreviousName);
            Assert.Equal("changed name", nameChanged.CurrentName);
        }
コード例 #2
0
        public async Task Can_Initialize_Aggregate_From_Events()
        {
            // PREPARE
            var @event = new TestAggregateCreated
            {
                TestAggregateId = 332,
                Name            = "ddsd"
            };

            // RUN
            var aggregate = new TestAggregate();
            await aggregate.Initialize(GetEvents(@event), Task.FromResult(3333));

            // ASSERT
            Assert.False(aggregate.HasChanges());
            Assert.Equal("332", aggregate.AggregateId);
            Assert.Equal(3333, aggregate.AggregateVersion);
            var changes = aggregate.GetChanges();

            Assert.Empty(changes);
        }