예제 #1
0
        public void Should_Redirect_Change_Created_By_Action_To_Event_Handler()
        {
            const int expectedUncommittedChanges = 2;
            const int expectedVersion            = 1;

            var aggregate = new FakeAggregate(Guid.NewGuid(), nameof(FakeAggregate));

            aggregate.PerformAction();

            var uncommittedChanges = (aggregate as IEnumerable <UncommittedChange>);

            Assert.Equal(expectedVersion, (aggregate as IAggregateRoot).Version);
            Assert.Equal(expectedUncommittedChanges, uncommittedChanges.Count());
            Assert.Collection(
                uncommittedChanges,
                uncommittedChange =>
            {
                Assert.NotNull(uncommittedChange.Event);
                Assert.IsType <FakeCreateEvent>(uncommittedChange.Event);
            },
                uncommittedChange =>
            {
                Assert.NotNull(uncommittedChange.Event);
                Assert.IsType <FakeDummyActionEvent>(uncommittedChange.Event);
            });
        }
예제 #2
0
        public async Task Should_Publish_Aggregate_Events_When_Saving_Through_Repository()
        {
            const int expectedChanges = 2;

            var changes           = new List <Change>();
            var aggregateId       = Guid.NewGuid();
            var cancellationToken = default(CancellationToken);

            var storage    = Substitute.For <IStorage>();
            var repository = new AggregateRootRepository <FakeAggregate>(storage, null);

            var aggregate = new FakeAggregate(aggregateId, nameof(FakeAggregate));

            aggregate.Subscribe(changes.Add);

            aggregate.PerformAction();

            Assert.Empty(changes);

            await repository.SaveAsync(aggregate, cancellationToken);

            Assert.Equal(expectedChanges, changes.Count);
            Assert.Collection(
                changes,
                change =>
            {
                Assert.NotNull(change.Event);
                Assert.IsType <FakeCreateEvent>(change.Event);
            },
                change =>
            {
                Assert.NotNull(change.Event);
                Assert.IsType <FakeDummyActionEvent>(change.Event);
            });
        }