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


C# UserStore.FindByIdAsync方法代码示例

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


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

示例1: CreateAsync_GivenNewUser_CreatesNewUserAndAssignsUserId

        public async void CreateAsync_GivenNewUser_CreatesNewUserAndAssignsUserId()
        {
            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 insertedUser = await userStore.FindByIdAsync(user.Id);

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

示例2: RemoveClaimAsync_GivenAUserAndClaim_RemovesTheClaim

        public async void RemoveClaimAsync_GivenAUserAndClaim_RemovesTheClaim()
        {
            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 insertedUser = await userStore.FindByIdAsync(user.Id);

            await userStore.AddClaimAsync(insertedUser, new Claim("ClaimType2", "ClaimValue2"));

            await userStore.RemoveClaimAsync(insertedUser, new Claim("ClaimType2", "ClaimValue2"));

            IList<Claim> claims = await userStore.GetClaimsAsync(user);

            claims.Should().HaveCount(0);
        }
开发者ID:raypigott,项目名称:Identity,代码行数:32,代码来源:UserClaimStoreTests.cs

示例3: Should_create_UserStore_with_named_connection

        public void Should_create_UserStore_with_named_connection()
        {
            var target = new UserStore<IdentityUser>("TestDatabase");
            var task = target.FindByIdAsync(TestData.John_UserId);
            task.Wait();

            var user = task.Result;
            Assert.That(user, Is.Not.Null);
            Assert.That(user.Id, Is.EqualTo(TestData.John_UserId));
        }
开发者ID:rioka,项目名称:Simple.Data.AspNet.Identity,代码行数:10,代码来源:When_using_different_connection_configuration.cs

示例4: FindByIdAsyncTest

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

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

示例5: Should_read_user_from_MyUsers_table

        public void Should_read_user_from_MyUsers_table()
        {
            TestData.AddUsers(useCustomTables: true);
            var tables = new Tables().SetUsersTable("MyUsers");
            var target = new UserStore<IdentityUser>(tables);

            var task = target.FindByIdAsync(TestData.John_UserId);

            task.Wait();

            Assert.That(task.Result, Is.Not.Null);
            Assert.That(task.Result.UserName, Is.EqualTo("John"));
        }
开发者ID:rioka,项目名称:Simple.Data.AspNet.Identity,代码行数:13,代码来源:When_working_with_custom_table.cs

示例6: ThenItIsAddedToTheList

        async public Task ThenItIsAddedToTheList()
        {
            var store = new UserStore<TestUser>();

            var user = new TestUser() { Id = "1", UserName = "FStallone" };

            await store.CreateAsync(user);

            var output = await store.FindByIdAsync("1");

            Assert.IsNotNull(output);
            Assert.AreEqual("FStallone", output.UserName);
        }
开发者ID:pottereric,项目名称:BiggyUserStore,代码行数:13,代码来源:WhenAUserIsCreated.cs

示例7: CreateAsyncTest

        public async Task CreateAsyncTest()
        {
            var database = CreateDatabase();
            
            var store = new UserStore<ApplicationUser>(database);
            var user = new ApplicationUser() { UserName = "TestUser" };
            await store.CreateAsync(user);
            Assert.IsTrue(user.Id.Length > 0);
            var userFromDb = await store.FindByIdAsync(user.Id);
            
            Assert.IsNotNull(userFromDb);
            Assert.AreEqual("TestUser", userFromDb.UserName);

            database.GetCollection<ApplicationUser>("users").Remove(Query<ApplicationUser>.EQ(u => u.Id, user.Id));
        }
开发者ID:peters,项目名称:Asp.Net-Identity-sample-app,代码行数:15,代码来源:StoreTests.cs

示例8: Button1_Click

 protected async void Button1_Click(object sender, EventArgs e)
 {
     if (txtPsw.Text.Length > 8)
     {
     UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(_db);
     UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(store);
     String userId = ddlUser.SelectedValue.ToString(); 
     String newPassword = txtPsw.Text; 
     String hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword);
     ApplicationUser cUser = await store.FindByIdAsync(userId);
     await store.SetPasswordHashAsync(cUser, hashedNewPassword);
     await store.UpdateAsync(cUser);
         lblOk.ForeColor = Color.GreenYellow;
         lblOk.Text = "Password modificata con successo!";
     }
     else
     {
         lblOk.ForeColor = Color.Red;
         lblOk.Text = "Scrivi una password valida! Almeno 8 carattteri, 1 maiuscola e un carattere non alfanumerico!";
     }
 }
开发者ID:alceweb,项目名称:PuntoFitness2,代码行数:21,代码来源:rst.aspx.cs

