public void Saving_GivenEventWithGuidProperty_ShouldAllowReloadingToGuidType()
        {
            // Arrange
            IEventStore store = new DelayedWriteRavenEventStore(_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);
        }
Example #2
0
        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 Loading_GivenEmptyStore_ShouldReturnNull()
        {
            // Arrange
            IEventStore store = new DelayedWriteRavenEventStore(_documentStore);

            // Act
            EventStream <Customer> stream = store.Load <Customer>(Guid.NewGuid().ToString());

            // Assert
            CollectionAssert.IsEmpty(stream.Events);
        }
Example #4
0
        public void Loading_GivenEmptyStore_ShouldReturnNull()
        {
            // Arrange
            var         versionHandlerMock = new Mock <IVersionHandler>();
            IEventStore store = new DelayedWriteRavenEventStore(_documentStore, versionHandlerMock.Object);

            // Act
            IEnumerable <object> events = store.Load(Guid.NewGuid());

            // Assert
            CollectionAssert.IsEmpty(events);
        }
        public void Saving_GivenNoEvents_ShouldDoNothing()
        {
            // Arrange
            IEventStore store = new DelayedWriteRavenEventStore(_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);
        }
Example #6
0
        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);
        }
Example #7
0
        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 Saving_GivenEvents_ShouldAllowReloading()
        {
            // Arrange
            IEventStore store = new DelayedWriteRavenEventStore(_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.");
        }
Example #9
0
        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 GivenAggregateWithMultipleEvents_WhenLoadingSpecificVersionThatNoEventHas_ThenShouldFail()
        {
            // Arrange
            IEventStore store        = new DelayedWriteRavenEventStore(_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 DelayedWriteRavenEventStore(_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 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
            IEventStore store = new DelayedWriteRavenEventStore(_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 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);
                }
            });
        }
Example #15
0
        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.");
        }
Example #16
0
        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.");
        }
Example #17
0
        public void Disposing_a_delayedwriteeventstore_with_pending_changes_should_throw_exception()
        {
            Assert.Throws <InvalidOperationException>(
                () =>
            {
                using (var eventStore = new DelayedWriteRavenEventStore(_documentStore))
                {
                    var customerId = Guid.NewGuid();

                    var storedEvents = new EventChain
                    {
                        new CustomerSignedUp(customerId),
                        new SubscribedToNewsletter("latest"),
                        new SubscribedToNewsletter("top")
                    };

                    eventStore.Save <Customer>(customerId.ToString(), 0, storedEvents);
                }
            });
        }
Example #18
0
        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"));
            }
        }