Example #1
0
        public void ApplyingNoEvents_GivenNewAggregateObject_ShouldNotModifyState()
        {
            // Arrange
            var user = new User();

            // Act
            user.ApplyAll(Enumerable.Empty<object>());

            // Assert
            AssertAreJsonEqual((Guid?)null, user.BaseVersion);
        }
Example #2
0
        public void ApplyingEventsThatHaveBaseType_GivenAnyAggregateObject_ShouldCallAppropriateApplyMethodForEachTypeInEventTypeHierarchy()
        {
            // Arrange
            var user = new User();
            var events = new object[] { new UserRegistered(user.Id), new UserChangedPassword("newpassword"), new UserChangedPassword("newerpassword") };

            // Act
            user.ApplyAll(events);

            // Assert
            Assert.AreEqual(3, user.ChangeCount);
        }
Example #3
0
        public void ApplyingPreviouslyGeneratedEvents_GivenNewAggregateObject_ShouldBringAggregateBackToPreviousState()
        {
            // Arrange
            var user = new User();
            user.Register();
            var events = new object[] {new UserRegistered(user.Id), new UserChangedPassword("newpassword"), new UserChangedPassword("newerpassword") };

            // Act
            user.ApplyAll(events);

            // Assert
            Assert.Throws<InvalidOperationException>(() => user.ChangePassword("newerpassword"), "Expected exception stating the new password must be different the the previous one, indicating that previous events have replayed successfully.");
        }
Example #4
0
        public void ApplyingPreviousEvents_GivenEventsThatWouldNotSatisfyCurrentInvariantLogic_ShouldNotFail()
        {
            // Arrange
            var userId = Guid.Parse("{42B90234-926D-4AA6-A960-F610D52F8F88}");
            var user = new User();
            var events = new object[] {new UserRegistered(userId), new UserChangedPassword("newpassword"), new UserChangedPassword("newpassword") };

            // Act
            user.ApplyAll(events);

            // Assert
            Assert.Throws<InvalidOperationException>(() => user.ChangePassword("newpassword"), "Expected exception stating the new password must be different the the previous one, indicating that previous events have replayed successfully.");
        }
Example #5
0
        public void InvokingBehaviourOnObjectWithNoIdThatDoesntSetTheId_ShouldFail()
        {
            var user = new User();
            var events = new object[] { /*new UserRegistered(user.Id), */new UserChangedPassword("newpassword"), new UserChangedPassword("newpassword") };
            user.ApplyAll(events);

            Assert.Throws<IdNotSetException>(() => user.ChangePassword("newnewpassword"));
        }