Exemplo n.º 1
0
        public void AcceptingEvents_GivenAggregateWithUncommittedEvents_ShouldClearUncommittedEvents()
        {
            // Arrange
            var user = new User();
            user.Register();
            user.ChangePassword("newpassword");

            // Act
            var userRegisteredEvent = new UserRegistered(user.Id);
            var userChangedPasswordEvent = new UserChangedPassword("newpassword") { ParentVersion = userRegisteredEvent.Version };
            IEnumerable<object> expectedBefore = new object[] { userRegisteredEvent, userChangedPasswordEvent };
            IEnumerable<object> expectedAfter = new object[0];

            IEnumerable<object> before = user.GetUncommittedEvents();
            user.AcceptUncommittedEvents();
            IEnumerable<object> after = user.GetUncommittedEvents();

            // Assert
            CollectionAssertAreJsonEqual(expectedBefore, before);
            CollectionAssertAreJsonEqual(expectedAfter, after);
        }