public async Task InsertProductCategory_InvokreRepositoryAndClearCache() { //var collectonMock = new Mock<IMongoCollection<Product>>(); //_productRepositoryMock.Setup(p => p.Collection).Returns(collectonMock.Object); await _productCategoryService.InsertProductCategory(new ProductCategory(), "id"); //TODO //collectonMock.Verify(c => c.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(), It.IsAny<UpdateDefinition<Product>>(), null, default(CancellationToken)), Times.Once); _mediatorMock.Verify(c => c.Publish(It.IsAny <EntityInserted <ProductCategory> >(), default(CancellationToken)), Times.Once); _casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny <string>(), true), Times.Exactly(2)); }
public ActionResult Edit(ProductCategoryModel model) { try { using (ProductCategoryService service = new ProductCategoryService()) { if (ModelState.IsValid) { bool isNew = false; long res = 0; if (model.CATEGORY_ID_HIDDEN == 0) { isNew = true; res = service.InsertProductCategory(model); JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet); return(result); } else { isNew = false; res = service.UpdateProductCategory(model); JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet); return(result); } } else { var ErrorMessages = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); } return(new EmptyResult()); } } catch (Exception ex) { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; System.Web.HttpContext.Current.Session["ERROR"] = ex; return(new EmptyResult()); } }