public void GivenPopulatedEventStore_WhenLoadingSpecificVersionOfAggregate_ThenRepositoryShouldRebuildThatAggregateToThatVersion() { // Arrange var eventStore = new InMemoryEventStore(new ConsoleLogger()); var userId = Guid.NewGuid(); var events = new EventChain { new UserRegistered(userId), new UserChangedPassword("newpassword"), new UserChangedPassword("newnewpassword") }; eventStore.Save <User>(EventStreamIdFormatter.GetStreamId <User>(userId.ToString()), 0, events); var repository = new EventSourcingRepository <User>(eventStore, new Mock <IConcurrencyMonitor>().Object, _logger); // Act User user = repository.Get(userId, events[1].Version); // Assert Assert.AreEqual(events[1].Version, user.BaseVersion); }
public void GivenPopulatedEventStore_WhenLoadingAggregate_ThenRepositoryShouldRebuildThatAggregate() { // Arrange var eventStore = new InMemoryEventStore(new ConsoleLogger()); var userId = Guid.NewGuid(); eventStore.Save <User>( EventStreamIdFormatter.GetStreamId <User>(userId.ToString()), 0, new EventChain() { new UserRegistered(userId), new UserChangedPassword("newpassword"), new UserChangedPassword("newnewpassword") }); var repository = new EventSourcingRepository <User>(eventStore, new Mock <IConcurrencyMonitor>().Object, _logger); // Act User user = repository.Get(userId, 3); // Assert Assert.Throws <InvalidOperationException>(() => user.ChangePassword("newnewpassword")); // Should fail if the user's events were correctly applied }
public void GivenPopulatedEventStore_WhenLoadingAggregate_ThenAggregateVersionShouldReflectStoredEvents() { // Arrange var eventStore = new InMemoryEventStore(new ConsoleLogger()); var userId = Guid.NewGuid(); eventStore.Save <User>( EventStreamIdFormatter.GetStreamId <User>(userId.ToString()), EventStreamVersion.NoStream, new EventChain { new UserRegistered(userId), new UserChangedPassword("newpassword"), new UserChangedPassword("newnewpassword") }); var repository = new EventSourcingRepository <User>(eventStore, new Mock <IConcurrencyMonitor>().Object, _logger); // Act User user = repository.Get(userId, 2); // Assert Assert.AreEqual(2, user.BaseVersion); }