コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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.");
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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.");
        }
コード例 #6
0
        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.");
        }
コード例 #7
0
        public void Disposing_a_delayedwriteeventstore_with_pending_changes_should_throw_exception()
        {
            Assert.Throws <InvalidOperationException>(
                () =>
            {
                using (var eventStore = new RavenEventStore(_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);
                }
            });
        }
コード例 #8
0
        public void Saving_GivenEventMappedToAggregateType_ThenShouldSetRavenCollectionName()
        {
            var customerId = Guid.NewGuid();

            using (var eventStore = new RavenEventStore(_documentStore))
            {
                Conventions.SetFindAggregateTypeForEventType(
                    type =>
                {
                    if (type == typeof(CustomerSignedUp))
                    {
                        return(typeof(Customer));
                    }

                    return(typeof(EventStream));
                });

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

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