public void Saving_GivenEventWithGuidProperty_ShouldAllowReloadingToGuidType() { // Arrange var versionHandlerMock = new Mock <IVersionHandler>(); IEventStore store = new DelayedWriteRavenEventStore(_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.Add(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_GivenNoEvents_ShouldDoNothing() { // Arrange var versionHandlerMock = new Mock <IVersionHandler>(); IEventStore store = new DelayedWriteRavenEventStore(_documentStore, versionHandlerMock.Object); // Act var id = Guid.NewGuid(); store.Add(id, Enumerable.Empty <object>()); var events = store.Load(id); // Assert CollectionAssert.IsEmpty(events); }
public void Saving_GivenEvents_ShouldAllowReloading() { // Arrange IEventStore store = new DelayedWriteRavenEventStore(_documentStore, _versionHandlerMock.Object); // Act var customer = new Customer(); customer.Signup(); store.Add(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 GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersionThatNoEventHas_ThenShouldFail() { // Arrange IEventStore store = new DelayedWriteRavenEventStore(_documentStore, _versionHandlerMock.Object); var customerId = Guid.NewGuid(); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; store.Add(customerId, storedEvents); // Act / Assert Assert.Throws <ArgumentOutOfRangeException>(() => store.Load(customerId, Guid.Parse("00000000-0000-0000-0000-000000000001"))); }
public void Disposing_a_delayedwriteeventstore_with_pending_changes_should_throw_exception() { Assert.Throws<InvalidOperationException>(() => { using (var eventStore = new DelayedWriteRavenEventStore(_documentStore, _versionHandlerMock.Object)) { var customerId = Guid.NewGuid(); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; eventStore.Add(customerId, storedEvents); } }); }
public void Disposing_a_delayedwriteeventstore_with_pending_changes_should_throw_exception() { Assert.Throws <InvalidOperationException>(() => { using (var eventStore = new DelayedWriteRavenEventStore(_documentStore, _versionHandlerMock.Object)) { var customerId = Guid.NewGuid(); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; eventStore.Add(customerId, storedEvents); } }); }
public void Saving_GivenSingleEvent_ShouldAllowReloading() { // Arrange var versionHandlerMock = new Mock <IVersionHandler>(); IEventStore store = new DelayedWriteRavenEventStore(_documentStore, versionHandlerMock.Object); // Act var id = Guid.NewGuid(); var evt = new CustomerSignedUp(id); store.Add(id, new[] { 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 GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersion_ThenShouldOnlyReturnRequestedEvents() { // Arrange IEventStore store = new DelayedWriteRavenEventStore(_documentStore, _versionHandlerMock.Object); var customerId = Guid.NewGuid(); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; store.Add(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_GivenEventMappedToAggregateType_ThenShouldSetRavenCollectionName() { var customerId = Guid.NewGuid(); using (var eventStore = new DelayedWriteRavenEventStore(_documentStore, _versionHandlerMock.Object)) { Conventions.SetFindAggregateTypeForEventType( type => { if (type == typeof(CustomerSignedUp)) { return(typeof(Customer)); } return(typeof(EventStream)); }); var storedEvents = new object[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; eventStore.Add(customerId, storedEvents); eventStore.Flush(); } using (var session = _documentStore.OpenSession()) { var eventStream = session.Load <EventStream>(customerId.ToString()); var entityName = session.Advanced.GetMetadataFor(eventStream)[Constants.RavenEntityName].ToString(); Assert.That(entityName, Is.EqualTo("Customers")); } }