简体   繁体   中英

Asp.net Identity Integration Test

I want write test and save user in sql ce.This my test:

   using (ApplicationContext context = new ApplicationContext())
        {
            var email = "Shahrooz@s.s";
            var username = "shahrooz";
            var customUserStore = SmObjectFactory.Container.GetInstance<IUserStore<ApplicationUser, int>>();
            var customRoleStore = SmObjectFactory.Container.GetInstance<IApplicationRoleManager>();
            var smsService = SmObjectFactory.Container.GetInstance<IIdentityMessageService>();
            var emailService = SmObjectFactory.Container.GetInstance<IIdentityMessageService>();
            ApplicationUserManager manager = new ApplicationUserManager(customUserStore, customRoleStore, new DpapiDataProtectionProvider(), smsService, emailService);
            context.Database.Connection.Open();
            manager.CreateAsync(new ApplicationUser { Email = email, UserName = username }, Guid.NewGuid().ToString()).Wait();
            var applicationUser = context.Users.Find(1);
            Assert.IsNotNull(applicationUser);
            Assert.IsTrue(applicationUser.Email == email);
            Assert.IsTrue(applicationUser.UserName == username);
            context.Database.Connection.Close();
        }

But CreateAsync dont store any thing in database. What is my problem?

This line:

manager.CreateAsync(.....

this method returns an object IdentityResult that contains boolean for Successful and a list of Errors that you should inspect. Inspect this object for errors and if user was created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM