public void BookLibraryUserBuiderResultTest() { var userDraft = new UserDraft(); var userBuilder = new UserBuilder(); var user = userBuilder.BuildUser(userDraft); DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(double.Parse(userDraft.dateOfBirth)); Assert.AreEqual(user.DateOfBirth, dtDateTime); Assert.AreEqual(user.FirstName, userDraft.firstName); Assert.AreEqual(user.LastName, userDraft.lastName); Assert.AreEqual(user.UserName, userDraft.userName); Assert.IsNotNull(user.Address); Assert.AreEqual(user.Address.Country, userDraft.country); Assert.AreEqual(user.Address.City, userDraft.city); Assert.AreEqual(user.Address.State, userDraft.state); Assert.AreEqual(user.Address.Zipcode, userDraft.zipCode); Assert.AreSame(user.Address.User, user); Assert.IsNotNull(user.MobilePhone); Assert.AreEqual(user.MobilePhone.Value, userDraft.mobilePhone); Assert.AreEqual(user.MobilePhone.IsConfirmed, false); Assert.AreSame(user.MobilePhone.User, user); Assert.IsNotNull(user.Emails[0]); Assert.AreEqual(user.Emails[0].Value, userDraft.email); Assert.AreEqual(user.Emails[0].IsConfirmed, false); Assert.AreSame(user.Emails[0].User, user); Assert.IsNotNull(user.Credentials); Assert.IsNotNull(user.Credentials.Logins); Assert.AreEqual(user.Credentials.Logins.Find(x => x.Type == LoginType.Email).Value, userDraft.email); Assert.AreSame(user.Credentials.Logins.Find(x => x.Type == LoginType.Email).Credentials, user.Credentials); Assert.AreEqual(user.Credentials.Logins.Find(x => x.Type == LoginType.MobilePhone).Value, userDraft.mobilePhone); Assert.AreSame(user.Credentials.Logins.Find(x => x.Type == LoginType.MobilePhone).Credentials, user.Credentials); Assert.AreEqual(user.Credentials.Logins.Find(x => x.Type == LoginType.Username).Value, userDraft.userName); Assert.AreSame(user.Credentials.Logins.Find(x => x.Type == LoginType.Username).Credentials, user.Credentials); Assert.IsNotNull(user.Credentials.Passwords); Assert.AreEqual(user.Credentials.Passwords.Count, 1); Assert.AreEqual(user.Credentials.Passwords[0].Value, userDraft.password); Assert.AreEqual(user.Credentials.Passwords[0].IsActive, true); Assert.IsNotNull(user.Credentials.Passwords[0].ExpirationDate); Assert.AreSame(user.Credentials.Passwords[0].Credentials, user.Credentials); Assert.AreEqual(user.Credentials.User, user); Assert.IsNotNull(user.UserRoles); Assert.AreEqual(user.UserRoles.Count, 1); Assert.AreEqual(user.UserRoles[0].Name, "user"); }
public UserDraft GenerateUserDraft() { var userDraft = new UserDraft(); const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const string charsForName = "abcdefghijklmnopqrstuvwxyz"; const string numericChars = "1234567890"; var start = new DateTime(1946, 1, 1); var generator = new Generator(); userDraft.userName = generator.GenerateString(chars); userDraft.firstName = generator.GenerateString(charsForName); userDraft.firstName = char.ToUpper(userDraft.firstName[0]) + userDraft.firstName.Substring(1); userDraft.lastName = generator.GenerateString(charsForName); userDraft.lastName = char.ToUpper(userDraft.lastName[0]) + userDraft.lastName.Substring(1); userDraft.email = userDraft.firstName.ToLower() + "." + userDraft.lastName.ToLower() + "@gmail.com"; userDraft.password = "******"; userDraft.dateOfBirth = DateTime.Now.Subtract(generator.GenerateDate(start)).TotalSeconds.ToString(); userDraft.mobilePhone = "+" + generator.GenerateString(numericChars); userDraft.country = generator.GenerateString(charsForName); userDraft.country = char.ToUpper(userDraft.country[0]) + userDraft.country.Substring(1); userDraft.state = generator.GenerateString(charsForName); userDraft.state = char.ToUpper(userDraft.state[0]) + userDraft.state.Substring(1); userDraft.city = generator.GenerateString(charsForName); userDraft.city = char.ToUpper(userDraft.city[0]) + userDraft.city.Substring(1); userDraft.addresLine = generator.GenerateString(chars); userDraft.zipCode = generator.GenerateString(numericChars); return(userDraft); }
public User BuildUser(UserDraft userToBuild) { var user = new User(); DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); dtDateTime = dtDateTime.AddSeconds(userToBuild.dateOfBirth); user.DateOfBirth = dtDateTime; user.FirstName = userToBuild.firstName; user.LastName = userToBuild.lastName; user.UserName = userToBuild.userName; var address = new Address(); address.Country = userToBuild.country; address.City = userToBuild.city; address.Zipcode = userToBuild.zipcode; address.AddressLine = userToBuild.addressLine; address.State = userToBuild.state; address.User = user; user.Address = address; var mobilePhone = new MobilePhone(); mobilePhone.User = user; mobilePhone.Value = userToBuild.mobilePhone; mobilePhone.IsConfirmed = false; user.MobilePhone = mobilePhone; var email = new Email(); email.User = user; email.Value = userToBuild.email; email.IsConfirmed = false; email.IsActive = true; user.Emails.Add(email); var credentials = new Credentials(); credentials.User = user; var password = new Password(); string hash; using (MD5 md5Hash = MD5.Create()) { hash = GetMd5Hash(md5Hash, userToBuild.password); } password.Value = hash; password.IsActive = true; password.ExpirationDate = DateTime.Now.AddYears(1); password.Credentials = credentials; credentials.Logins.Add(new LoginName(LoginType.Username, userToBuild.userName, credentials)); credentials.Logins.Add(new LoginName(LoginType.Email, userToBuild.email, credentials)); credentials.Logins.Add(new LoginName(LoginType.MobilePhone, userToBuild.mobilePhone, credentials)); credentials.Passwords.Add(password); user.Credentials = credentials; var role = new Role(); role.Name = "user"; role.Users.Add(user); user.UserRoles.Add(role); return(user); }