public void ApplyingNoEvents_GivenNewAggregateObject_ShouldNotModifyState() { // Arrange var user = new User(); // Act user.ApplyAll(Enumerable.Empty<object>()); // Assert AssertAreJsonEqual((Guid?)null, user.BaseVersion); }
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); }
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."); }
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."); }
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")); }