Example #1
0
        public void ShouldUpdateProductCatalogView()
        {
            var rootId  = Guid.NewGuid();
            var handler = new ProductServiceCommandHandler(_eventStore, _factory);

            var idProd2 = Guid.NewGuid();
            var view    = new ProductView();

            _resolver.Register <ProductCreated>(view);

            IProductQueryHandler queryHandler = new ProductQueryHandler(view);

            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"));
            handler.Execute(new CreateProductCommand(rootId, idProd2, "Notebook 2 em 1 Dell", "Notebook Lenovo 2 em 1 ideapad C340 i7-8565U 8GB 256GB SSD Win10 14' FHD IPS - 81RL0001BR"));

            var product      = queryHandler.GetById(idProd2);
            var listProducts = queryHandler.ListAllProducts();
            var dell         = queryHandler.ListByFilter(x => x.Name.Contains("Dell"));


            Assert.True(product.Id == idProd2);
            Assert.True(listProducts.Count == 2);
            Assert.True(dell.Count == 1);
        }
Example #2
0
        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());
        }
Example #3
0
        public void ShouldCreateProductCatalog()
        {
            var rootId  = Guid.NewGuid();
            var handler = new ProductServiceCommandHandler(_eventStore, _factory);
            var view    = new ProductView();

            _resolver.Register <ProductCreated>(view);

            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);

            Assert.True(stream.Version == 2);
            Assert.True(1 == view.Products.Count);
        }
Example #4
0
        public void ShouldMergeEvents()
        {
            var eventBus     = new MemoryEventBus(new MemoryResolver());
            var appendOnly   = new MemoryAppendOnlyStore(eventBus);
            var eventStore   = new EventStore(appendOnly, eventBus);
            var snapShotRepo = new SnapshotRepository();
            var factory      = new AggregateFactory(eventStore, snapShotRepo);

            var rootId  = Guid.NewGuid();
            var handler = new ProductServiceCommandHandler(eventStore, factory);

            handler.Execute(new CreateProductCatalog(rootId));
            var prodId = Guid.NewGuid();

            handler.Execute(new CreateProductCommand(rootId, prodId, "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 threads = new List <Task>();

            threads.Add(Task.Run(() =>
            {
                var handlerThread1 = new ProductServiceCommandHandler(eventStore, factory);
                handlerThread1.Execute(new CreateProductCommand(rootId, Guid.NewGuid(), "Notebook 2 em 1 Dell", "Notebook 2 em 1 Dell Inspiron i14-5481-M11F 8ª Geração Intel Core i3 4GB 128GB SSD 14' Touch Windows 10 Office 365 McAfe"));
            }));

            threads.Add(Task.Run(() =>
            {
                var handlerThread2 = new ProductServiceCommandHandler(eventStore, factory);
                handlerThread2.Execute(new ChangeProductNameCommand(rootId, prodId, "Novo nome"));
            }));

            Task.WaitAll(threads.ToArray());

            var stream         = eventStore.LoadEventStream(rootId);
            var productChanged = (ProductNameChanged)stream.Events.Where(x => x.GetType() == typeof(ProductNameChanged)).FirstOrDefault();

            Assert.True(4 == stream.Version);
            Assert.True("Novo nome" == productChanged.Name);
        }