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


C# UserStore.CreateAsync方法代码示例

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


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

示例1: SetLockoutEndDateAsync_GivenAUserAndLockoutDate_LockoutDateIsSet

        public async void SetLockoutEndDateAsync_GivenAUserAndLockoutDate_LockoutDateIsSet()
        {
            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.SetLockoutEndDateAsync(user, Convert.ToDateTime("01/01/2014"));

            var lockoutDate = await userStore.GetLockoutEndDateAsync(user);

            lockoutDate.Should().Be(Convert.ToDateTime("01/01/2014"));
        }
开发者ID:raypigott,项目名称:Identity,代码行数:27,代码来源:UserLockoutStoreTests.cs

示例2: AddToRoleAsync_GivenAUserAndRole_AddsTheUserToTheRole

        public async void AddToRoleAsync_GivenAUserAndRole_AddsTheUserToTheRole()
        {
            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);

            await userStore.AddToRoleAsync(user, "Admin");

            var roles = await userStore.GetRolesAsync(user);

            roles.Should().HaveCount(1);
            roles[0].Should().Be("Admin");
        }
开发者ID:raypigott,项目名称:Identity,代码行数:29,代码来源:UserRoleTests.cs

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

示例4: AddRemoveUserClaimTest

 public async Task AddRemoveUserClaimTest()
 {
     var db = UnitTestHelper.CreateDefaultDb();
     var store = new UserStore<IdentityUser>(db);
     ;
     var user = new IdentityUser("ClaimsAddRemove");
     await store.CreateAsync(user);
     Claim[] claims = {new Claim("c", "v"), new Claim("c2", "v2"), new Claim("c2", "v3")};
     foreach (Claim c in claims)
     {
         await store.AddClaimAsync(user, c);
     }
     await store.UpdateAsync(user);
     var userClaims = await store.GetClaimsAsync(user);
     Assert.Equal(3, userClaims.Count);
     await store.RemoveClaimAsync(user, claims[0]);
     Assert.Equal(3, userClaims.Count); // No effect until save changes
     db.SaveChanges();
     userClaims = await store.GetClaimsAsync(user);
     Assert.Equal(2, userClaims.Count);
     await store.RemoveClaimAsync(user, claims[1]);
     Assert.Equal(2, userClaims.Count); // No effect until save changes
     db.SaveChanges();
     userClaims = await store.GetClaimsAsync(user);
     Assert.Equal(1, userClaims.Count);
     await store.RemoveClaimAsync(user, claims[2]);
     Assert.Equal(1, userClaims.Count); // No effect until save changes
     db.SaveChanges();
     userClaims = await store.GetClaimsAsync(user);
     Assert.Equal(0, userClaims.Count);
     //Assert.Equal(0, user.Claims.Count);
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:32,代码来源:UserClaimsTest.cs

示例5: AddUserResourcePool_IdShouldBeBiggerThanZero

        public async Task AddUserResourcePool_IdShouldBeBiggerThanZero()
        {
            // Arrange
            var userStore = new UserStore(Context);
            userStore.AutoSaveChanges = false;

            var user = new User("User");

            await userStore.CreateAsync(user);
            await Context.SaveChangesAsync();

            LoginAs(user);

            var resourcePool = new ResourcePool(user, "ResourcePool");
            var userResourcePool = resourcePool.AddUserResourcePool(100);

            // Act
            resourcePoolRepository.Insert(resourcePool);
            await Context.SaveChangesAsync();

            // Assert
            Assert.IsTrue(user.Id > 0);
            Assert.IsTrue(resourcePool.Id > 0);
            //Assert.IsTrue(userResourcePool.Id > 0);
        }
开发者ID:gitter-badger,项目名称:WealthEconomy,代码行数:25,代码来源:ResourcePoolRepositoryTests.cs

示例6: HasPasswordAsync_GivenAUserWithAPasswordHash_ReturnsTrue

        public async void HasPasswordAsync_GivenAUserWithAPasswordHash_ReturnsTrue()
        {
            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 hasPasswordHash = await userStore.HasPasswordAsync(user);

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

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

示例8: AddUserWithNoUserNameFailsTest

 public void AddUserWithNoUserNameFailsTest()
 {
     var db = UnitTestHelper.CreateDefaultDb();
     var store = new UserStore<IdentityUser>(db);
     Assert.Throws<DbEntityValidationException>(
         () => AsyncHelper.RunSync(() => store.CreateAsync(new IdentityUser())));
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:7,代码来源:UserStoreTest.cs

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

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

示例11: When_Not_Success_CreateAsync_Throws_CouchbaseException

        public void When_Not_Success_CreateAsync_Throws_CouchbaseException()
        {
            var mockBucket = new Mock<IBucket>();
            mockBucket.SetupGet(e => e.Name).Returns("default");

            var mockResult = new Mock<IOperationResult<IdentityUser>>();
            mockResult.SetupGet(x => x.Success).Returns(false);
            mockResult.SetupGet(x => x.Status).Returns(ResponseStatus.KeyExists);
            mockBucket.Setup(x => x.InsertAsync(It.IsAny<string>(), It.IsAny<IdentityUser>()))
                .ReturnsAsync(mockResult.Object);

            var mockResult2 = new Mock<IOperationResult<string>>();
            mockResult2.SetupGet(x => x.Success).Returns(false);
            mockResult2.SetupGet(x => x.Status).Returns(ResponseStatus.KeyExists);
            mockBucket.Setup(x => x.InsertAsync(It.IsAny<string>(), It.IsAny<string>()))
              .ReturnsAsync(mockResult2.Object);

            var mockResult3 = new Mock<IOperationResult<string>>();
            mockResult3.SetupGet(x => x.Success).Returns(false);
            mockResult3.SetupGet(x => x.Status).Returns(ResponseStatus.KeyExists);
            mockBucket.Setup(x => x.InsertAsync(It.IsAny<string>(), It.IsAny<string>()))
              .ReturnsAsync(mockResult3.Object);

            var user = new IdentityUser("foo")
            {
                Email = "[email protected]"
            };
            var store = new UserStore<IdentityUser>(new ThrowableBucket(mockBucket.Object));
            Assert.Throws<CouchbaseException>(async () => await store.CreateAsync(user));
        }
开发者ID:RoyGoode,项目名称:couchbase-aspnet-identity,代码行数:30,代码来源:UserStoreTests.cs

示例12: SetPasswordHashAsync_GivenAUserAndPasswordHash_SetsTheHashForTheUser

        public async void SetPasswordHashAsync_GivenAUserAndPasswordHash_SetsTheHashForTheUser()
        {
            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);

            await userStore.SetPasswordHashAsync(user, "1234");

            var passwordHash = await userStore.GetPasswordHashAsync(user);

            passwordHash.Should().Be("1234");
        }
开发者ID:raypigott,项目名称:Identity,代码行数:28,代码来源:UserPasswordStoreTests.cs

示例13: AddDupeUserIdWithStoreFailsTest

 public async Task AddDupeUserIdWithStoreFailsTest()
 {
     var db = UnitTestHelper.CreateDefaultDb();
     var store = new UserStore<IdentityUser>(db);
     var user = new IdentityUser("dupemgmt");
     await store.CreateAsync(user);
     var u2 = new IdentityUser {Id = user.Id, UserName = "User"};
     try
     {
         await store.CreateAsync(u2);
         Assert.False(true);
     }
     catch (Exception e)
     {
         Assert.True(e.InnerException.InnerException.Message.Contains("duplicate key"));
     }
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:17,代码来源:UserStoreTest.cs

示例14: CreateAutoSavesTest

 public async Task CreateAutoSavesTest()
 {
     var db = new NoopIdentityDbContext();
     db.Configuration.ValidateOnSaveEnabled = false;
     var store = new UserStore<IdentityUser>(db);
     var user = new IdentityUser("test");
     await store.CreateAsync(user);
     Assert.True(db.SaveChangesCalled);
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:9,代码来源:UserStoreTest.cs

示例15: CanDisableAutoSaveChangesTest

 public async Task CanDisableAutoSaveChangesTest()
 {
     var db = new NoopIdentityDbContext();
     var store = new UserStore<IdentityUser>(db);
     store.AutoSaveChanges = false;
     var user = new IdentityUser("test");
     await store.CreateAsync(user);
     Assert.False(db.SaveChangesCalled);
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:9,代码来源:UserStoreTest.cs


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