public ActionResult Delete(int[] ids) { var list = ProductCategoryService.FindList(o => ids.Contains(o.Id)); var re = ProductCategoryService.Delete(list); #region 操作日志 foreach (var item in list) { var msg = LogEngine.CompareModelToLog <ProductCategory>(LogModule.种类管理, null, item); new LogEngine().WriteDelete(msg, LogModule.种类管理); } #endregion return(new JsonNetResult(re)); }
public void Delete_IdNonExisting_ReturnsNull() { //Arrange int nonExistingId = 12; ProductCategory expected = null; Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); productCategoryRepository.Setup(repo => repo.Delete(nonExistingId)). Returns(expected); IProductCategoryService productCategoryService = new ProductCategoryService(productCategoryRepository.Object); //Act ProductCategory actual = productCategoryService.Delete(nonExistingId); //Assert Assert.Equal(expected, actual); }
public async void Delete() { var mock = new ServiceMockFacade <IProductCategoryRepository>(); var model = new ApiProductCategoryRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ProductCategoryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductCategoryMapperMock, mock.DALMapperMockFactory.DALProductCategoryMapperMock, mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock, mock.DALMapperMockFactory.DALProductSubcategoryMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
private string Delete(HttpContext contex) { //实例化BLL中的服务类,用于调用 ProductCategoryService service = new ProductCategoryService(); string id = contex.Request["deleteid"]; //初始值为0,成功后为10000 int code = 0; if (service.Delete(id)) { code = 10000; } //设置匿名变量,存储执行是否成功的消息,序列化返回到Ajax的result var resultObj = new { Success = code }; return(Newtonsoft.Json.JsonConvert.SerializeObject(resultObj)); }
public void Delete_IdExisting_ReturnsDeletedProductCategoryWithSpecifiedId() { //Arrange int existingId = 12; ProductCategory expected = new ProductCategory { Id = existingId, Name = "Accessories" }; Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); productCategoryRepository.Setup(repo => repo.Delete(existingId)). Returns(expected); IProductCategoryService productCategoryService = new ProductCategoryService(productCategoryRepository.Object); //Act ProductCategory actual = productCategoryService.Delete(existingId); //Assert Assert.Equal(expected, actual); }
public void ProductCategoryServiceCRUDTest() { var context = new NoodleDbContext("NoodleDb"); IProductCategoryService service = new ProductCategoryService(context); var id = Guid.NewGuid(); var productId = Guid.NewGuid(); var categoryId = Guid.NewGuid(); var record = new ProductCategory { Id = id, ProductId = productId, CategoryId = categoryId }; service.Create(record); record.CategoryId = Guid.NewGuid(); record.ProductId = Guid.NewGuid(); service.Update(record); var record2 = service.GetById(id); Assert.AreEqual(record.Id, record2.Id); Assert.AreEqual(record.CategoryId, record2.CategoryId); Assert.AreEqual(record.ProductId, record2.ProductId); service.Delete(record.Id); var record3 = service.GetById(id); Assert.IsNull(record3); }
public async Task <IActionResult> Delete(int id) { await _productCateService.Delete(id); return(Ok()); }