private UserResponse SetResponse(EditedUser model) { return(new UserResponse() { User = SetUser(model), IsValid = true }); }
public AccountManagerResponse CreateUser(EditedUser model) { UserResponse creationResult = _userManager.Create(model); SetResponse(creationResult); ProcessResponse(); return(response); }
public void Test_CreateUser_return_ok() { EditedUser user = UserValid(); Account account = new Account(userManager, token); AccountManagerResponse response = account.CreateUser(user); Assert.IsTrue(response.IsValid); }
public UserResponse Create(EditedUser model) { NonNullParametersChecker.checkObjectTypeParameter(model); ValidateNewUser(model); ProcessRequest(model); return(response); }
public void Test_CreateUser_bad() { EditedUser user = User(); Account account = new Account(userManager, token); AccountManagerResponse response = account.CreateUser(user); Assert.IsFalse(response.IsValid); Assert.AreEqual(response.StatusCode, 400); }
public void Test_Account_Create_return_Bad() { IAccount _account = new AccountMock(doNotThrowException); EditedUser model = IncorrectUser(); var controller = new AccountController(_account, responseHandler); var result = controller.CreateUser(model).GetType().Name; Assert.IsTrue(result.Contains("BadRequestObjectResult")); }
public void Create_ok_test() { IUserManager userManager = new UserManager(unitOfWork, roles); EditedUser user = UserValid(); var response = userManager.Create(user); Assert.IsTrue(response.IsValid); Assert.AreEqual(user.UserName, response.User.UserName); }
private Users SetUserModel(EditedUser model) => new Users() { Id = GenerateId(), UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, PasswordHash = PasswordHash.GetPasswordHash(model.Password) };
public void Test_Account_Create_return_Ok() { IAccount _account = new AccountMock(doNotThrowException); EditedUser model = CorrectUser(); var controller = new AccountController(_account, responseHandler); var result = controller.CreateUser(model).GetType().Name; Assert.AreEqual("OkObjectResult", result); }
private void ProcessRequest(EditedUser model) { if (response.IsValid) { Users user = SetUserModel(model); response.User = _unitOfWork.Users.Add(user); _unitOfWork.commit(); } }
public void Create_catch_exception_test() { IAccount _account = new AccountMock(throwException); EditedUser model = CorrectUser(); var controller = new AccountController(_account, responseHandler); var result = controller.CreateUser(model) as BadRequestObjectResult; var message = result.Value.GetType().Name; Assert.AreEqual(message, "Exception"); }
public UserResponse Create(EditedUser model) { UserResponse response = SetResponse(model); if (model.UserName != "UserNameTestValid") { response.IsValid = false; response.StatusCode = 400; } return(response); }
public void Create_bad_test() { IUserManager userManager = new UserManager(unitOfWork, roles); EditedUser user = UserValid(); user.UserName = "******"; var response = userManager.Create(user); Assert.IsFalse(response.IsValid); Assert.IsNull(response.User); }
private Users SetUser(EditedUser model) { return(new Users() { Id = "IdTest", UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, PasswordHash = model.Password }); }
public IActionResult CreateUser([FromBody] EditedUser model) { IActionResult response; try { response = _responseHandler.ProcessResponse(_account.CreateUser(model)); } catch (Exception e) { response = BadRequest(e); } return(response); }
public AccountManagerResponse CreateUser(EditedUser model) { if (_exception) { throw new Exception(); } AccountManagerResponse response = new AccountManagerResponse() { Token = new TokenModel() }; if (model.Email == "*****@*****.**") { response.IsValid = true; response.Token.Value = "token"; } else { response.IsValid = false; response.StatusCode = 400; } return(response); }
private void ValidateNewUser(EditedUser newUser) { ValidateNewUserName(newUser.UserName); ValidateNewUserEmail(newUser.Email); }
public void UpdateUser(EditedUser newValues) { try { using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true)) { session.BeginUpdate(); if (newValues.Id == 0) { IssueTracker issueTracker = (IssueTracker)session.Open(IssueTracker.PlaceInDatabase, 1, 1, false); User user = lookupUser(issueTracker, session); User newUser = new User(user, newValues.Email, newValues.FirstName, newValues.LastName, newValues.UserName); Placement placer = new Placement(newUser.PlacementDatabaseNumber); newUser.Persist(placer, session, true, true); issueTracker.UserSet.Add(newUser); } else { User existingUser = (User)session.Open(newValues.Id); existingUser.FirstName = newValues.FirstName; existingUser.LastName = newValues.LastName; existingUser.Email = newValues.Email; existingUser.UserName = newValues.UserName; } session.Commit(); } } catch (System.Exception ex) { this.errorLabel.Text = ex.ToString(); } }
public void InsertUser(EditedUser newValues) { newValues.CreatedBy = ""; newValues.FirstName = ""; newValues.LastName = ""; newValues.UserName = ""; newValues.Email = ""; }
public void UpdateUser(EditedUser newValues) { try { int sessionId = -1; SessionBase session = null; try { session = s_sessionPool.GetSession(out sessionId); using (var transaction = session.BeginUpdate()) { if (newValues.Id == 0) { IssueTracker issueTracker = session.AllObjects<IssueTracker>(false).FirstOrDefault(); User user = lookupUser(issueTracker, session); User newUser = new User(user, newValues.Email, newValues.FirstName, newValues.LastName, newValues.UserName); session.Persist(newUser); issueTracker.UserSet.Add(newUser); } else { User existingUser = (User)session.Open(newValues.Id); existingUser.FirstName = newValues.FirstName; existingUser.LastName = newValues.LastName; existingUser.Email = newValues.Email; existingUser.UserName = newValues.UserName; } session.Commit(); s_sharedReadOnlySession.ForceDatabaseCacheValidation(); } } catch (Exception ex) { Console.Out.WriteLine(ex.StackTrace); } finally { s_sessionPool.FreeSession(sessionId, session); } } catch (System.Exception ex) { this.errorLabel.Text = ex.ToString(); } }