public ActionResult Create(RoleActionDTO roleAction) { MethodBase method = MethodBase.GetCurrentMethod(); try { RoleAction newRoleAction = Mapper.Map <RoleAction>(roleAction); newRoleAction.IsValid = true; newRoleAction.Id = 0; var response = RoleActionRepo.Create(newRoleAction); if (response > 0) { CreateLog(Enums.Success, GetMethodCode(method), LogLevel.Information); return(Ok(response)); } else { CreateLog(Enums.BadRequest, GetMethodCode(method), LogLevel.Warning); return(BadRequest(response)); } } catch (Exception ex) { return(HandleError(ex.Message, GetMethodCode(method))); } }
public void Setup() { // Mock _configuration = new Mock <IConfiguration>(MockBehavior.Loose); _roleActionRepo = new Mock <IRoleActionRepo>(MockBehavior.Loose); _logger = new Mock <ILogger <RoleActionController> >(MockBehavior.Loose); // Mapper var config = new MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperConfig()); }); _mapper = new Mapper(config); // Config Filler <RoleAction> pFiller = new Filler <RoleAction>(); Filler <RoleActionDTO> pFillerDTO = new Filler <RoleActionDTO>(); roleAction = pFiller.Create(); roleActionDTO = pFillerDTO.Create(); // Service under test _roleActionController = new RoleActionController(_configuration.Object, _mapper, _roleActionRepo.Object, _logger.Object); }
public ActionResult Delete(RoleActionDTO roleAction) { MethodBase method = MethodBase.GetCurrentMethod(); try { if (roleAction.Id > 0) { RoleAction delRoleAction = Mapper.Map <RoleAction>(roleAction); RoleActionRepo.Delete(delRoleAction); CreateLog(Enums.Success, GetMethodCode(method), LogLevel.Information); return(Ok(true)); } else { CreateLog(Enums.BadRequest, GetMethodCode(method), LogLevel.Information); return(BadRequest()); } } catch (Exception ex) { return(HandleError(ex.Message, GetMethodCode(method))); } }