예제 #1
0
        public void WhenCommandIsIssuedThenEventIsAppliedToAggregate()
        {
            var aggregate = new TestAggregate();

            aggregate.ChangeName("New Name");

            Assert.Equal("New Name", aggregate.Name);
        }
예제 #2
0
        public void WhenCommandIsIssuedThenPendingEventIsCreated()
        {
            var aggregate = new TestAggregate();

            Assert.Equal(0, aggregate.GetPendingEvents().Count);

            aggregate.ChangeName("New Name");

            Assert.Equal(1, aggregate.GetPendingEvents().Count);
        }
예제 #3
0
        public void WhenCommandIsIssuedThenVersionIsIncremented()
        {
            var aggregate = new TestAggregate();

            Assert.Equal(-1, aggregate.Version);

            aggregate.ChangeName("New Name");

            Assert.Equal(0, aggregate.Version);
        }
예제 #4
0
        public async void WhenAggregateIsSavedThenPendingEventsAreWritten()
        {
            var connection = A.Fake <IEventStoreConnection>();
            var repository = new Repository(connection, new EventTypeResolver(ReflectionHelper.ContractsAssembly));

            var testAggregate = new TestAggregate();

            testAggregate.ChangeName("First Name");
            testAggregate.ChangeName("Second Name");

            await repository.SaveAsync(testAggregate);

            Func <IEnumerable <EventData>, bool> expectedEventData = data => data.Count(x => x.Type == "TestAggregateNameChangedEvent") == 2;

            A.CallTo(
                () =>
                connection.AppendToStreamAsync(A <string> .That.IsEqualTo(testAggregate.Identifier.ToString()),
                                               A <int> ._,
                                               A <IEnumerable <EventData> > .That.Matches(expectedEventData, "EventData Is Correct"),
                                               A <UserCredentials> ._)).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #5
0
        public async void WhenAggregateIsSavedThenPendingEventsAreClearedFromAggregate()
        {
            var aggregate = new TestAggregate();

            aggregate.ChangeName("New Name");

            var connection = A.Fake <IEventStoreConnection>();
            var repository = new Repository(connection, new EventTypeResolver(ReflectionHelper.ContractsAssembly));

            await repository.SaveAsync(aggregate);

            Assert.Equal(0, aggregate.GetPendingEvents().Count);
        }