public async Task EditUserTest() { var result = new Tuple <bool, string>(true, "Usr/1"); var userMod = new UserModMsg { EmployeeId = "EP001", FirstName = "F1", LastName = "L2", Id = "Usr/1" }; var pmUser = new PMUser { EmployeeId = userMod.EmployeeId, FirstName = userMod.FirstName, LastName = userMod.LastName }; var mockUserRepo = new Mock <IUserRepo>(); var mockProjectTaskRepo = new Mock <IProjectTaskRepo>(); var logger = createUserLogger(); mockUserRepo.Setup(usrRepo => usrRepo.EditUser(It.IsAny <PMUser>())) .Returns(Task.FromResult(result)); var mockMapper = new Mock <IMapper>(); mockMapper.Setup(map => map.Map <PMUser>(It.IsAny <UserModMsg>())).Returns(pmUser); var userService = new UserService(mockUserRepo.Object, mockProjectTaskRepo.Object, logger, mockMapper.Object); var modResult = await userService.Edit(userMod); Assert.True(modResult.Item1); Assert.Equal("Usr/1", modResult.Item2); }
public async Task <ActionResult <bool> > Put([FromBody] UserModMsg userMod) { if (userMod == null) { ModelState.AddModelError("ParameterEmpty", "Input parameter are all empty"); return(BadRequest(ModelState)); } var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(userMod); var validationResults = new List <ValidationResult>(); if (!Validator.TryValidateObject(userMod, validationContext, validationResults)) { return(BadRequest(ModelState)); } var result = await userService.Edit(userMod); if (result.Item1) { return(Accepted()); } else { return(StatusCode(500, "Unable to edit user")); } }
public async Task <Tuple <bool, string> > Edit(UserModMsg userMod) { var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(userMod); var validationResults = new List <ValidationResult>(); if (Validator.TryValidateObject(userMod, validationContext, validationResults)) { var pmUser = mapper.Map <PMUser>(userMod); return(await userRepo.EditUser(pmUser)); } return(new Tuple <bool, string>(false, "")); }
public void GetterSetterTest() { var userMsg = new UserModMsg { EmployeeId = "E001", FirstName = "F1", LastName = "L1" }; Assert.Equal("E001", userMsg.EmployeeId); Assert.Equal("F1", userMsg.FirstName); Assert.Equal("L1", userMsg.LastName); }
public async Task EditUserBadRequestValidationError() { var usrModMsg = new UserModMsg { EmployeeId = "EP001", FirstName = "F1", LastName = "L2" }; var mockUserService = new Mock <IUserService>(); var userLogger = createUserLogger(); var usrController = new UserController(mockUserService.Object, userLogger); var actionResult = (await usrController.Put(usrModMsg)).Result as BadRequestObjectResult; Assert.NotNull(actionResult); Assert.Equal(400, actionResult.StatusCode); }
public async Task EditUser() { var mockUserService = new Mock <IUserService>(); var usrModMsg = new UserModMsg { EmployeeId = "EP001", FirstName = "F1", LastName = "L2", Id = "Usr/1" }; mockUserService.Setup(usr => usr.Edit(It.IsAny <UserModMsg>())) .Returns(Task.FromResult(new Tuple <bool, string>(true, "Usr/1"))); var userLogger = createUserLogger(); var usrController = new UserController(mockUserService.Object, userLogger); var actionResult = (await usrController.Put(usrModMsg)).Result as AcceptedResult; Assert.NotNull(actionResult); Assert.Equal(202, actionResult.StatusCode); }