public void RegisterTest2() { UserService target = CreateNewUserService(); UserRegisterSP p = new UserRegisterSP(); p.UserName = "******"; p.FirstName = "fName"; p.LastName = "lName"; p.Password = "******"; p.ConfirmPassword = p.Password; p.Email = "*****@*****.**"; p.PhoneNumber = TestUtils.RandomUtils.RandomPhoneNumber(); //p.membershipAreaID = 0; p.DefaultRoleID = (long)EntityEnums.RoleEnum.Patient; try { target.Register(p); throw new Exception("Test failed because of duplicate username couldn't be found in database"); } catch (BRException ex) { Assert.AreEqual(1, ex.RuleErrors.Count); Assert.AreEqual(BusinessErrorStrings.User.UserName_DuplicateUserName, ex.RuleErrors[0].ErrorDescription); // test success; } catch (Exception) { throw; } }
public void RegisterTest() { UserService target = CreateNewUserService(); UserRegisterSP p = new UserRegisterSP(); p.UserName = TestUtils.RandomUtils.RandomUserName(); p.FirstName = TestUtils.RandomUtils.RandomString(100); p.LastName = TestUtils.RandomUtils.RandomString(100); p.Password = TestUtils.RandomUtils.RandomString(64); p.ConfirmPassword = p.Password; p.Email = TestUtils.RandomUtils.RandomEmail(); p.PhoneNumber = TestUtils.RandomUtils.RandomPhoneNumber(); //p.membershipAreaID = 0; p.DefaultRoleID = (long)EntityEnums.RoleEnum.Patient; target.Register(p); User u = (User)target.GetByUserNameT(p.UserName); Assert.AreEqual(p.UserName.ToLower(), u.UserName); Assert.AreEqual(p.Email.ToLower(), u.Email); UserInRoleService uInRoleService = (UserInRoleService)EntityFactory.GetEntityServiceByName(vUserInRole.EntityName, ""); var count = uInRoleService.GetCount(new FilterExpression(new Filter(vUserInRole.ColumnNames.UserID, u.UserID))); Assert.AreEqual(1, count, "UserInRole should have 1 default role"); // we expect that user be in one of the assigned roles TestUtils.Access.SetPrivateStaticField(typeof(FWUtils), "_SecurityUtils", new SecurityUtilsFake(u.UserID)); var ulService = User_LanguageEN.GetService(); var count2 = uInRoleService.GetCount(new FilterExpression(new Filter(vUser_Language.ColumnNames.UserID, u.UserID))); Assert.AreEqual(1, count2, "User_Language should have 1 default language"); // we expect that user be in one of the assigned roles }
public bool Register(UserRegisterSP p, BusinessRuleErrorList errors, bool throwIfException) { if (p.Password != p.ConfirmPassword) { errors.Add(vUser.ColumnNames.PasswordHash, BusinessErrorStrings.User.PasswordAndConfirmPasswordDoesntMatch); } ValidatePassword(p.Password, errors, false); ValidateUserName(p.UserName, null, errors, RuleFunctionSEnum.Insert, false); ValidateEmail(p.Email, null, errors, RuleFunctionSEnum.Insert, false); ValidatePhoneNumber(p.PhoneNumber, null, false, errors, RuleFunctionSEnum.Insert, false); if (errors.Count > 0 && throwIfException) { throw new BRException(errors); } return(errors.Count == 0); }