本文整理汇总了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");
}
示例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);
}
示例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);
}
示例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();
}
示例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");
}
}
}
示例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)));
}
示例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);
}