public async Task ShouldUpdateProduct() { var productId = Guid.NewGuid(); var supplierId = Guid.NewGuid(); var model = new ProductCategoryRequestModel { SupplierId = Guid.NewGuid(), CategoryName = "celular" }; var product = new CategoryProductBuilder() .WithSupplier(supplierId) .WithName("carro") .Construct(); _productRepository .GetById(supplierId) .Returns(product); _productRepository.ValidateEntityExistence(productId).Returns(true); _productRepository.GetById(productId).Returns(product); await _productService.Update(productId, model); await _productRepository .Received(1) .Update(Arg.Is <ProductCategory>(x => x.CategoryName.ToString() == "celular")); }
public async Task Update(Guid id, ProductCategoryRequestModel request) { await _supplierService.ValidateEntityExistence(request.SupplierId); var productToUpdate = await _productCategoryRepository.GetById(id); if (productToUpdate == null) { _notificationService.AddNotification("Erro ao atualizar categoria de produto", "Categoria de produto não encontrada"); return; } productToUpdate.Update(request.CategoryName, request.SupplierId); await _productCategoryRepository.Update(productToUpdate); }
public async Task should_fail_when_category_name_invalid() { var supplierId = Guid.NewGuid(); var model = new ProductCategoryRequestModel() { SupplierId = supplierId, CategoryName = "" }; _supplierService.ExistsById(supplierId).Returns(true); await _productService.Create(model); Assert.True(_notificationService.HasNotifications()); }
public void ShouldSaveProductCategory() { var supplierId = Guid.NewGuid(); var model = new ProductCategoryRequestModel() { SupplierId = supplierId, CategoryName = "celular" }; _supplierService.ExistsById(supplierId).Returns(true); _productService.Create(model); _productRepository.Received(1) .Create(Arg.Is <ProductCategory>(x => x.CategoryName.ToString() == "celular" && x.SupplierId == supplierId)); }
public async Task should_dar_erro_quando_nao_encontrar_categoria_para_update() { var productId = Guid.Empty; var supplierId = Guid.NewGuid(); var model = new ProductCategoryRequestModel { SupplierId = Guid.NewGuid(), CategoryName = "celular" }; var exception = await Assert.ThrowsAsync <Exception>(async() => await _productService.Update(productId, model)); exception.Message.Should().Be("Categoria de produto não encontrada"); await _productRepository .DidNotReceive() .Update(Arg.Any <ProductCategory>()); }
public async Task Create(ProductCategoryRequestModel request) { await _supplierService.ValidateEntityExistence(request.SupplierId); if (_notificationService.HasNotifications()) { return; } var productCategory = new ProductCategory(request.CategoryName, request.SupplierId); if (productCategory.Invalid) { _notificationService.AddEntityNotifications(productCategory.ValidationResult); return; } await _productCategoryRepository.Create(productCategory); }
public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] ProductCategoryRequestModel request) { await _productCategoryService.Update(id, request); return(Accepted()); }
public async Task <IActionResult> Create([FromBody] ProductCategoryRequestModel request) { await _productCategoryService.Create(request); return(Accepted()); }