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);
        }
Example #2
0
        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 Loading_GivenEmptyStore_ShouldReturnNull()
        {
            // Arrange
            IEventStore store = new RavenEventStore(_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 RavenEventStore(_documentStore, versionHandlerMock.Object);

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

            // Assert
            CollectionAssert.IsEmpty(events);
        }
Example #5
0
        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);
        }
Example #7
0
        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_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.");
        }
Example #9
0
        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.");
        }
Example #10
0
 public void Setup()
 {
     // Arrange
     _eventPublisher = new InMemoryEventBus(new MessageRouterStub());
     var eventStore = new RavenEventStore(_eventPublisher, "RavenDB");
     eventStore.DeleteCollection();
     _aggregate = new StubAggregate();
     _aggregate.AggregateId = Guid.NewGuid();
     _aggregate.DoThis();
     _aggregate.DoSomethingElse();
     _aggregate.DoThis();
     _aggregate.DoSomethingElse();
     _aggregateId = _aggregate.AggregateId;
     eventStore.Insert(_aggregate);
     eventStore.Commit();
 }
Example #11
0
        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")));
        }
Example #12
0
        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);
            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);
            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 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.");
        }
Example #16
0
        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.");
        }
Example #17
0
        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.");
        }
Example #18
0
        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 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);
                }
            });
        }
Example #20
0
 public void ShouldNotFail()
 {
     var id = Guid.NewGuid();
     var eventPublisher = new InMemoryEventBus(new MessageRouterStub());
     var eventStore = new RavenEventStore(eventPublisher, "RavenDB");
     eventStore.DeleteCollection();
     var events = new List<IDomainEvent>
                      {
                          new ValidEvent(id),
                          new AnotherValidEvent(id),
                          new ValidEvent(id),
                          new AnotherValidEvent(id)
                      };
     eventStore.InsertBatchTest(events);
     var eventsFromStore = eventStore.GetEventsTest(id);
     foreach (var domainEvent in eventsFromStore)
     {
         events.Should().Contain(domainEvent);
     }
     
 }
        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"));
            }
        }
Example #22
0
        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.");
        }
Example #23
0
 private void VerifyEvents(Func<RavenEventStore, IEnumerable<IDomainEvent>> getEventsFunc)
 {
     var eventStore = new RavenEventStore(_eventPublisher, "RavenDB");
     var @events = getEventsFunc(eventStore).ToList();
     @events.Count.Should().Be(4);
     for (int i = 0; i < @events.Count; i++)
     {
         @events[i].EventNumber.Should().Be(i);
         if (i % 2 == 0)
             @events[i].GetType().Should().Be(typeof(ValidEvent));
         else
             @events[i].GetType().Should().Be(typeof(AnotherValidEvent));
     }
 }
Example #24
0
        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);
        }
Example #25
0
        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.");
        }
Example #26
0
        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);
        }