Asp.net 身份集成测试

Asp.net Identity Integration Test

我想编写测试并将用户保存在 sql ce.This 我的测试中:

   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();
        }

但是 CreateAsync 不在数据库中存储任何东西。 我的问题是什么?

这一行:

manager.CreateAsync(.....

此方法 returns 一个对象 IdentityResult,其中包含 Successful 的布尔值和您应该检查的 Errors 列表。检查此对象是否有错误以及是否已创建用户。