public void Saving_GivenEventWithGuidProperty_ShouldAllowReloadingToGuidType() { // Arrange var versionHandlerMock = new Mock <IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); var customer = new Customer(); customer.Signup(); var accountManager = new AccountManager(); var startDate = new DateTime(2012, 4, 28); accountManager.Employ(startDate); customer.AssignAccountManager(accountManager.Id, startDate); store.Store(customer.Id, customer.GetUncommittedEvents()); // Act var acctMgrAssignedEvent = (AssignedAccountManager)store.Load(customer.Id).LastOrDefault(); // Assert Assert.NotNull(acctMgrAssignedEvent); Assert.AreEqual(accountManager.Id, acctMgrAssignedEvent.AccountManagerId); }
public void Saving_GivenEventWithGuidProperty_ShouldAllowReloadingToGuidType() { // Arrange IEventStore store = new RavenEventStore(_documentStore); var customer = new Customer(); customer.Signup(); var accountManager = new AccountManager(); var startDate = new DateTime(2012, 4, 28); accountManager.Employ(startDate); customer.AssignAccountManager(accountManager.Id, startDate); store.Save <Customer>(customer.Id.ToString(), 0, customer.GetUncommittedEvents()); // Act var acctMgrAssignedEvent = (AssignedAccountManager)store.Load <Customer>(customer.Id.ToString()) .Events .LastOrDefault(); // Assert Assert.NotNull(acctMgrAssignedEvent); Assert.AreEqual(accountManager.Id, acctMgrAssignedEvent.AccountManagerId); }
public void Loading_GivenEmptyStore_ShouldReturnNull() { // Arrange IEventStore store = new RavenEventStore(_documentStore); // Act EventStream <Customer> stream = store.Load <Customer>(Guid.NewGuid().ToString()); // Assert CollectionAssert.IsEmpty(stream.Events); }
public void Loading_GivenEmptyStore_ShouldReturnNull() { // Arrange var versionHandlerMock = new Mock <IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); // Act IEnumerable <object> events = store.Load(Guid.NewGuid()); // Assert CollectionAssert.IsEmpty(events); }
public void Loading_GivenEmptyStore_ShouldReturnNull() { // Arrange var versionHandlerMock = new Mock<IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); // Act IEnumerable<object> events = store.Load(Guid.NewGuid()); // Assert CollectionAssert.IsEmpty(events); }
public void Saving_GivenNoEvents_ShouldDoNothing() { // Arrange IEventStore store = new RavenEventStore(_documentStore); // Act var id = Guid.NewGuid(); store.Save <Customer>(id.ToString(), 0, Enumerable.Empty <IEvent>()); var stream = store.Load <Customer>(id.ToString()); // Assert CollectionAssert.IsEmpty(stream.Events); }
public void Saving_GivenNoEvents_ShouldDoNothing() { // Arrange var versionHandlerMock = new Mock <IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); // Act var id = Guid.NewGuid(); store.Store(id, Enumerable.Empty <object>()); var events = store.Load(id); // Assert CollectionAssert.IsEmpty(events); }
public void GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersionThatNoEventHas_ThenShouldFail() { // Arrange IEventStore store = new RavenEventStore(_documentStore, _versionHandlerMock.Object); var customerId = Guid.NewGuid(); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; store.Store(customerId, storedEvents); // Act / Assert Assert.Throws<ArgumentOutOfRangeException>(() => store.Load(customerId, Guid.Parse("00000000-0000-0000-0000-000000000001"))); }
public void Saving_GivenEvents_ShouldAllowReloading() { // Arrange IEventStore store = new RavenEventStore(_documentStore, _versionHandlerMock.Object); // Act var customer = new Customer(); customer.Signup(); store.Store(customer.Id, customer.GetUncommittedEvents()); var events = store.Load(customer.Id); // Assert Assert.NotNull(events); CollectionAssert.AreEqual(customer.GetUncommittedEvents(), events, "Events reloaded from store do not match those generated by aggregate."); }
public void Saving_GivenEvents_ShouldAllowReloading() { // Arrange IEventStore store = new RavenEventStore(_documentStore); // Act var customer = new Customer(); customer.Signup(); store.Save <Customer>(customer.Id.ToString(), 0, customer.GetUncommittedEvents()); var stream = store.Load <Customer>(customer.Id.ToString()); // Assert Assert.NotNull(stream); CollectionAssert.AreEqual(customer.GetUncommittedEvents(), stream.Events, "Events reloaded from store do not match those generated by aggregate."); }
public void GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersionThatNoEventHas_ThenShouldFail() { // Arrange IEventStore store = new RavenEventStore(_documentStore); var customerId = Guid.NewGuid(); var storedEvents = new IEvent[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; store.Save <Customer>(customerId.ToString(), 0, storedEvents); // Act / Assert Assert.Throws <ArgumentOutOfRangeException>(() => store.Load <Customer>(customerId.ToString(), 4)); }
public void GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersion_ThenShouldOnlyReturnRequestedEvents() { // Arrange IEventStore store = new RavenEventStore(_documentStore); var customerId = Guid.NewGuid(); var storedEvents = new EventChain().Add(new CustomerSignedUp(customerId)) .Add(new SubscribedToNewsletter("latest")) .Add(new SubscribedToNewsletter("top")); store.Save <Customer>(customerId.ToString(), 0, storedEvents); // Act var stream = store.Load <Customer>(customerId.ToString(), storedEvents[1].Version); // Assert CollectionAssert.AreEqual(storedEvents.Take(2), stream.Events, "Events loaded from store do not match version requested."); }
public void GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersionThatNoEventHas_ThenShouldFail() { // Arrange IEventStore store = new RavenEventStore(_documentStore, _versionHandlerMock.Object); var customerId = Guid.NewGuid(); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; store.Store(customerId, storedEvents); // Act / Assert Assert.Throws <ArgumentOutOfRangeException>(() => store.Load(customerId, Guid.Parse("00000000-0000-0000-0000-000000000001"))); }
public void GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersion_ThenShouldOnlyReturnRequestedEvents() { // Arrange IEventStore store = new RavenEventStore(_documentStore, _versionHandlerMock.Object); var customerId = Guid.NewGuid(); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; store.Store(customerId, storedEvents); // Act var events = store.Load(customerId, ((Event)storedEvents[1]).Version); // Assert CollectionAssert.AreEqual(storedEvents.Take(2), events, "Events loaded from store do not match version requested."); }
public void Saving_GivenSingleEvent_ShouldAllowReloading() { // Arrange IEventStore store = new RavenEventStore(_documentStore); // Act var id = Guid.NewGuid(); var evt = new CustomerSignedUp(id); store.Save <Customer>(id.ToString(), 0, new[] { evt }); var stream = store.Load <Customer>(id.ToString()); // Assert Assert.NotNull(stream); CollectionAssert.AreEqual( new object[] { evt }, stream.Events, "Events reloaded from store do not match those generated by aggregate."); }
public void Saving_GivenSingleEvent_ShouldAllowReloading() { // Arrange var versionHandlerMock = new Mock <IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); // Act var id = Guid.NewGuid(); var evt = new CustomerSignedUp(id); store.Store(id, evt); var events = store.Load(id); // Assert Assert.NotNull(events); CollectionAssert.AreEqual( new object[] { evt }, events, "Events reloaded from store do not match those generated by aggregate."); }
public void Saving_GivenSingleEvent_ShouldAllowReloading() { // Arrange var versionHandlerMock = new Mock<IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); // Act var id = Guid.NewGuid(); var evt = new CustomerSignedUp(id); store.Store(id, evt); var events = store.Load(id); // Assert Assert.NotNull(events); CollectionAssert.AreEqual( new object[] { evt }, events, "Events reloaded from store do not match those generated by aggregate."); }
public void Saving_GivenNoEvents_ShouldDoNothing() { // Arrange var versionHandlerMock = new Mock<IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); // Act var id = Guid.NewGuid(); store.Store(id, Enumerable.Empty<object>()); var events = store.Load(id); // Assert CollectionAssert.IsEmpty(events); }
public void Saving_GivenEventWithGuidProperty_ShouldAllowReloadingToGuidType() { // Arrange var versionHandlerMock = new Mock<IVersionHandler>(); IEventStore store = new RavenEventStore(_documentStore, versionHandlerMock.Object); var customer = new Customer(); customer.Signup(); var accountManager = new AccountManager(); var startDate = new DateTime(2012, 4, 28); accountManager.Employ(startDate); customer.AssignAccountManager(accountManager.Id, startDate); store.Store(customer.Id, customer.GetUncommittedEvents()); // Act var acctMgrAssignedEvent = (AssignedAccountManager)store.Load(customer.Id).LastOrDefault(); // Assert Assert.NotNull(acctMgrAssignedEvent); Assert.AreEqual(accountManager.Id, acctMgrAssignedEvent.AccountManagerId); }