public async void Login_NOk() { try { SqliteConnection.Open(); //insert user on database IActionResult saveResult = SaveUser(); //Arrange ILoginService loginService = GetLoginService(); LoginController controller = new LoginController(loginService); DTO.User user = new DTO.User() { Email = "*****@*****.**", Password = "******" }; //Act IActionResult result = await controller.Login(user); //Assert Assert.True(result is BadRequestObjectResult); } finally { SqliteConnection.Close(); } }
public void Put_User_Ok() { try { SqliteConnection.Open(); IActionResult saveResult = SaveUser(); //Update user using (IRepository <Models.User> repository = GetRepository <Models.User>()) { UserController controller = new UserController(repository); //Act DTO.User user = ((OkObjectResult)saveResult).Value as DTO.User; //Set password because save API not returns it user.Password = "******"; user.Email = "*****@*****.**"; IActionResult result = controller.Update(user); //Assert Assert.True(saveResult is OkObjectResult); Assert.True(result is OkResult); } } finally { SqliteConnection.Close(); } }
/// <summary> /// Method to save User using the Controller /// </summary> /// <returns>Post IActionResult</returns> private IActionResult SaveUser() { using (IRepository <Models.User> repository = GetRepository <Models.User>()) { UserController controller = new UserController(repository); DTO.User user = GetDTOUser(); return(controller.Save(user)); } }
/// <summary> /// Method to save User using the Controller /// </summary> /// <returns>Post IActionResult</returns> private IActionResult SaveUser() { using (IRepository <Model.User> repository = GetRepository <Model.User>()) { UserController controller = new UserController(repository); DTO.User user = new DTO.User() { Name = "Testing User", Email = "*****@*****.**", Password = "******" }; return(controller.Save(user)); } }
public IActionResult Remove([FromBody] DTO.User user) { try { _repository.Remove(new Models.User(user, true)); return(Ok()); } catch (ArgumentException ex) { return(BadRequest(ex)); } catch (Exception ex) { return(new UnprocessableEntityObjectResult(ex.Message)); } }
public async Task <IActionResult> Login(DTO.User user) { try { Model.Token token = await _loginService.DoLogin(new Model.User(user.Email, user.Password)); if (token == null) { return(BadRequest(new { type = "ERROR", message = "Usuário ou senha incorretos." })); } else { return(Ok(token)); } } catch (Exception ex) { return(new UnprocessableEntityObjectResult(ex.Message)); } }
public void Save_User_Name_NOk() { try { SqliteConnection.Open(); using (IRepository <Models.User> repository = GetRepository <Models.User>()) { UserController controller = new UserController(repository); DTO.User user = GetDTOUser(); user.Name = null; IActionResult result = controller.Save(user); Assert.True(result is BadRequestObjectResult); } } finally { SqliteConnection.Close(); } }