コード例 #1
0
        public void Teacher_Role_Should_Be_Able_To_Edit_Grade(GradeController sut)
        {
            //arrange
            var roles  = new string[] { "teacher" };
            var method = sut.GetType().GetMethod("Index");
            //act
            var attrib = method.GetCustomAttributes(typeof(AuthorizeAttribute), true).FirstOrDefault() as AuthorizeAttribute;

            if (attrib == null)
            {
                throw new Exception();
            }
            //assert
            attrib.Roles.ShouldContain(roles[0]);
        }
コード例 #2
0
        public void Teacher_Role_Should_Be_Able_To_Update_Grade(GradeController sut)
        {
            //arrange
            var roles = new List <string> {
                "teacher"
            };
            var unauthorizedRoles = new List <string> {
                "student", "prospect"
            };
            var method = sut.GetType().GetMethod("AddGrade");
            //act
            var attrib = method.GetCustomAttributes(typeof(AuthorizeAttribute), true).FirstOrDefault() as AuthorizeAttribute;

            if (attrib == null)
            {
                throw new Exception();
            }
            //assert
            attrib.Roles.ShouldContain(roles[0]);
            unauthorizedRoles.ForEach(r => attrib.Roles.ShouldNotContain(r));
        }