public async Task SignUp_ReturnProblemObjectResult_WhenCreateNewUserFailed() { //Arrange var userSignUpResource = new UserSignUpResource(); var expectedErrorMessage = "Sign up error"; _mockService.Setup(service => service.FindUserByEmail(It.IsAny <string>())) .ReturnsAsync((User)null); _mockService.Setup(service => service.FindUserByUsername(It.IsAny <string>())) .ReturnsAsync((User)null); _mockService.Setup(service => service.CreateNewUser(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(false); var controller = new AuthController(_mapper, _mockService.Object); //Act var actionResult = await controller.SignUp(userSignUpResource); var objectResult = actionResult as ObjectResult; var errorMessage = objectResult.Value; //Assert Assert.IsType <ObjectResult>(actionResult); Assert.Equal(500, objectResult.StatusCode); Assert.Equal(expectedErrorMessage, errorMessage); }
public async void UserShouldBeCreatedSuccessfullyFromUserResource() { // Arrange UserSignUpResource userSignUpResource = new UserSignUpResource { Email = "*****@*****.**", FirstName = "Thomas", LastName = "Test", Password = "******", Address = new SaveAddressResource() { City = "Vejle", Zipcode = "7100", CountryCode = "dk", StreetName = "Paradisæblevej", StreetNumber = "13" } }; // Act var result = await _controller.SignUp(userSignUpResource); // Assert Assert.NotNull(result); Assert.Equal(_controller.Created(string.Empty, string.Empty), result); }
public IActionResult SignUp(UserSignUpResource resource) { var userId = Guid.NewGuid(); _authService.SignUpAsync(userId, resource.Email, resource.Password, resource.Role); return(Ok()); }
public async Task <IActionResult> SignUp() { UserSignUpResource userSignUpResource = new UserSignUpResource { OutputHandler = new OutputHandler { IsErrorOccured = false } }; return(View(userSignUpResource)); }
public async Task <IActionResult> SignUp(UserSignUpResource userSignUpResource) { var user = _mapper.Map <UserSignUpResource, User>(userSignUpResource); var userCreateResult = await _userManager.CreateAsync(user, userSignUpResource.Password); if (userCreateResult.Succeeded) { return(Created(string.Empty, string.Empty)); } return(Problem(userCreateResult.Errors.First().Description, null, 500)); }
public async Task <IActionResult> SignUp(UserSignUpResource userSignUpResource) { var output = await _authenticationService.SignUp(userSignUpResource); if (output.IsErrorOccured) { return(BadRequest(output)); } else { return(Ok(output)); } }
public async Task <IActionResult> SignUp([FromBody] UserSignUpResource userSignUpResource) { //var user = _mapper.Map<UserSignUpResource, User>(userSignUpResource); var user = _mapper.Map <User>(userSignUpResource); Console.WriteLine($"userName: {user.UserName}"); var userCreateResult = await _userManager.CreateAsync(user, userSignUpResource.Password); if (userCreateResult.Succeeded) { return(Created(string.Empty, string.Empty)); } return(Problem(userCreateResult.Errors.ToString(), null, 500)); }
public async Task <OutputHandler> SignUp(UserSignUpResource userSignUpResource) { var user = new AutoMapper <UserSignUpResource, User>().MapToObject(userSignUpResource); userSignUpResource.Email = user.Email; var userCreateResult = await _userManager.CreateAsync(user, userSignUpResource.Password); if (userCreateResult.Succeeded) { return(new OutputHandler { IsErrorOccured = false }); } return(new OutputHandler { IsErrorOccured = true, Message = userCreateResult.Errors.First().Description }); // Problem(userCreateResult.Errors.First().Description, null, 500); }
public async Task <IActionResult> SignUp(UserSignUpResource userSignUpResource) { User userSignIn = new User(); userSignIn.Email = userSignUpResource.Email; userSignIn.Name = userSignUpResource.Name; userSignIn.UserName = userSignUpResource.Email; userSignIn.State = userSignUpResource.State; var newUser = await _userService.Register(userSignIn, userSignUpResource.Password, userSignUpResource.UserRoles); if (newUser == null) { return(BadRequest(new { Status = "502", Message = "User already exists" })); } else { return(Ok(userSignIn)); } }
public async Task <IActionResult> SignUp(UserSignUpResource userSignUpResource) { try { var user = _mapper.Map <UserSignUpResource, User>(userSignUpResource); var userCreateResult = await _userManager.CreateAsync(user, userSignUpResource.Password); if (userCreateResult.Succeeded) { return(Created(string.Empty, string.Empty)); } return(Problem(userCreateResult.Errors.First().Description, null, 500)); } catch (Exception ex) { Log.Logger.Error(ex, "AuthController > SignUp - Erro Interno"); return(InternalServerError()); } }
public async Task SignUp_ReturnConflictObjectResult_WhenUsernameIsTaken() { //Arrange var userSignUpResource = new UserSignUpResource(); var expectedErrorMessage = "Username has already been taken"; _mockService.Setup(service => service.FindUserByEmail(It.IsAny <string>())) .ReturnsAsync((User)null); _mockService.Setup(service => service.FindUserByUsername(It.IsAny <string>())) .ReturnsAsync(new User()); var controller = new AuthController(_mapper, _mockService.Object); //Act var actionResult = await controller.SignUp(userSignUpResource); var objectResult = actionResult as ConflictObjectResult; var errorMessage = objectResult.Value; //Assert Assert.IsType <ConflictObjectResult>(actionResult); Assert.Equal(expectedErrorMessage, errorMessage); }
public async Task <IActionResult> SignUp(UserSignUpResource userSignUpResource, string roleName = "client") { if (await _authService.FindUserByEmail(userSignUpResource.Email) != null) { return(Conflict("Email has already been taken")); } if (await _authService.FindUserByUsername(userSignUpResource.UserName) != null) { return(Conflict("Username has already been taken")); } var user = _mapper.Map <UserSignUpResource, User>(userSignUpResource); bool IsSuccess = await _authService.CreateNewUser(user, userSignUpResource.Password, roleName); if (!IsSuccess) { return(StatusCode(500, "Sign up error")); } return(Created(string.Empty, "Sign up success")); }
public async Task <IActionResult> SignUp(UserSignUpResource signUpCredentials) { var requestUrl = $"{BaseUrl}{apiUriAccount}/SignUp"; OutputHandler outputHandler = new OutputHandler(); //Get Sermons using (var client = new HttpClient()) { signUpCredentials.Username = signUpCredentials.Email; client.BaseAddress = new Uri(requestUrl); HttpResponseMessage response = await client.PostAsJsonAsync(requestUrl, signUpCredentials); if (response.StatusCode == HttpStatusCode.OK) { outputHandler = await response.Content.ReadAsAsync <OutputHandler>(); if (!outputHandler.IsErrorOccured) { return(RedirectToAction("Login", "Account")); } } else { outputHandler = await response.Content.ReadAsAsync <OutputHandler>(); }; }; UserSignUpResource userSignUpResource = new UserSignUpResource { OutputHandler = new OutputHandler { IsErrorOccured = true, Message = outputHandler.Message } }; return(View(userSignUpResource)); }
public async Task SignUp_ReturnCreatedResult_WhenCreateNewUserIsSuccess() { //Arrange var userSignUpResource = new UserSignUpResource(); var expectedValue = "Sign up success"; _mockService.Setup(service => service.FindUserByEmail(It.IsAny <string>())) .ReturnsAsync((User)null); _mockService.Setup(service => service.FindUserByUsername(It.IsAny <string>())) .ReturnsAsync((User)null); _mockService.Setup(service => service.CreateNewUser(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(true); var controller = new AuthController(_mapper, _mockService.Object); //Act var actionResult = await controller.SignUp(userSignUpResource); var objectResult = actionResult as CreatedResult; var value = objectResult.Value; //Assert Assert.IsType <CreatedResult>(actionResult); Assert.Equal(expectedValue, value); }