private static IUser CreateUser(this IEntitySession session, string userName, UserType userType, string password = DefaultPassword, string email = null) { var user = session.NewUser(userName, userType, userName); var loginMgr = session.Context.App.GetService <ILoginManagementService>(); var login = loginMgr.NewLogin(session, userName, password, userId: user.Id, loginId: user.Id); if (!string.IsNullOrEmpty(email)) { loginMgr.AddFactor(login, ExtraFactorTypes.Email, email); } return(user); }