public async Task GetAllRoles_Returns_Roles()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InMemoryDatabase")
                          .Options;

            var mockUserInfoProvider = new MockUserInfoProvider("Test User");

            // Setup some data
            using (var context = new ApplicationDbContext(options, mockUserInfoProvider))
            {
                context.Roles.Add(new Role("TestUser")
                {
                    Name        = "SomeRole",
                    Description = "SomeRole"
                });
                await context.SaveChangesAsync();
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new ApplicationDbContext(options, mockUserInfoProvider))
            {
                // Arrange
                var service = new RolesService(context, mockUserInfoProvider);

                // Act
                var roles = (await service.GetRoles()).ToList();

                // Assert
                Assert.Equal(1, roles.Count);
                Assert.Equal("SomeRole", roles.First().Name);
                Assert.Equal("TestUser", roles.First().CreatedBy);
            }
        }
        /// <summary>
        /// 得到我们主键表的权限名称
        /// </summary>
        /// <param name="rid">权限编号</param>
        /// <returns>权限名称</returns>
        public string GetRolesTitle(int rid)
        {
            var data = roles_bll.GetRoles(rid);

            if (data == null)
            {
                return("");
            }
            return(data.Title);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            HttpCookie u_cookie = Request.Cookies["LoginOk"];
            HttpCookie r_cookie = Request.Cookies["RolesId"];

            if ((Session["LoginOk"] == null || Session["RolesId"] == null) && (u_cookie == null || r_cookie == null))
            {
                Response.Write("<script>alert('账号信息过期,请重新登入');location.href='../Login.aspx'</script>");
            }
            else
            {
                var id = Request.Params["action"];
                if (id == null)
                {
                    Response.Write("<script>alert('传输数据丢失,请稍后再试');location.href='RolesList.aspx'</script>");
                }
                else
                {
                    var roles = bll.GetRoles(int.Parse(id));
                    if (roles == null)
                    {
                        Response.Write("<script>alert('该角色信息不存在');location.href='RolesList.aspx'</script>");
                    }
                    else
                    {
                        int rs = bll.Delete(roles);
                        if (rs > 0)
                        {
                            Response.Write("<script>alert('删除成功');location.href='RolesList.aspx'</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('删除失败');location.href='RolesList.aspx'</script>");
                        }
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            HttpCookie u_cookie = Request.Cookies["LoginOk"];
            HttpCookie r_cookie = Request.Cookies["RolesId"];

            if ((Session["LoginOk"] == null || Session["RolesId"] == null) && (u_cookie == null || r_cookie == null))
            {
                Response.Write("<script>alert('账号信息过期,请重新登入');location.href='../Login.aspx'</script>");
            }
            else
            {
                //修改要做的 :
                //1. 页面绑定
                // (1) 先去获取到我们从连接当中传递过来的id值
                var id = Request.Params["action"];
                if (id == null)
                {
                    Response.Write("<script>alert('传输数据丢失,请稍后再试');location.href='RolesList.aspx'</script>");
                }
                else
                {
                    var roles = bll.GetRoles(int.Parse(id));
                    if (roles == null)
                    {
                        Response.Write("<script>alert('该角色信息不存在');location.href='RolesList.aspx'</script>");
                    }
                    else
                    {
                        this.RolesId.Text    = roles.Id.ToString();
                        this.RolesTitle.Text = roles.Title;
                    }
                }
            }
        }
Exemple #5
0
 public async Task <ActionResult <IEnumerable <Role> > > GetRoles()
 {
     return(await _rolesService.GetRoles());
 }