public void PublishesEvents()
        {
            // Arrange
            var customer = new Customer("My name");
            var container = CreateContainer(new[] { typeof(CustomerInitializedHandler) });

            // Act
            WithEventStore(container, s => s.Store(customer));

            // Assert
            var session = container.Resolve<IDocumentSession>();
            var vm = session.Query<CustomerViewModel>().Customize(x => x.WaitForNonStaleResults()).SingleOrDefault();
            Assert.That(vm, Is.Not.Null);
            Debug.Assert(vm != null, "vm != null");
            Assert.That(vm.Name, Is.EqualTo("My name"));
        }
        public void StoresAggregateInUnitOfWork()
        {
            // Arrange
            var customer = new Customer("Name of customer");

            // Act
            WithEventStore(
                CreateContainer(new[] { typeof(CustomerInitializedHandler) }),
                session =>
                {
                    session.Store(customer);
                    var stored = session.Load<Customer>(customer.Id);
                    // Assert
                    Assert.That(stored, Is.Not.Null);
                });
        }
        public void DispatchesAllEvents()
        {
            // Arrange
            var called = 0;
            var container = CreateContainer(new[] { new Handler { Callback = () => called ++ } });
            var documentStore = container.Resolve<IDocumentStore>();
            var eventStore = container.Resolve<EventStore>();
            var documentSession = container.Resolve<IDocumentSession>();
            var eventStoreSession = eventStore.OpenSession(documentStore, documentSession);
            var aggregate = new Customer("Customer name");
            eventStoreSession.Store(aggregate);
            eventStoreSession.SaveChanges();

            // Act
            Assert.That(called, Is.EqualTo(1));
            eventStore.RebuildReadModels();

            // Assert
            Assert.That(called, Is.EqualTo(2));
        }