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); }
public void Init() { _productService = Substitute.For <IProductService>(); _productService.GetProducts(Arg.Any <FilterDto>()).Returns(CreateMockProducts()); _productService.GetProductById(Arg.Any <string>()) .Returns(new Product { Id = "MockId", Brand = "Mock Brand", Description = "Mock Desc", Model = "Mock Model" }); _queryHandler = new ProductQueryHandler(_productService); }
public ProductController(ProductsCommandHandler commandHandler, ProductQueryHandler queryHandler) { this._commandHandler = commandHandler; this._queryHandler = queryHandler; }