public void ShouldCreateProductCatalog() { var rootId = Guid.NewGuid(); var handler = new ProductServiceCommandHandler(_eventStore, _factory); handler.Execute(new CreateProductCatalog(rootId)); handler.Execute(new CreateProductCommand(rootId, Guid.NewGuid(), "Notebook Lenovo 2 em 1 ideapad C340", "Notebook Lenovo 2 em 1 ideapad C340 i7-8565U 8GB 256GB SSD Win10 14' FHD IPS - 81RL0001BR")); var stream = _eventStore.LoadEventStream(rootId); var productAggregate = new ProductCatalogAggregate(stream); Assert.True(stream.Version == 2); Assert.True(1 == productAggregate.CountProducts()); }
public void ShouldIncrementVersionCorrectly() { var rootId = Guid.NewGuid(); var queueService = new MemoryQueueService(); var appendOnly = new MemoryAppendOnlyStore(queueService); var eventStore = new EventStore(appendOnly); var factory = new AggregateFactory(eventStore); var rootToSave = factory.Create <ProductCatalogAggregate>(rootId); eventStore.AppendToStream <ProductCatalogAggregate>(rootToSave.Id, rootToSave.Version, rootToSave.Changes); var stream = eventStore.LoadEventStream(rootId); var root = new ProductCatalogAggregate(stream); root.CreateProduct(new CreateProductCommand(rootId, Guid.NewGuid(), "Notebook", "Dell Inspiron 15000")); eventStore.AppendToStream <ProductCatalogAggregate>(root.Id, root.Version, root.Changes); stream = eventStore.LoadEventStream(rootId); root = new ProductCatalogAggregate(stream); Assert.Equal(2, stream.Version); Assert.Equal(1, root.CountProducts()); }