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


C# RoleStore.CreateAsync方法代码示例

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


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

示例1: InitializeAppEnvironment

        private void InitializeAppEnvironment()
        {
            //app environment configuration
            using (var db = new ApplicationDbContext())
            {
                db.Database.CreateIfNotExists();
                var roleStore = new RoleStore<IdentityRole>(db);
                var role = roleStore.FindByNameAsync("Admin").Result;
                if (role == null)
                {
                    roleStore.CreateAsync(new IdentityRole("Admin")).Wait();
                }

                var userStore = new UserStore<ApplicationUser>(db);
                var manager = new ApplicationUserManager(userStore);

                var admin = manager.FindByName("admin");
                if (admin == null)
                {
                    admin = new ApplicationUser
                    {
                        UserName = "admin",
                        Email = "[email protected]",
                        EmailConfirmed = true,
                        CreateDate = DateTime.Now
                    };
                    var r = manager.CreateAsync(admin, "~Pwd123456").Result;
                }
                if (!manager.IsInRole(admin.Id, role.Name))
                {
                    manager.AddToRole(admin.Id, role.Name);
                }
            }
        }
开发者ID:kissstudio,项目名称:Topawes,代码行数:34,代码来源:Startup.cs

示例2: CreateRole

 /// <summary>
 /// 创建角色
 /// </summary>
 /// <param name="name">角色名称</param>
 /// <param name="normalizedName">角色普通称谓</param>
 /// <returns></returns>
 public bool CreateRole(string name, string normalizedName)
 {
     var role = new IdentityRole<int>()
     {
         Name = name,
         NormalizedName = normalizedName
     };
     var roleStore = new RoleStore<IdentityRole<int>, CrossContext, int>(_db);
     return roleStore.CreateAsync(role).Result.Succeeded;
 }
开发者ID:wccxsz,项目名称:Cross,代码行数:16,代码来源:AccountBLL.cs

示例3: RoleStorePublicNullCheckTest

 public async Task RoleStorePublicNullCheckTest()
 {
     Assert.Throws<ArgumentNullException>("context", () => new RoleStore<IdentityRole>(null));
     var store = new RoleStore<IdentityRole>(new InMemoryContext());
     await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.GetRoleIdAsync(null));
     await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.GetRoleNameAsync(null));
     await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.SetRoleNameAsync(null, null));
     await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.CreateAsync(null));
     await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.UpdateAsync(null));
     await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.DeleteAsync(null));
 }
开发者ID:bmansoob,项目名称:Identity,代码行数:11,代码来源:RoleStoreTest.cs

示例4: RoleStoreMethodsThrowWhenDisposedTest

 public async Task RoleStoreMethodsThrowWhenDisposedTest()
 {
     var store = new RoleStore<IdentityRole>(new InMemoryContext());
     store.Dispose();
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByIdAsync(null));
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByNameAsync(null));
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRoleIdAsync(null));
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRoleNameAsync(null));
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.SetRoleNameAsync(null, null));
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.CreateAsync(null));
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.UpdateAsync(null));
     await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.DeleteAsync(null));
 }
开发者ID:bmansoob,项目名称:Identity,代码行数:13,代码来源:RoleStoreTest.cs

示例5: When_Not_Success_CreateAsync_Throws_CouchbaseException

        public void When_Not_Success_CreateAsync_Throws_CouchbaseException()
        {
            var mockResult = new Mock<IOperationResult<IdentityRole>>();
            mockResult.SetupGet(x => x.Success).Returns(false);
            mockResult.SetupGet(x => x.Status).Returns(ResponseStatus.KeyExists);

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

            var store = new RoleStore<IdentityRole>(mockBucket.Object);
            Assert.Throws<CouchbaseException>(async () => await store.CreateAsync(new IdentityRole("user", Guid.NewGuid().ToString())));
        }
开发者ID:RoyGoode,项目名称:couchbase-aspnet-identity,代码行数:14,代码来源:RoleStoreTests.cs

示例6: When_Success_CreateAsync_Does_Not_Throw_Exception

        public void When_Success_CreateAsync_Does_Not_Throw_Exception()
        {
            var mockResult = new Mock<IOperationResult<IdentityRole>>();
            mockResult.SetupGet(x => x.Success).Returns(true);

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

            var store = new RoleStore<IdentityRole>(mockBucket.Object);
            Assert.DoesNotThrow(async () => await store.CreateAsync(new IdentityRole("user", Guid.NewGuid().ToString())));
        }
