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


C# UserStore.SetLockoutEnabledAsync方法代码示例

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


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

示例1: SetLockoutEnabledAsync_GivenAUserAndATrueFlag_LockoutEnabledIsSetToTrue

        public async void SetLockoutEnabledAsync_GivenAUserAndATrueFlag_LockoutEnabledIsSetToTrue()
        {
            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 = false,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };
            await userStore.CreateAsync(user);

            await userStore.SetLockoutEnabledAsync(user, true);

            var isLockedOut  = await userStore.GetLockoutEnabledAsync(user);

            isLockedOut.Should().BeTrue();
        }
开发者ID:raypigott,项目名称:Identity,代码行数:27,代码来源:UserLockoutStoreTests.cs

示例2: Should_set_the_lockout_enabled

        public void Should_set_the_lockout_enabled()
        {
            var target = new UserStore<IdentityUser>();

            var task = target.SetLockoutEnabledAsync(TestData.GetTestUserJohn(), true);

            task.Wait();

            var db = Database.Open();
            IdentityUser record = db.AspNetUsers.FindAllByUserName("John").SingleOrDefault();

            Assert.That(record.LockoutEnabled, Is.True);
        }
开发者ID:rioka,项目名称:Simple.Data.AspNet.Identity,代码行数:13,代码来源:When_setting_lockout_enabled.cs

示例3: Should_throw_ArgumentNullException_if_user_is_null

        public void Should_throw_ArgumentNullException_if_user_is_null()
        {
            var target = new UserStore<IdentityUser>();

            Assert.Throws<ArgumentNullException>(() => target.SetLockoutEnabledAsync(null,true));
        }
开发者ID:rioka,项目名称:Simple.Data.AspNet.Identity,代码行数:6,代码来源:When_setting_lockout_enabled.cs

示例4: Should_throw_ObjectDisposedException_if_disposed

 public void Should_throw_ObjectDisposedException_if_disposed()
 {
     var target = new UserStore<IdentityUser>();
     target.Dispose();
     Assert.Throws<ObjectDisposedException>(() => target.SetLockoutEnabledAsync(new IdentityUser(), true));
 }
开发者ID:rioka,项目名称:Simple.Data.AspNet.Identity,代码行数:6,代码来源:When_setting_lockout_enabled.cs

示例5: LockoutEnabled

        public void LockoutEnabled()
        {
            using (UserStore<IdentityUser> store = new UserStore<IdentityUser>())
            {
                using (UserManager<IdentityUser> manager = new UserManager<IdentityUser>(store))
                {
                    manager.UserTokenProvider = new EmailTokenProvider<IdentityUser>();

                    var user = User;

                    var taskLockoutSet = manager.SetLockoutEnabledAsync(user.Id, true);
                    taskLockoutSet.Wait();
                    Assert.IsTrue(taskLockoutSet.Result.Succeeded, string.Concat(taskLockoutSet.Result.Errors));

                    DateTimeOffset offSet = new DateTimeOffset(DateTime.UtcNow.AddMinutes(3));
                    var taskDateSet = manager.SetLockoutEndDateAsync(user.Id, offSet);
                    taskDateSet.Wait();
                    Assert.IsTrue(taskDateSet.Result.Succeeded, string.Concat(taskDateSet.Result.Errors));

                    var taskEnabledGet = manager.GetLockoutEnabledAsync(user.Id);
                    taskEnabledGet.Wait();
                    Assert.IsTrue(taskEnabledGet.Result, "Lockout not true");

                    var taskDateGet = manager.GetLockoutEndDateAsync(user.Id);
                    taskDateGet.Wait();
                    Assert.AreEqual(offSet,taskDateGet.Result, "Lockout date incorrect");

                    DateTime tmpDate = DateTime.UtcNow.AddDays(1);
                    user.LockoutEndDateUtc = tmpDate;
                    var taskGet = store.GetLockoutEndDateAsync(user);
                    taskGet.Wait();
                    Assert.AreEqual<DateTimeOffset>(new DateTimeOffset(tmpDate), taskGet.Result, "LockoutEndDate not set");

                    user.LockoutEndDateUtc = null;
                    var taskGet2 = store.GetLockoutEndDateAsync(user);
                    taskGet2.Wait();
                    Assert.AreEqual<DateTimeOffset>(new DateTimeOffset(), taskGet2.Result, "LockoutEndDate not set");

                    var minOffSet = DateTimeOffset.MinValue;
                    var taskSet2 = store.SetLockoutEndDateAsync(user, minOffSet);
                    taskSet2.Wait();
                    Assert.IsNull(user.LockoutEndDateUtc, "LockoutEndDate not null");

                    try
                    {
                        store.GetLockoutEnabledAsync(null);
                    }
                    catch (ArgumentException) { }

                    try
                    {
                        store.GetLockoutEndDateAsync(null);
                    }
                    catch (ArgumentException) { }

                    try
                    {
                        store.SetLockoutEndDateAsync(null, offSet);
                    }
                    catch (ArgumentException) { }

                    try
                    {
                        store.SetLockoutEnabledAsync(null, false);
                    }
                    catch (ArgumentException) { }
                }
            }
        }
开发者ID:thermous,项目名称:identitydocumentdb,代码行数:69,代码来源:UserStoreTests.Properties.partial.cs


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