public void DeleteProductShouldRemoveProductFromDb() { var options = new DbContextOptionsBuilder <BookStoreDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; // var dbContext = new BookStoreDbContext(options); var genreServices = new Mock <IGenreService>(); var _searchService = new Mock <ISearchService>(); var _userServices = new Mock <IUserServices>(); var productServices = new ProductServices(dbContext, genreServices.Object, _searchService.Object, _userServices.Object); List <Product> productsList = new List <Product>(); var testProduct1 = new Product() { Id = 1, Title = "Бай Ганьо1", ProductTypes = ProductTypes.Book, Price = 153.03M, Quantity = 1 }; var testProduct2 = new Product() { Id = 2, Title = "Бай Ганьо2", ProductTypes = ProductTypes.Book, Price = 175.03M, Quantity = 1000 }; productsList.Add(testProduct1); productsList.Add(testProduct2); dbContext.Products.AddRange(productsList); dbContext.SaveChanges(); var fullListOfProducts = dbContext.Products.ToList().Count; var getProductFromDb = dbContext.Products.FirstOrDefault(); var productId = getProductFromDb.Id; productServices.Delete(productId); var getNextProductFromDb = dbContext.Products.FirstOrDefault().Id; productServices.Delete(getNextProductFromDb); var getNullProductFromDb = dbContext.Products.ToList().Count == 0; Assert.Equal(2, fullListOfProducts); Assert.True(getNullProductFromDb); }
public void ThatAProductCanBeDeleted() { var product = GetProduct(); ProductServices.Delete(product); Assert.IsNull(ProductServices.Products.SingleOrDefault(x => x.Name == product.Name)); }
public async Task Delete_InvalidProduct_ReturnError(int id) { // ===== Arrange ===== var dbName = Guid.NewGuid().ToString(); var context = BuildContext(dbName); var mapper = BuildMap(); var httpContext = new Mock <IHttpContextAccessor>(); var http = new DefaultHttpContext(); httpContext.Setup(_ => _.HttpContext).Returns(http); await Generate_Product_Data(context, mapper, httpContext.Object); var data = await context.Product.Where(_ => _.Id == id).FirstOrDefaultAsync(); // ===== Act ====== var actContext = BuildContext(dbName); var service = new ProductServices(actContext, mapper, httpContext.Object); var result = await service.Delete(id); // ===== Assert ===== // Expected Exception }
public ActionResult Delete(int id) { ProductServices pds = new ProductServices(); pds.Delete(id); return(Content("OK")); }
public void ThatAProductWithOnlyRoutesCanBeDeleted() { var product = GetProduct(); product.RemoveRoute(product.Routes.First()); ProductServices.Delete(product); product = ProductServices.Products.SingleOrDefault(x => x.Name == ProductTestFixtures.ProductName); Assert.IsNull(product); }
public void ThatProductWithSubstancesAndRoutesCanBeDeleted() { var product = GetProduct(); Assert.IsTrue(product.Substances.Any(), "substances were not added"); ProductServices.Delete(product); product = ProductServices.Products.SingleOrDefault(x => x.Name == ProductTestFixtures.ProductName); Assert.IsTrue(product == null, "product was not deleted"); }
private void DeleteProduct() { if (productServices.Delete(Convert.ToInt32(txtID.Text))) { MessageBox.Show("Producto eliminado correctamente"); } else { MessageBox.Show("El producto no pudo ser eliminado"); } }
public void ReturnSuccessIsTrueValueWhenCanDeleteProduct() { IsolateController(); var product = Isolate.Fake.Instance <IProduct>(); Isolate.Fake.StaticMethods(typeof(ProductServices)); Isolate.WhenCalled(() => ProductServices.Delete(product)).IgnoreCall(); var result = _controller.DeleteProduct(Guid.NewGuid().ToString()); Assert.IsTrue(ActionResultParser.GetSuccessValue(result)); }
public ActionResult DeleteConfirmed(int id) { try { // TODO: Add delete logic here productServices.Delete(id); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult DeleteProduct(String id) { Boolean success; var message = String.Empty; try { var product = ProductServices.Get(Guid.Parse(id)); ProductServices.Delete(product); success = true; } catch (Exception e) { success = false; message = e.ToString(); } return(this.Direct(new { success, message })); }
public async Task <ActionResult> DeleteIds(string ids) { try { var result = await _productServices.Delete(ids); if (result.Status == Status.ok) { return(Json("ok")); } else { return(Json(result.Message)); } } catch { return(View()); } }
public ActionResult DeleteConfirmed(int id) { try { Db db = new Db(DbServices.ConnectionString); ProductServices.Delete(CurrentUser.Id, id, db); TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "DeleteConfirmed"); // return RedirectToAction("Index"); } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } // return View(product); return(RedirectToAction("Index")); }
public void Delete(int id) { try { UserProfile _user = AuthManager.CurrentUser; if (_user == null) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } ProductServices.Delete(id); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }
public async Task Delete_ValidProduct_ReturnDataWithSaveChanged(int id) { // ===== Arrange ===== var dbName = Guid.NewGuid().ToString(); var context = BuildContext(dbName); var mapper = BuildMap(); var httpContext = new Mock <IHttpContextAccessor>(); var http = new DefaultHttpContext(); httpContext.Setup(_ => _.HttpContext).Returns(http); await Generate_Product_Data(context, mapper, httpContext.Object); var result = new ServiceResponse <ProductDTO>(); // ===== Act ====== var actContext = BuildContext(dbName); var service = new ProductServices(actContext, mapper, httpContext.Object); result = await service.Delete(id); // ===== Assert ===== var assContext = BuildContext(dbName); Assert.IsNotNull(result.Data); Assert.IsTrue(result.IsSuccess); var deleteData = await assContext.Product.Where(_ => _.Id == id).FirstOrDefaultAsync(); Assert.IsNull(deleteData); var count = await assContext.Product.CountAsync(); Assert.AreEqual(14, count); }
public ActionResult Delete(int id) { productServices.Delete(id); return(RedirectToAction("ProductsList")); }
public void DeleteProduct(Product product) { ProductServices.Delete(product); SearchProduct(); }
public IActionResult DeleteConfirmed(int?id) { productServices.Delete(id); return(RedirectToAction(nameof(MyOffers))); }