Esempio n. 1
0
        public EventSourcingQueryableSpec()
        {
            this.store = new QueryableStore(() => this.utcNow());

            var product = new Product(id1, "DevStore");

            product.Publish(1);
            product.Publish(2);
            product.Publish(3);

            store.Persist(product);

            product = new Product(id2, "WoVS");
            product.Publish(1);
            product.Publish(2);

            store.Persist(product);
        }
Esempio n. 2
0
        public void WhenSavingMultipleEvents_ThenCanLoadSpecificObject()
        {
            var store   = new QueryableStore();
            var product = new Product(id1, "DevStore");

            product.Publish(1);

            store.Persist(product);

            product = new Product(id2, "WoVS");
            product.Publish(1);
            product.Publish(2);
            product.Publish(3);

            store.Persist(product);

            var saved = new Product(store.Query().For <Product>(id2).Execute());

            Assert.Equal(3, saved.Version);
            Assert.Equal("WoVS", saved.Title);
            Assert.Equal(id2, saved.Id);
        }
Esempio n. 3
0
        public void WhenSavingEvent_ThenCanRetrieveIt()
        {
            var store   = new QueryableStore();
            var product = new Product(id1, "DevStore");

            product.Publish(1);

            store.Persist(product);

            var events = store.Query().Execute().ToList();

            Assert.Equal(2, events.Count);
            Assert.True(events.OfType <Product.CreatedEvent>().Any(x => x.Id == id1 && x.Title == "DevStore"));
            Assert.True(events.OfType <Product.PublishedEvent>().Any(x => x.Version == 1));
        }
Esempio n. 4
0
        public void WhenFilteringByDateSince_ThenSucceeds()
        {
            var product = new Product(store.Query().For <Product>(id2).Execute());

            var when = DateTime.Today.Subtract(TimeSpan.FromDays(5)).ToUniversalTime();

            this.utcNow = () => DateTime.Today.Subtract(TimeSpan.FromDays(7)).ToUniversalTime();
            product.Deactivate();
            store.Persist(product);

            this.utcNow = () => DateTime.Today.Subtract(TimeSpan.FromDays(6)).ToUniversalTime();
            product.Deactivate();
            store.Persist(product);

            this.utcNow = () => when;
            product.Deactivate();
            store.Persist(product);

            this.utcNow = () => DateTime.Today.Subtract(TimeSpan.FromDays(4)).ToUniversalTime();
            product.Deactivate();
            store.Persist(product);

            var events = store.Query().OfType <DeactivatedEvent>().Since(when).Execute();

            Assert.Equal(2, events.Count());
        }