public void EditTest() { CreateContext(); DefaultController <ObjectMappingForTest> defaultController = new DefaultController <ObjectMappingForTest>(new FakeLogger(), new FetchDomainData <ObjectMappingForTest>(_uow), new HandlerCRUD <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >(new RepositoryAddItem <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >(_uow, context)), new HandlerCRUD <ObjectMappingForTest, EditParamOfCRUDOperation <ObjectMappingForTest> >(new RepositoryEditItem <ObjectMappingForTest, EditParamOfCRUDOperation <ObjectMappingForTest> >(_uow, context)), new HandlerCRUD <ObjectMappingForTest, DeleteParamOfCRUDOperation <ObjectMappingForTest> >(new RepositoryDeleteItem <ObjectMappingForTest, DeleteParamOfCRUDOperation <ObjectMappingForTest> >(_uow, context))); //Проверка редактирования без ID.Будет ошибка, так как нет идентификатора записи EditParamOfCRUDOperation <ObjectMappingForTest> paramQueryAdd = new EditParamOfCRUDOperation <ObjectMappingForTest>(); paramQueryAdd.Item = new ObjectMappingForTest() { IntValue = 1, IntValue2 = 1, StrValue = "1" }; var exArgumentException = Assert.ThrowsExceptionAsync <ArgumentException>(() => defaultController.Edit(paramQueryAdd)); Assert.AreEqual("Объект не найден в БД для изменения.", exArgumentException.Result.Message); //Проверка успешного изменения записи paramQueryAdd.Item = new ObjectMappingForTest() { Id = 3, IntValue = 1, IntValue2 = 1, StrValue = "1" }; JsonResult resultAdd = defaultController.Edit(paramQueryAdd).Result; BaseResultType <PrepareItemResult <ObjectMappingForTest> > resultSuccessQuery = (BaseResultType <PrepareItemResult <ObjectMappingForTest> >)resultAdd.Value; Assert.AreEqual(ResultStatus.Success, resultSuccessQuery.Status); Assert.IsNotNull(resultSuccessQuery.Data.Item); Assert.IsInstanceOfType(resultSuccessQuery.Data.Item, typeof(ObjectMappingForTest), "Вернулся тип объекта не ObjectMappingForTest после сохранения этого объекта."); Assert.AreEqual(1, ((ObjectMappingForTest)resultSuccessQuery.Data.Item).IntValue); Assert.AreEqual(1, ((ObjectMappingForTest)resultSuccessQuery.Data.Item).IntValue2); Assert.AreEqual("1", ((ObjectMappingForTest)resultSuccessQuery.Data.Item).StrValue); Assert.AreEqual(3, ((ObjectMappingForTest)resultSuccessQuery.Data.Item).Id); //Проверка запроса из БД, что запись не добавилась JsonResult result = defaultController.GetAsync(new FetchDataParameters() { CountOnPage = 10, PageNumber = 1 }).Result; BaseResultType <ResultFetchData <ObjectMappingForTest> > fetchDataResultQuery = (BaseResultType <ResultFetchData <ObjectMappingForTest> >)result.Value; Assert.AreEqual(ResultStatus.Success, fetchDataResultQuery.Status); Assert.AreEqual(3, fetchDataResultQuery.Data.TotalCountRows); ObjectMappingForTest itemFromDB = fetchDataResultQuery.Data.Items[2]; Assert.AreEqual(1, itemFromDB.IntValue); Assert.AreEqual(1, itemFromDB.IntValue2); Assert.AreEqual("1", itemFromDB.StrValue); Assert.AreEqual(3, itemFromDB.Id); }
public async override Task <BaseResultType <PrepareItemResult <TEntity> > > Execute(EditParamOfCRUDOperation <TEntity> paramOfCRUDOperation) { BaseResultType <PrepareItemResult <TEntity> > result = await _handlerCRUD.Execute(paramOfCRUDOperation); if (result.Status == ResultStatus.Success) { await _cache.UpdateAsync(result.Data.Item); } return(result); }