public void Saving_GivenEventWithGuidProperty_ShouldAllowReloadingToGuidType() { // Arrange IEventStore store = new SqlServerEventStoreTestDataBuilder().Build(); 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(), EventStreamVersion.NoStream, customer.GetUncommittedEvents()); // Act var acctMgrAssignedEvent = (AccountManagerAssigned)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 SqlServerEventStoreTestDataBuilder().Build(); // Act EventStream <Customer> events = store.Load <Customer>(Guid.NewGuid().ToString()); // Assert Assert.That(events, Is.Null); }
public void Saving_GivenNoEvents_ShouldDoNothing() { // Arrange IEventStore store = new SqlServerEventStoreTestDataBuilder().Build(); // Act var id = Guid.NewGuid(); store.Save <Customer>(id.ToString(), EventStreamVersion.NoStream, Enumerable.Empty <IEvent>()); var stream = store.Load <Customer>(id.ToString()); // Assert Assert.That(stream, Is.Null); }
public void Saving_GivenEvents_ShouldAllowReloading() { // Arrange IEventStore store = new SqlServerEventStoreTestDataBuilder().Build(); // Act var customer = new Customer(); customer.Signup(); store.Save <Customer>(customer.Id.ToString(), EventStreamVersion.NoStream, 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_WhenLoadingSpecialNoStreamVersion_ThenShouldFail() { // Arrange IEventStore store = new SqlServerEventStoreTestDataBuilder().Build(); var customerId = Guid.NewGuid(); var storedEvents = new IEvent[] { new CustomerSignedUp(customerId), new SubscribedToNewsletter("latest"), new SubscribedToNewsletter("top") }; store.Save <Customer>(customerId.ToString(), EventStreamVersion.NoStream, storedEvents); // Act / Assert Assert.Throws <ArgumentOutOfRangeException>(() => store.Load <Customer>(customerId.ToString(), EventStreamVersion.NoStream)); }
public void GivenAggregateWithMultipleEvents_WhenLoadingMaxVersion_ThenShouldReturnAllEvents() { // Arrange IEventStore store = new SqlServerEventStoreTestDataBuilder().Build(); 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(), EventStreamVersion.NoStream, storedEvents); // Act var stream = store.Load <Customer>(customerId.ToString(), EventStreamVersion.Max); // Assert CollectionAssert.AreEqual(storedEvents, stream.Events, "Events loaded from store do not match version requested."); }
public void Saving_GivenSingleEvent_ShouldAllowReloading() { // Arrange IEventStore store = new SqlServerEventStoreTestDataBuilder().Build(); // Act var id = Guid.NewGuid(); var evt = new CustomerSignedUp(id); store.Save <Customer>(id.ToString(), EventStreamVersion.NoStream, 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."); }