当前位置: 首页>>代码示例>>C#>>正文


C# UserStore.FindByNameAsync方法代码示例

本文整理汇总了C#中UserStore.FindByNameAsync方法的典型用法代码示例。如果您正苦于以下问题:C# UserStore.FindByNameAsync方法的具体用法?C# UserStore.FindByNameAsync怎么用?C# UserStore.FindByNameAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserStore的用法示例。


在下文中一共展示了UserStore.FindByNameAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateAsync_GivenAnUpdate_UpdatesTheUser

        public async void UpdateAsync_GivenAnUpdate_UpdatesTheUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var existingUser = await userStore.FindByNameAsync("UserName");
            existingUser.Email = "[email protected]";
            existingUser.PhoneNumber = "1234";

            await userStore.UpdateAsync(existingUser);

            var updatedUser = await userStore.FindByNameAsync("UserName");

            updatedUser.Should().NotBeNull();
            updatedUser.Email.Should().Be("[email protected]");
            updatedUser.PhoneNumber.Should().Be("1234");
        }
开发者ID:raypigott,项目名称:Identity,代码行数:34,代码来源:UserStoreTests.cs

示例2: CanCreateUser

        public async Task CanCreateUser()
        {
            string username = "test_user";

            var userstore = new UserStore<IdentityUser>(new Uri(endpoint), key, userdb, usercoll);
            await userstore.CreateAsync(new IdentityUser("test_user"));
            IdentityUser user = await userstore.FindByNameAsync(username);
            Assert.IsNotNull(user);
            Assert.AreEqual(username, user.UserName);
        }
开发者ID:alphio,项目名称:DocumentDB.AspNet.Identity,代码行数:10,代码来源:UserStoreTests.cs

示例3: FindByNameAsyncAsyncTest

        public async Task FindByNameAsyncAsyncTest()
        {
            var database = CreateDatabase();

            var store = new UserStore<ApplicationUser>(database);
            var user = new ApplicationUser() { UserName = "TestUser" };
            await store.CreateAsync(user);
            var userFromDb = await store.FindByNameAsync("testuser");
            Assert.IsTrue(userFromDb.Id.Length > 0);
            Assert.AreEqual(user.Id, userFromDb.Id);
            await store.DeleteAsync(user);
        }
开发者ID:peters,项目名称:Asp.Net-Identity-sample-app,代码行数:12,代码来源:StoreTests.cs

示例4: DeleteAsync_GivenAnExistingUser_UpdatesTheAccountToInActive

        public async void DeleteAsync_GivenAnExistingUser_UpdatesTheAccountToInActive()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var existingUser = await userStore.FindByNameAsync("UserName");
            existingUser.UserName = "HideMe";
            await userStore.UpdateAsync(existingUser);

            await userStore.DeleteAsync(existingUser);

            existingUser.IsAccountActive.Should().BeFalse();
        }
开发者ID:raypigott,项目名称:Identity,代码行数:13,代码来源:UserStoreTests.cs

示例5: RegisterAdmin

        public static void RegisterAdmin()
        {
            using (var context = new CmsContext())
            using (var userStore = new UserStore<CmsUser>(context))
            using (var userManager = new UserManager<CmsUser>(userStore))
            {
                var user = userStore.FindByNameAsync("admin").Result;

                if (user == null)
                {
                    var adminUser = new CmsUser
                    {
                        UserName = "admin",
                        Email = "[email protected]",
                        DisplayName = "Administrator"
                    };

                    userManager.Create(adminUser, "Passw0rd1234");
                }
            }
        }
开发者ID:gadalaavinash,项目名称:Building-a-CMS-With-ASP.NET-MVC5,代码行数:21,代码来源:AuthDbConfig.cs

示例6: UserStoreMethodsThrowWhenDisposedTest

 public void UserStoreMethodsThrowWhenDisposedTest()
 {
     var db = UnitTestHelper.CreateDefaultDb();
     var store = new UserStore<IdentityUser>(db);
     store.Dispose();
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddClaimAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddLoginAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddToRoleAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetClaimsAsync(null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetLoginsAsync(null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetRolesAsync(null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.IsInRoleAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(
         () => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindAsync(null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByIdAsync(null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByNameAsync(null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.UpdateAsync(null)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.DeleteAsync(null)));
     Assert.Throws<ObjectDisposedException>(
         () => AsyncHelper.RunSync(() => store.SetEmailConfirmedAsync(null, true)));
     Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetEmailConfirmedAsync(null)));
     Assert.Throws<ObjectDisposedException>(
         () => AsyncHelper.RunSync(() => store.SetPhoneNumberConfirmedAsync(null, true)));
     Assert.Throws<ObjectDisposedException>(
         () => AsyncHelper.RunSync(() => store.GetPhoneNumberConfirmedAsync(null)));
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:30,代码来源:UserStoreTest.cs

示例7: FindByUserName

        public async Task FindByUserName()
        {
            var db = UnitTestHelper.CreateDefaultDb();
            var store = new UserStore<IdentityUser>(db);
            var user = new IdentityUser("Hao");
            await store.CreateAsync(user);
            var found = await store.FindByNameAsync("hao");
            Assert.NotNull(found);
            Assert.Equal(user.Id, found.Id);

            found = await store.FindByNameAsync("HAO");
            Assert.NotNull(found);
            Assert.Equal(user.Id, found.Id);

            found = await store.FindByNameAsync("Hao");
            Assert.NotNull(found);
            Assert.Equal(user.Id, found.Id);
        }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:18,代码来源:UserStoreTest.cs


注:本文中的UserStore.FindByNameAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。