コード例 #1
0
        private static async Task <InTandemUser> EnsureUser(IServiceProvider serviceProvider,
                                                            string testUserPw, string firstName, string lastName, string userName, string emailAddress)
        {
            var userManager = serviceProvider.GetService <UserManager <InTandemUser> >();

            var user = await userManager.FindByEmailAsync(emailAddress);

            if (user == null)
            {
                user = new InTandemUser {
                    FirstName = firstName, LastName = lastName, UserName = userName, Email = emailAddress
                };
                if ((user.FirstName != "Volunteer") && (user.FirstName != "Admin"))
                {
                    user.HasBeenApproved = false;
                }

                var result = await userManager.CreateAsync(user, testUserPw);
            }

            return(user);
        }