示例9: When_User_Exists_FindByIdAsync_Succeeds

        public void When_User_Exists_FindByIdAsync_Succeeds()
        {
            var mockResult = new Mock<IOperationResult<IdentityUser>>();
            mockResult.SetupGet(x => x.Success).Returns(true);
            mockResult.SetupGet(x => x.Status).Returns(ResponseStatus.Success);

            var mockBucket = new Mock<IBucket>();
            mockBucket.SetupGet(e => e.Name).Returns("default");
            mockBucket.Setup(x => x.GetAsync<IdentityUser>(It.IsAny<string>()))
                .ReturnsAsync(mockResult.Object);

            var store = new UserStore<IdentityUser>(new ThrowableBucket(mockBucket.Object));
            Assert.DoesNotThrow(async () => await store.FindByIdAsync(Guid.NewGuid().ToString()));
        }
开发者ID:RoyGoode,项目名称:couchbase-aspnet-identity,代码行数:14,代码来源:UserStoreTests.cs

示例10: UserPropertiesList

        public ActionResult UserPropertiesList()
        {
            return Task.Run(async () =>
            {
                UserPropertiesViewModel uservm = new UserPropertiesViewModel();
                using (CustomDbContext db = new CustomDbContext())
                {
                    try
                    {
                        UserStore<CustomUser> userstore = new UserStore<CustomUser>(db);
                        var user = await userstore.FindByIdAsync(User.Identity.GetUserId());

                        uservm.FirstName = user.FirstName;
                        uservm.LastName = user.LastName;
                        uservm.Email = user.Email;
                        uservm.Phone = user.Phone;
                        uservm.JoinDate = user.JoinDate;
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error occurred while getting user properties: {0}", ex.ToString());
                    }

                }
                return (ActionResult)PartialView("_UserPropertiesListPartial", uservm);
            }).Result;
        }
开发者ID:reyntjesr,项目名称:IdentityUserPropertiesSample,代码行数:27,代码来源:AccountController.cs

示例11: 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

示例12: CreateLoadDeleteUserTest

        public async Task CreateLoadDeleteUserTest()
        {
            var db = UnitTestHelper.CreateDefaultDb();
            var store = new UserStore<IdentityUser>(db);
            var user = new IdentityUser("Test");
            Assert.Null(await store.FindByIdAsync(user.Id));
            await store.CreateAsync(user);
            var loadUser = await store.FindByIdAsync(user.Id);
            Assert.NotNull(loadUser);

            Assert.Equal(user.Id, loadUser.Id);
            await store.DeleteAsync(loadUser);
            loadUser = await store.FindByIdAsync(user.Id);
            Assert.Null(loadUser);
        }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:15,代码来源:UserStoreTest.cs

示例13: DeleteUserTest

 public async Task DeleteUserTest()
 {
     var db = UnitTestHelper.CreateDefaultDb();
     var store = new UserStore<IdentityUser>(db);
     var mgmt = new IdentityUser("deletemgmttest");
     await store.CreateAsync(mgmt);
     Assert.NotNull(await store.FindByIdAsync(mgmt.Id));
     await store.DeleteAsync(mgmt);
     Assert.Null(await store.FindByIdAsync(mgmt.Id));
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:10,代码来源:UserStoreTest.cs

示例14: Should_update_user_in_MyUsers_table

        public void Should_update_user_in_MyUsers_table()
        {
            TestData.AddUsers(useCustomTables: true);

            var target = new UserStore<IdentityUser>();
            target.Tables.SetUsersTable("MyUsers");

            var task = target.FindByIdAsync(TestData.John_UserId);

            task.Wait();

            var user = task.Result;

            user.PhoneNumber = "1234";
            user.PhoneNumberConfirmed = true;

            var updateTask = target.UpdateAsync(user);

            updateTask.Wait();

            var db = Database.Open();

            var updatedUser = (IdentityUser)db.MyUsers.FindAllById(TestData.John_UserId).First();

            Assert.That(updatedUser.PhoneNumber, Is.EqualTo("1234"));
            Assert.That(updatedUser.PhoneNumberConfirmed, Is.True);

        }
开发者ID:rioka,项目名称:Simple.Data.AspNet.Identity,代码行数:28,代码来源:When_working_with_custom_table.cs

示例15: UserProperties

        public async Task<ActionResult> UserProperties(UserPropertiesViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (CustomDbContext db = new CustomDbContext())
                    {
                        UserStore<CustomUser> userstore = new UserStore<CustomUser>(db);
                        var user = await userstore.FindByIdAsync(User.Identity.GetUserId());
                        user.FirstName = model.FirstName;
                        user.LastName = model.LastName;
                        user.Email = model.Email;
                        user.Phone = model.Phone;
                        await userstore.UpdateAsync(user);
                        await db.SaveChangesAsync();
                        return RedirectToAction("Manage", new { Message = "Your properties have been updated." });
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error occurred while updating user properties : {0}", ex.ToString());
                }
            }

            return View(model);

        }
开发者ID:reyntjesr,项目名称:IdentityUserPropertiesSample,代码行数:28,代码来源:AccountController.cs


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