public void Should_delete_product() { // Arrange var command = new DeleteProduct { Id = 1 }; var entity = new Product { Id = 1, Description = "test1", Name = "test1" }; var fakeRepo = new Mock <IProductRepository>(); fakeRepo.Setup(m => m.Find(entity.Id)).Returns(entity); fakeRepo.Setup(m => m.Delete(It.IsAny <Product>())).Returns(1); // Act var res = Task.Run(() => new DeleteProductHandler(fakeRepo.Object, _mapper).Handle(command, default)).Result; // Assert fakeRepo.Verify(x => x.Delete(It.IsAny <Product>()), Times.Once()); fakeRepo.Verify(x => x.Find(entity.Id), Times.Once()); Assert.Equal(entity, res); }
public void DeleteProduct_Action_Fails() { // Arrange var productDto = TestHelper.ProductDto(); GenericServiceResponse <bool> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.ProductService.DeleteProduct(productDto)).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new DeleteProduct <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(productDto); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsFalse(result.Success); }
public void Any(DeleteProduct request) { using (var db = DbFactory.OpenDbConnection()) { db.Delete(request.Product); } }
public async Task SubcribeProductDeleted( DeleteProduct command, [FromServices] IMediator mediator, CancellationToken cancellationToken) { await mediator.Send(command, cancellationToken); }
private void DeleteBtn_Click(object sender, EventArgs e) { int index = dataGridView.SelectedCells[0].RowIndex; int productId = 0; bool check = Int32.TryParse(dataGridView[0, index] .Value.ToString(), out productId); if (!check) { return; } if (MessageBox.Show(Resources.RemoveQuestion, Resources.AcceptRemoveText, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } Id = productId; DeleteProduct.Invoke(sender, EventArgs.Empty); UpdateDataGridView(); Id = 0; }
public HttpResponseMessage isDeleteProduct(DeleteProduct deleteProduct) { //string result = ""; BooleanMessage bm = new BooleanMessage(); Business business = new Business(); try { bm = business.isDeleteProduct(deleteProduct); } catch (Exception ex) { business.addErrorLog("WebApi", "isDeleteProduct", ex.Message); //Utility.ErrorMessageToLogFile(ex); //throw; } string result = JsonConvert.SerializeObject(bm); return(new HttpResponseMessage() { Content = new StringContent(result) }); }
static void CreateWindow() { DeleteProduct window = EditorWindow.GetWindow(typeof(DeleteProduct), true, "Deletar Produto") as DeleteProduct; window.minSize = new Vector2(300f, 500f); window.maxSize = new Vector2(300f, 500f); }
public ProductController(CreateProduct createProduct, DeleteProduct deleteProduct, IProductRepository productRepository, IUnitOfWork uow, IMapper mapper) { _createProduct = createProduct; _deleteProduct = deleteProduct; _productRepository = productRepository; _uow = uow; _mapper = mapper; }
public void DeleteProduct_ThrowsWebServiceException_WhenCatalogNumberIsNotProvided() { var deleteProduct = new DeleteProduct(); var client = CreateClient(); Assert.ThrowsAsync <WebServiceException>(() => client.DeleteAsync(deleteProduct)); }
public IActionResult Delete(Guid productID) { DeleteProduct selectedProduct = _productRepository.Delete(productID); selectedProduct.ProductID = productID; return(RedirectToAction("DeleteProduct", selectedProduct)); }
public AdminProductsBlazorService(GetProducts getProducts, GetProduct getProduct, CreateProduct createProduct, DeleteProduct deleteProduct, UpdateProduct updateProduct) { _getProducts = getProducts; _getProduct = getProduct; _createProduct = createProduct; _deleteProduct = deleteProduct; _updateProduct = updateProduct; }
//DELETE : /api/products/{id} public async Task <ActionResult> Delete([FromBody] DeleteProduct command) { await DispatchAsync(command); _logger.LogInfo($"Product with id: {command.ProductId} removed."); return(NoContent()); }
public async Task DeleteProduct([FromServices] DeleteProduct deleteProduct, int id) { var images = await deleteProduct.Do(id); foreach (var i in images) { _fileManager.DeleteImage(rootPath, i); } }
public async Task <IActionResult> DeleteProduct([FromServices] DeleteProduct deleteProduct, int productId) { if (await deleteProduct.Do(productId) > 0) { return(Ok()); } return(BadRequest()); }
public IActionResult Delete(string id) { DeleteProduct deleteProduct = new DeleteProduct { ProductId = new Guid(id) }; _broker.Dispatch(deleteProduct); return(Ok()); }
public void DelProd(DeleteProduct prod) { Cart cart = db.Cart.SingleOrDefault(q => q.cartid == prod.cartid && q.productid == prod.productid); if (cart != null) { db.Cart.Remove(cart); db.SaveChangesAsync(); } }
public async Task GivenExistingProduct_WhenDeleteProductCommandSent_ThenProductDeleted() { var command = new DeleteProduct(Guid.NewGuid()); repository.ExistsAsync(command.ProductId).Returns(true); await handler.HandleAsync(command); await repository.Received().DeleteAsync(Arg.Any <AggregateId>()); }
public void TearDown() { using (IDbConnection dbConnection = new SqliteConnectionFactory().Create()) { var createProduct = new DeleteProduct(); dbConnection.Execute(createProduct.All()); var dropProductTable = new DropProductTable(); dbConnection.Execute(dropProductTable.Query()); } }
public async Task GivenNonExistingProduct_WhenDeleteProductCommandSent_ThenExceptionThrown() { var command = new DeleteProduct(Guid.NewGuid()); repository.ExistsAsync(command.ProductId).Returns(false); var exception = await Record.ExceptionAsync(async() => await handler.HandleAsync(command)); exception.Should().NotBeNull(); exception.Should().BeOfType <ProductNotFoundException>(); }
public async Task <IActionResult> OnPostDeleteAsync(Guid id) { var command = new DeleteProduct { AggregateRootId = id }; await _dispatcher.SendAsync(command); return(RedirectToPage()); }
public async Task<object> DeleteAsync(DeleteProduct request) { var product = (await _productsRepository.GetByIdsAsync(new int[] { request.CatalogNumber })).FirstOrDefault(); if (product == null) { throw HttpError.NotFound($"Product with Catalog Number:{request.CatalogNumber} does not exist."); } await _productsRepository.DeleteAsync(product.CatalogNumber); return new DeleteProductResponse(); }
private void DgvProducts_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { if (e.ColumnIndex == 5) { ProductSelected?.Invoke(this, int.Parse(dgvProducts[0, e.RowIndex].Value.ToString())); PopulateInputControlsFromGrid(e.RowIndex); } else if (e.ColumnIndex == 6) { DeleteProduct?.Invoke(this, int.Parse(dgvProducts[0, e.RowIndex].Value.ToString())); } }
public IApiResult Delete(DeleteProduct operation) { var result = operation.ExecuteAsync().Result; if (result is ValidationsOutput) { return new ApiResult<List<ValidationItem>>() { Data = ((ValidationsOutput)result).Errors }; } else { return new ApiResult<object>() { Status = ApiResult<object>.ApiStatus.Success }; } }
private void btnDelete_Click(object sender, EventArgs e) { removeAllManagamentControls(); switch (this.Mantenimiento) { case "Users": DeleteUser deleteUser = new DeleteUser(); Parent.Controls.Add(deleteUser); break; case "Clients": DeleteClient deleteClient = new DeleteClient(); Parent.Controls.Add(deleteClient); break; case "States": DeleteState deleteState = new DeleteState(); Parent.Controls.Add(deleteState); break; case "PaymentMethods": DeletePaymentMethod deletePayment = new DeletePaymentMethod(); Parent.Controls.Add(deletePayment); break; case "MaterialTypes": DeleteMaterialType deleteMaterialType = new DeleteMaterialType(); Parent.Controls.Add(deleteMaterialType); break; case "Materials": DeleteMaterial deleteMaterial = new DeleteMaterial(); Parent.Controls.Add(deleteMaterial); break; case "ProductTypes": DeleteProductType deleteProductType = new DeleteProductType(); Parent.Controls.Add(deleteProductType); break; case "Products": DeleteProduct deleteProduct = new DeleteProduct(); Parent.Controls.Add(deleteProduct); break; case "Providers": DeleteProvider delP = new DeleteProvider(); Parent.Controls.Add(delP); break; } }
private void buttonSelectDelete_Click(object sender, EventArgs e) { if (isCategorySelected) { DeleteCategory deleteCategory = new DeleteCategory(); deleteCategory.Show(); } else { DeleteProduct deleteProduct = new DeleteProduct(); deleteProduct.Show(); } }
public async Task <IActionResult> Delete(DeleteProduct request) { try { var result = await _mediator.Send(request); return(new OkObjectResult(result)); } catch (Exception ex) { return(LogExceptionHelper.CreateApiError(ex, _logger)); } }
public object Delete(DeleteProduct request) { if (Request.Headers["Authorization"] == null || !JsonWebToken.Decode(Request.Headers["Authorization"], iuserservice)) { return(new HttpError(HttpStatusCode.Forbidden, "Invalid token")); } if (request.Id?.Length != 24) { return(new HttpError(HttpStatusCode.BadRequest, "Bad Request")); } var result = iproductservice.DeleteProduct(request.Id); return(!result.Success ? StatusCode(result) : null); }
//deletes a product public HttpResult Delete(DeleteProduct request) { var domainObject = ProductRepository.GetById(request.Id); if (domainObject == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; } else { ProductRepository.Delete(request.Id); Response.StatusCode = (int)HttpStatusCode.NoContent; } return(null); }
public void DeleteProduct_DoesNotThrow_WhenCatalogNumberIsProvided(int productId) { //Arrange var client = CreateClient(); var deleteProduct = new DeleteProduct { CatalogNumber = productId }; //Act var deleteProductTask = client.DeleteAsync(deleteProduct); //Assert Assert.DoesNotThrowAsync(async() => await deleteProductTask); }
public Task Handle(object command) { return(command switch { Create cmd => HandleCreate(cmd), UpdateProduct cmd => HandleUpdate(cmd.Id, c => c.UpdateProductName(cmd.Name)), ChangeBrand cmd => HandleUpdateAsync(cmd.Id, async c => await UpdateBrandAsync(c, cmd.BrandId)), ChangeProductType cmd => HandleUpdateAsync(cmd.Id, async c => await UpdateProductTypeAsync(c, cmd.ProductTypeId)), ChangeSize cmd => HandleUpdateAsync(cmd.Id, async c => await UpdateSizeAsync(c, cmd.SizeId)), DeleteProduct cmd => HandleUpdateAsync(cmd.Id, _ => _repository.RemoveAsync(cmd.Id)), _ => Task.CompletedTask });