开发者ID:RoyGoode,项目名称:couchbase-aspnet-identity,代码行数:13,代码来源:RoleStoreTests.cs

示例7: GetAllRoles

        public void GetAllRoles()
        {
            var user1 = new IdentityUser("Lukz 04");
            var user2 = new IdentityUser("Moa 01");
            var user3 = new IdentityUser("Win 02");
            var user4 = new IdentityUser("Andre 03");
            var role = new IdentityRole("ADM");
            var role2 = new IdentityRole("USR");
            var store = new UserStore<IdentityUser>(this._session);
            var roleStore = new RoleStore<IdentityRole>(this._session);

            roleStore.CreateAsync(role);
            roleStore.CreateAsync(role2);
            store.CreateAsync(user1);
            store.CreateAsync(user2);
            store.CreateAsync(user3);
            store.CreateAsync(user4);
            store.AddToRoleAsync(user1, "ADM");
            store.AddToRoleAsync(user2, "ADM");
            store.AddToRoleAsync(user3, "ADM");
            store.AddToRoleAsync(user4, "ADM");
            store.AddToRoleAsync(user1, "USR");
            store.AddToRoleAsync(user4, "USR");

            Assert.IsTrue(this._session.Query<IdentityRole>().Any(x => x.Name == "ADM"));
            Assert.IsTrue(this._session.Query<IdentityUser>().Any(x => x.UserName == "Lukz 04"));

            Assert.IsTrue(this._session.Query<IdentityUser>().Any(x => x.UserName == "Andre 03"));

            var resul = roleStore.Roles;

            Assert.AreEqual(2, resul.Count());
        }
开发者ID:dags20,项目名称:NHibernate.AspNet.Identity.MultiTenant,代码行数:33,代码来源:UserStoreTest.cs

示例8: WhenRemoveUserFromRole_ThenDoNotDeleteRole_BugFix

        public void WhenRemoveUserFromRole_ThenDoNotDeleteRole_BugFix()
        {
            var user = new IdentityUser("Lukz 05");
            var role = new IdentityRole("ADM05");
            var store = new UserStore<IdentityUser>(_session);
            var roleStore = new RoleStore<IdentityRole>(_session);

            roleStore.CreateAsync(role);
            store.CreateAsync(user);
            store.AddToRoleAsync(user, "ADM05");

            Assert.IsTrue(_session.Query<IdentityRole>().Any(x => x.Name == "ADM05"));
            Assert.IsTrue(_session.Query<IdentityUser>().Any(x => x.UserName == "Lukz 05"));
            Assert.IsTrue(store.IsInRoleAsync(user, "ADM05").Result);

            var result = store.RemoveFromRoleAsync(user, "ADM05");

            Assert.IsNull(result.Exception);
            Assert.IsFalse(store.IsInRoleAsync(user, "ADM05").Result);
            Assert.IsTrue(_session.Query<IdentityUser>().Any(x => x.UserName == "Lukz 05"));
            Assert.IsTrue(_session.Query<IdentityRole>().Any(x => x.Name == "ADM05"));
        }
开发者ID:dags20,项目名称:NHibernate.AspNet.Identity.MultiTenant,代码行数:22,代码来源:UserStoreTest.cs

示例9: GivenHaveRoles_WhenDeleteUser_ThenDeletingCausesNoCascade

        public void GivenHaveRoles_WhenDeleteUser_ThenDeletingCausesNoCascade()
        {
            var user = new IdentityUser("Lukz 04");
            var role = new IdentityRole("ADM");
            var store = new UserStore<IdentityUser>(_session);
            var roleStore = new RoleStore<IdentityRole>(_session);

            roleStore.CreateAsync(role);
            store.CreateAsync(user);
            store.AddToRoleAsync(user, "ADM");

            Assert.IsTrue(_session.Query<IdentityRole>().Any(x => x.Name == "ADM"));
            Assert.IsTrue(_session.Query<IdentityUser>().Any(x => x.UserName == "Lukz 04"));

            var result = store.DeleteAsync(user);

            Assert.IsNull(result.Exception);
            Assert.IsFalse(this._session.Query<IdentityUser>().Any(x => x.UserName == "Lukz 04"));
            Assert.IsTrue(this._session.Query<IdentityRole>().Any(x => x.Name == "ADM"));
        }
开发者ID:dags20,项目名称:NHibernate.AspNet.Identity.MultiTenant,代码行数:20,代码来源:UserStoreTest.cs


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