public void Validation_Email_Size() { var newUser = new NewUser(); var loopMax = 1000; var expectedMaxLength = 256; for (int i = 1; i < loopMax; i++) { newUser.Email = (i*256).randomLetters(); //works quite fast even with values as hight as 1000000 newUser.Username = "".add_RandomLetters(10); newUser.Password = "******".add_RandomLetters(20); var dateStart = DateTime.Now; var validEmail = newUser.valid_Email_Address(); Assert.IsFalse(validEmail); var validationResults = newUser.validate(); var resultsMapped = validationResults.indexed_By_MemberName(); var seconds = (DateTime.Now - dateStart).TotalSeconds; Assert.Less(seconds,1, "A email with size {0} took more than 1 sec to calculate".format(i*10)); if (i > expectedMaxLength) { Assert.AreEqual(resultsMapped["Email"].size() , 1); Assert.IsTrue (resultsMapped["Email"].contains("The field Email must be a string with a maximum length of {0}.".format(expectedMaxLength))); } } }
public void Validation_Email_Format() { var shouldFailValidation = new [] { "aaa", "bbb", "aa.bb", "aa.bb", "Abc.example.com","[email protected]", "a;[email protected]","aaa@em;ail.com", "[email protected];om","*****@*****.**", "a@[email protected]", "*****@*****.**", "*****@*****.**","A@b@[email protected]" }; var shouldPassValidation = new [] { "*****@*****.**","*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" ,"*****@*****.**", "*****@*****.**" }; Func<string,bool> validEmail = (email)=>{ var newUser = new NewUser { Email = email }; // create new user return newUser.valid_Email_Address(); }; foreach(var testEmail in shouldFailValidation ) // these should all fail Assert.IsFalse(validEmail(testEmail), "Should had failed for: {0}".format(testEmail)); foreach(var testEmail in shouldPassValidation ) // these should all work Assert.IsTrue(validEmail(testEmail), "Should had worked for: {0}".format(testEmail)); }
public static List<int> createTmUsers(this TM_UserData userData, string batchUserData) { var newUsers = new List<NewUser>(); foreach(var line in batchUserData.fix_CRLF().split_onLines()) { var newUser = new NewUser(); //return _newUser; var items = line.split(","); newUser.Username = items.size()>0 ? items[0].trim() : ""; newUser.Password = items.size()>1 ? items[1].trim() : ""; newUser.Firstname = items.size()>2 ? items[2].trim() : ""; newUser.Lastname = items.size()>3 ? items[3].trim() : ""; newUser.GroupId = items.size()>4 ? items[4].trim().toInt() : 0; //default values newUser.Company = "..."; newUser.Country = "..."; newUser.Email = "{0}@randomm.xyz".format(10.randomLetters()); newUser.Note = "(Batch user created)"; newUser.State = "..."; newUser.Title = "..."; if (newUser.validation_Failed()) { "[createTmUsers] failed validation for user data:{0}".error(newUser.toXml()); newUsers.Add(null); } else newUsers.Add(newUser); } return userData.createTmUsers(newUsers); }
public void Validation_Email_Format() { var shouldFailValidation = new [] { "aaa", "bbb", "aa.bb", "aa.bb", "a@b","[email protected]", "a;[email protected]","aaa@em;ail.com", "[email protected];om" }; var shouldPassValidation = new [] { "*****@*****.**","*****@*****.**", "*****@*****.**" }; Func<string,bool> validEmail = (email)=>{ var newUser = new NewUser { Email = email }; // create new user return newUser.validate() // validate .indexed_By_MemberName() // get dictionary with results .hasKey("Email") // see if email .isFalse(); // is not there }; foreach(var testEmail in shouldFailValidation ) // these should all fail Assert.IsFalse(validEmail(testEmail), "Should had failed for: {0}".format(testEmail)); foreach(var testEmail in shouldPassValidation ) // these should all work Assert.IsTrue(validEmail(testEmail), "Should had worked for: {0}".format(testEmail)); }
public static int createTmUser(this TM_UserData userData, NewUser newUser) { if (newUser.isNull()) return 0; // ensure the email is lowercase (will fail validation otherwise) newUser.Email = newUser.Email.lower(); //validate user against the DataContract specificed in the NewUser class if (newUser.validation_Failed()) return 0; if(newUser.UserTags.notEmpty()) foreach(var userTag in newUser.UserTags) if(userTag.validation_Failed()) return 0; // if there is a groupId provided we must check if the user has the manageUsers Priviledge if (newUser.GroupId !=0) UserRole.ManageUsers.demand(); // Check if there is already a user with the provided username or email if (newUser.Username.tmUser().notNull() || newUser.Email.tmUser_FromEmail().notNull()) { userData.logTBotActivity("User Creation Fail","Username ('{0}') or Email ('{1})already existed".format(newUser.Username, newUser.Email)); return 0; } // Create user return userData.newUser(newUser.Username, newUser.Password, newUser.Email, newUser.Firstname, newUser.Lastname, newUser.Note, newUser.Title, newUser.Company, newUser.Country, newUser.State, newUser.UserTags,newUser.GroupId); }
public static int createTmUser(this TM_UserData userData, NewUser newUser) { if (newUser.groupId !=0) // if there is a groupId provided we must check if the user has the manageUsers Priviledge UserRole.ManageUsers.demand(); if (newUser.username.inValid() || newUser.username.tmUser().notNull()) return 0; return userData.newUser(newUser.username, newUser.password, newUser.email, newUser.firstname, newUser.lastname, newUser.note, newUser.title, newUser.company, newUser.groupId); }
public void Validation_NewUser_LargeDataInFields() { var newUser = new NewUser(); // new empty user object foreach (var property in newUser.type().properties()) // populate all strings newUser.prop(property.Name, 5001.randomLetters()); // ... with a random 5001 char value var validationResults = newUser.validate(); // validate var resultsMapped = validationResults.indexed_By_MemberName(); foreach (var result in resultsMapped) // checks validation errors Assert.IsTrue(result.Value.first() .contains("The field {0} must be a string with a maximum length of".format(result.Key)) || result.Value.second().contains("The field {0} must be a string with a maximum length of".format(result.Key)) , "mappings : {0}".format(result.Value.toString())); }
public static List<int> createTmUsers(this TM_UserData userData, string batchUserData) { var newUsers = new List<NewUser>(); foreach(var line in batchUserData.fixCRLF().split_onLines()) { var newUser = new NewUser(); //return _newUser; var items = line.split(","); newUser.username = items.size()>0 ? items[0].trim() : ""; newUser.password = items.size()>1 ? items[1].trim() : ""; newUser.firstname = items.size()>2 ? items[2].trim() : ""; newUser.lastname = items.size()>3 ? items[3].trim() : ""; newUser.groupId = items.size()>4 ? items[4].trim().toInt() : 0; newUsers.Add(newUser); } return userData.createTmUsers(newUsers); }
public void Issue_826__No_lenght_constraint_on_User_Tags_SigupResponse() { var userData = new TM_UserData(); var newUser = new NewUser().with_Random_Data(); newUser.validate().asStringList().assert_Is_Empty(); var userTag_Ok = new UserTag { Key = 254.randomLetters(), Value = 254.randomLetters() }; var userTag_Fail = new UserTag { Key = 256.randomLetters(), Value = 256.randomLetters() }; userTag_Ok.validate().assert_Empty(); userTag_Fail.validate().assert_Not_Empty(); newUser.UserTags.add(userTag_Ok); userData.createTmUserResponse(newUser).UserCreated.assert_Is_Not(0); newUser.UserTags.add(userTag_Fail); userData.createTmUser(newUser).assert_Is(0); }
public void Validation_Email_Size() { var newUser = new NewUser(); var loopMax = 100; var expectedMaxLength = 50; for (int i = 1; i < loopMax; i++) { newUser.Email = (i*10).randomLetters(); //works quite fast even with values as hight as 1000000 var dateStart = DateTime.Now; var validationResults = newUser.validate(); var resultsMapped = validationResults.indexed_By_MemberName(); var seconds = (DateTime.Now - dateStart).TotalSeconds; Assert.Less(seconds,1, "A email with size {0} took more than 1 sec to calculate".format(i)); Assert.IsTrue(resultsMapped["Email"].contains("The field Email must match the regular expression '{0}'.".format(ValidationRegex.Email)), "It was {0}".format(resultsMapped["Email"].toString())); if (i > expectedMaxLength) { Assert.AreEqual(resultsMapped["Email"].size() , 2); Assert.IsTrue (resultsMapped["Email"].contains("The field Email must be a string with a maximum length of {0}.".format(expectedMaxLength))); } } }
public void Sign_Up_For_New_Account() { var ieTeamMentor = this.new_IE_TeamMentor_Hidden(); var ie = ieTeamMentor.ie; Action<NewUser> signup_For_New_Account = (newUser)=> { ie.waitForField("ctl00_ContentPlaceHolder1_UsernameBox" ).value(newUser.Username ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_PasswordBox" ).value(newUser.Password ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_RepeatPasswordBox").value(newUser.Password ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_EmailBox" ).value(newUser.Email ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_FNameBox" ).value(newUser.Firstname ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_LNameBox" ).value(newUser.Lastname ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_Company" ).value(newUser.Company ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_Title" ).value(newUser.Title ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_Country" ).value(newUser.Country ).assert_Not_Null(); ie.field ("ctl00_ContentPlaceHolder1_State" ).value(newUser.State ).assert_Not_Null(); ie.button ("Sign Up").click(); }; //create Random user var random_NewUser = new NewUser(); foreach(var name in random_NewUser.property_Values_AsStrings().keys()) random_NewUser.property(name,"!!10".add_5_RandomLetters()); random_NewUser.Email = "testUser".random_Email(); ieTeamMentor.page_Logout(); signup_For_New_Account(random_NewUser); ie.wait_For_Element_InnerText("signupMessage", "Account created successfully\r\n\r\nPlease Login").assert_Not_Null(); ie.link ("Login") .click() .assert_Not_Null(); ie.waitForField("UsernameBox") .value(random_NewUser.Username) .assert_Not_Null(); ie.field ("PasswordBox") .value(random_NewUser.Password) .assert_Not_Null(); ie.button ("<span class=ui-button-text> Login</span>").click() .assert_Not_Null(); ie.waitForLink ("Logout") .assert_Not_Null(); ie.element ("topRightMenu").innerText() .assert_Contains("Logged in as", random_NewUser.Username); ieTeamMentor.close(); }
public static int createTmUser(this TM_UserData userData, NewUser newUser) { if (newUser.isNull()) return 0; // ensure the email is lowercase (will fail validation otherwise) newUser.Email = newUser.Email.lower(); //validate user against the DataContract specificed in the NewUser class if (newUser.validation_Failed()) return 0; // if there is a groupId provided we must check if the user has the manageUsers Priviledge if (newUser.GroupId !=0) UserRole.ManageUsers.demand(); // Check if there is already a user with the provided username or email if (newUser.Username.tmUser().notNull() || newUser.Email.tmUser_FromEmail().notNull()) return 0; // Create user return userData.newUser(newUser.Username, newUser.Password, newUser.Email, newUser.Firstname, newUser.Lastname, newUser.Note, newUser.Title, newUser.Company, newUser.Country, newUser.State,newUser.GroupId); }
public int CreateUser(NewUser newUser) { return userData.createTmUser(newUser); }
//Helper methods public NewUser newTempUser() { var password1 = "Sdimfl!@#".add_RandomLetters(10); var newUser = new NewUser { username = 10.randomLetters(), password = password1, company = 10.randomLetters(), email = 10.randomLetters(), firstname = 10.randomLetters(), lastname = 10.randomLetters(), title = 10.randomLetters() }; return newUser; }
[WebMethod(EnableSession = true)] public Signup_Result CreateUser_Response(NewUser newUser) { return(userData.createTmUserResponse(newUser)); }
public void createTmUser() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser() { Company = 10.randomLetters(), Country = 10.randomLetters(), Firstname = 10.randomLetters(), Lastname = 10.randomLetters(), Note = 10.randomLetters(), Password = "******"+10.randomLetters(), State = 10.randomLetters(), Title = 10.randomLetters(), Username = 10.randomLetters(), Email = "{0}@{0}.{0}".format(3.randomLetters()) }; Assert.IsEmpty(newUser.validate()); var user1 = newUser.create(); var user2 = newUser.create(); Assert.AreNotEqual(user1, 0); Assert.AreNotEqual(user1, user2); //try with email in upper case newUser.Username = 10.randomLetters(); newUser.Email = newUser.Email.upper(); //try creating a repeated user Assert.AreEqual(0, newUser.create()); //try creating an admin user (which should fail for anonymous users) newUser.GroupId = (int)UserGroup.Admin; newUser.Username = 10.randomLetters(); newUser.Email = "{0}@{0}.{0}".format(3.randomLetters()); Assert.Throws<SecurityException>(()=> newUser.create()); UserGroup.Admin.setPrivileges(); Assert.AreNotEqual(0, newUser.create()); //try creating a repeated user Assert.AreEqual (0, newUser.create()); newUser.Username = 10.randomLetters(); // just difference username should fail Assert.AreEqual (0, newUser.create()); newUser.Email = "{0}@{0}.{0}".format(3.randomLetters()); // with different username and password should work Assert.AreNotEqual(0, newUser.create()); //test nulls and fail validation Assert.AreEqual (0, userData.createTmUser(null)); newUser.Username = null; Assert.AreEqual (0, newUser.create()); }
//Helper methods public NewUser newTempUser() { var password1 = "13Sdimfl!@#".add_RandomLetters(10); var newUser = new NewUser { Username = 10.randomLetters(), Password = password1, Company = 10.randomLetters(), Email = "{0}@{0}.{0}".format(3.randomLetters()), Firstname = 10.randomLetters(), Lastname = 10.randomLetters(), Note = 10.randomLetters(), Title = 10.randomLetters(), Country = 10.randomLetters(), State = 10.randomLetters() }; return newUser; }
[Admin] public List <string> user_Verify(NewUser newUser) { return(TmWebServices.CreateUser_Validate(newUser)); }
[Admin] public int user_Create(NewUser newUser) { UserRole.Admin.demand(); return(TmWebServices.CreateUser(newUser)); }
public void CreateTmUserSigupResponse_Email_Address_Invalid_Bad_Format() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser().with_Random_Data(); newUser.Email = "novalid"; userData.createTmUserResponse(newUser).assert_Not_Null(); userData.createTmUserResponse(newUser).UserCreated.assert_Is(0); userData.createTmUserResponse(newUser).Signup_Status.assert_Is(Signup_Result.SignupStatus.Validation_Failed); userData.createTmUserResponse(newUser).Validation_Results.assert_Not_Null(); var validations = userData.createTmUserResponse(newUser).Validation_Results; validations.assert_Not_Null(); validations.FirstOrDefault().Field.assert_Is("Email"); validations.FirstOrDefault().Message.assert_Is(TMConsts.DEFAULT_EMAIL_ADDRESS_IS_INVALID); }
public void CreateTmUserSigupResponse_TLD_Email_Success() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser().with_Random_Data(); newUser.Email = "[email protected]"; newUser.valid_Email_Address().assert_True(); }
public static int create(this NewUser newUser) { return(TM_UserData.Current.createTmUser(newUser)); }
public void CreateTmUserSigupResponse_Success() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser().with_Random_Data(); newUser.validate().empty(); var response = newUser.createSigupResponse(); response.assert_Not_Null(); response.UserCreated.assert_Bigger_Than(0); response.Signup_Status.assert_Is(Signup_Result.SignupStatus.Signup_Ok); response.Validation_Results.count().assert_Is(0); }
public void CreateTmUserSigupResponse_PasswordIsWeak() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser() { Company = 10.randomLetters(), Country = 10.randomLetters(), Firstname = 10.randomLetters(), Lastname = 10.randomLetters(), Note = 10.randomLetters(), Password = "******" + 8.randomLetters(), State = 10.randomLetters(), Title = 10.randomLetters(), Username = 10.randomLetters(), Email = "{0}@{0}.{0}".format(3.randomLetters()) }; var response = userData.createTmUserResponse(newUser); Assert.IsTrue((response != null)); Assert.IsTrue(response != null && response.UserCreated == 0); Assert.IsTrue(response != null && response.Signup_Status == Signup_Result.SignupStatus.Validation_Failed); Assert.IsTrue(response != null && response.Validation_Results != null & response.Validation_Results.count() > 0); var results = response.Validation_Results; Assert.IsTrue(results.count() > 0); var result = results.FirstOrDefault(); Assert.IsTrue(result.notNull()); Assert.IsTrue(result.Message == tmConfig.TMErrorMessages.PasswordComplexityErroMessage); }
public void CreateTmUserSigupResponse_Email_Address_NullorEmpty() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser().with_Random_Data(); newUser.Email = string.Empty; var response = userData.createTmUserResponse(newUser); response.assert_Not_Null(); response.UserCreated.assert_Is(0); response.Signup_Status.assert_Equal(Signup_Result.SignupStatus.Validation_Failed); var results = response.Validation_Results; results.count().assert_Bigger_Than(0); results.FirstOrDefault().Field.assert_Is("Email"); results.FirstOrDefault().Message.assert_Is(TMConsts.DEFAULT_EMAIL_ADDRESS_IS_INVALID); }
[Admin] public string VerifyUserData(string payload) { UserRole.Admin.demand(); var users = payload.split("\n"); var userData = TM_UserData.Current; var errorMessage = string.Empty; var emails = new HashSet <string>(); var usernames = new HashSet <string>(); foreach (var user in users) { var rawData = user.split(","); //Safe check for if (rawData.count() < 13) { errorMessage = string.Format("There is a missing field for user {0}.Please verify.", rawData[0] ?? ""); break; } var userName = rawData[0] ?? ""; var password = rawData[1] ?? ""; var email = rawData[2] ?? ""; var firstName = rawData[3] ?? ""; var lastName = rawData[4] ?? ""; var company = rawData[5] ?? ""; var title = rawData[6] ?? ""; var country = rawData[7] ?? ""; var state = rawData[8] ?? ""; var expiryDate = rawData[9] ?? ""; var role = rawData[10] ?? ""; var passwordExpire = rawData[11] ?? ""; var userEnabled = rawData[12] ?? ""; var tmUser = new NewUser { Username = userName, Password = password, Company = company, Country = country, Email = email, Firstname = firstName, Lastname = lastName, GroupId = int.Parse(role), Note = "CSV user creation", State = state, Title = title }; if (!usernames.Contains(userName)) { usernames.Add(userName); } else { errorMessage = string.Format("Username {0} is already being used in this import.Please verify.", userName); break; } if (!emails.Contains(email.ToString())) { emails.Add(email); } else { errorMessage = string.Format("Email address {0} is already being used for another user in this import.Please verify.", email); break; } //Check wether or not the user does exist. if (userName.tmUser().notNull()) { errorMessage = string.Format("Username {0} already exist.", userName); break; } if (tmUser.valid_Email_Address().isFalse()) { errorMessage = TMConsts.DEFAULT_EMAIL_ADDRESS_IS_INVALID; break; } if (tmUser.validate().Count > 0) { errorMessage = string.Format("Please verify data for user {0} :", userName); errorMessage = tmUser.validate().Aggregate(errorMessage, (current, message) => current + " {0}".format(message.ErrorMessage)); break; } if (userData.TMUsers.Exists(x => x.EMail == email)) { errorMessage = string.Format("Email {0} already exist", email); break; } if (firstName == "") { errorMessage = string.Format("FirstName is a required field for user {0}", userName); break; } if (lastName == "") { errorMessage = string.Format("Last Name is a required field for user {0}", userName); break; } DateTime outputDate; if (String.IsNullOrEmpty(expiryDate) || !DateTime.TryParse(expiryDate, out outputDate)) { errorMessage = string.Format("Please enter a valid Expiration date for user {0}. Format must be {1}.", userName, "yyyy/mm/dd"); break; } if (outputDate <= DateTime.Now) { errorMessage = string.Format("Expiry date cannot be prior or equal than today. User {0}", userName); break; } if (passwordExpire.trim().ToLower() != "y" && passwordExpire.trim().ToLower() != "n") { errorMessage = string.Format("Please verify data for user {0}, Password expire value must be Y (for yes) or N (for No)", userName); break; } if (userEnabled.trim().ToLower() != "y" && userEnabled.trim().ToLower() != "n") { errorMessage = string.Format("Please verify data for user {0}, User Enabled value must be Y (for yes) or N (for No)", userName); break; } if (!Enum.IsDefined(typeof(UserGroup), int.Parse(role))) { errorMessage = string.Format("The group value set for user {0} is invalid. Valid groups are {1} {2} and {3}", userName, UserGroup.Admin, UserGroup.Editor, UserGroup.Reader); break; } } return(String.IsNullOrEmpty(errorMessage) ? "Success" : errorMessage); }
[Admin] public int user_Create(NewUser newUser) { return(TmWebServices.CreateUser(newUser)); }
[Admin] public List <string> user_Verify(NewUser newUser) { UserRole.Admin.demand(); return(TmWebServices.CreateUser_Validate(newUser)); }
public void CreateTmUserSigupResponse_EmailMaxLength_Exceeded() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser().with_Random_Data(); newUser.Email= newUser.Email +"".add_RandomLetters(260); newUser.Email.Length.assert_Bigger_Than(256); newUser.validate().notEmpty(); newUser.validate().count().assert_Is(1); newUser.validate().first().ErrorMessage.assert_Is("The field Email must be a string with a maximum length of 256."); }
public void CreateTmUserSigupResponse_Valid_Email() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser().with_Random_Data(); newUser.Email = "admin@domain"; newUser.valid_Email_Address().assert_Is_True(); }
public void EmailValidation_Performance_Fixed_Strings() { int maxIterations = 100000; var newUser = new NewUser().with_Random_Data(); var sw = new System.Diagnostics.Stopwatch(); for (var index = 0; index < maxIterations; index++) { newUser.Email = "".add_RandomLetters(50); sw.Start(); bool result = newUser.valid_Email_Address(); sw.stop(); sw.Elapsed.seconds().assert_Size_Is_Smaller_Than(3); sw.Reset(); } }
[WebMethod(EnableSession = true)] public int CreateUser(NewUser newUser) { return(userData.createTmUser(newUser)); }
public void EmailValidation_Performance_Random_EmailAdress() { var maxIterations = 100000; var newUser = new NewUser().with_Random_Data(); var sw = new System.Diagnostics.Stopwatch(); for (var index = 0; index < maxIterations; index++) { newUser.Email = "".random_Email(); sw.Start(); newUser.valid_Email_Address().assert_Is_True(); sw.stop(); sw.Elapsed.seconds().assert_Size_Is_Smaller_Than(3); sw.Reset(); } }
public void CreateUser_Validate() { //try with an empty NewUser object var newUser = new NewUser(); var result = tmWebServices.CreateUser_Validate(newUser); Assert.NotNull(result); Assert.AreEqual(result.size(), 3); Assert.AreEqual(result.first(), "Password:The Password field is required."); Assert.AreEqual(result.second(), "Username:The Username field is required."); //try with an a fully populated NewUser object newUser = newTempUser(); result = tmWebServices.CreateUser_Validate(newUser); Assert.NotNull(result); Assert.AreEqual(result.size(), 0); }
public void EmailValidation_Performance_Test() { var maxIterations = 10000; var newUser = new NewUser().with_Random_Data(); var sw = new System.Diagnostics.Stopwatch(); for (var index = 0; index < maxIterations; index++) { //Incrementing email lenght. newUser.Email = "".add_RandomLetters(50 + index); sw.Start(); newUser.valid_Email_Address().assert_False(); sw.stop(); sw.Elapsed.seconds().assert_Size_Is_Smaller_Than(3); sw.Reset(); } }
public void CreateTmUserSigupResponse_Username_AlreadyExist() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser() { Company = 10.randomLetters(), Country = 10.randomLetters(), Firstname = 10.randomLetters(), Lastname = 10.randomLetters(), Note = 10.randomLetters(), Password = "******" + 10.randomLetters(), State = 10.randomLetters(), Title = 10.randomLetters(), Username = "******".add_5_RandomLetters(), Email = "{0}@{0}.{0}".format(3.randomLetters()) }; var response = userData.createTmUserResponse(newUser); Assert.IsTrue((response != null)); Assert.IsTrue(response != null && response.UserCreated>0); Assert.IsTrue(response != null && response.Signup_Status == Signup_Result.SignupStatus.Signup_Ok); response = userData.createTmUserResponse(newUser); Assert.IsTrue(response.notNull()); Assert.IsTrue(response.Signup_Status== Signup_Result.SignupStatus.Validation_Failed); var results = response.Validation_Results; Assert.IsTrue(results.count()>0); Assert.IsTrue(results.FirstOrDefault().Field=="Username"); Assert.IsTrue(results.FirstOrDefault().Message == TMConsts.DEFAULT_SIGNUP_USERNAME_EXIST_MESSAGE); }
[WebMethod(EnableSession = true)] public List <String> CreateUser_Validate(NewUser newUser) { return(newUser.validate().asStringList()); }
public void Validation_NewUser_RequiredFields() { var newUser = new NewUser(); //var requiredValues = "Company,Country,Firstname,Lastname,Note,Password,State,Title,Username,Email".split(","); var requiredValues = "Password,Username,Email".split(","); var validationResults = newUser.validate(); var resultsMapped = validationResults.indexed_By_MemberName(); var validationok = newUser.validation_Ok(); //foreach (var result in validationResults) // "{0} - {1}".info(result.MemberNames.asString(), result.ErrorMessage); Assert.IsNotEmpty(validationResults , "Validation results should not be empty"); Assert.IsFalse (validationok , "Validation Ok should be false"); Assert.IsFalse (resultsMapped.hasKey("UserName__A") , "There should be no mapping here"); Assert.AreEqual (requiredValues.size(), validationResults.size(), "# of validation results"); foreach (var requiredValue in requiredValues) { Assert.IsTrue (resultsMapped.hasKey(requiredValue), "requiredValue not found in mapped data: {0}".format(requiredValue)); Assert.AreEqual(resultsMapped[requiredValue].first(), "The {0} field is required.".format(requiredValue)); } }
public void CreateTmUserSigupResponse_Username_Mustbe_30CharacterLong_() { UserGroup.None.assert(); // change current thread privildges to None var newUser = new NewUser() { Company = 10.randomLetters(), Country = 10.randomLetters(), Firstname = 10.randomLetters(), Lastname = 10.randomLetters(), Note = 10.randomLetters(), Password = "******" + 6.randomLetters(), State = 10.randomLetters(), Title = 10.randomLetters(), Username = 100.randomLetters(), Email = "{0}@{0}.{0}".format(3.randomLetters()) }; var response = userData.createTmUserResponse(newUser); Assert.IsTrue((response != null)); Assert.IsTrue(response != null && response.UserCreated == 0); Assert.IsTrue(response != null && response.Signup_Status == Signup_Result.SignupStatus.Validation_Failed); Assert.IsTrue(response != null && response.Validation_Results != null & response.Validation_Results.count() > 0); var results = response.Validation_Results; Assert.IsTrue(results.count() > 0); var result = results.FirstOrDefault(); Assert.IsTrue(result.notNull()); Assert.IsTrue(result.Field=="Username"); Assert.IsTrue((result.Message== "The field Username must be a string with a maximum length of 30.")); }