Esempio n. 1
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);
            });
        }