public void T2_Index_Get_RetrievesAllPermissionsFromRepository()
        {
            // Arrange
            Permission Permission1 = GetPermissionNamed(1, "Howth");
            Permission Permission2 = GetPermissionNamed(2, "Donnybrook");
            InMemoryPermissionRepository repository = new InMemoryPermissionRepository();
            repository.Add(Permission1);
            repository.Add(Permission2);
            var controller = GetHomeController(repository);

            // Act
            var result = controller.Index();

            // Assert
            var model = (IEnumerable<Permission>)result.ViewData.Model;
            CollectionAssert.Contains(model.ToList(), Permission1);
            CollectionAssert.Contains(model.ToList(), Permission2);
        }
        public void T5_Create_Post_PutsValidPermissionIntoRepository()
        {
            // Arrange
            InMemoryPermissionRepository repository = new InMemoryPermissionRepository();
            HomeController controller = GetHomeController(repository);
            Permission Permission = GetPermissionID_1();

            // Act
            controller.Create(Permission);

            // Assert
            IEnumerable<Permission> Permissions = repository.GetAllPermissions();
            Assert.IsTrue(Permissions.Contains(Permission));
        }
        public void T7_Check_for_Invalid_Characters()
        {
            List<Permission> permrecs = new List<Permission>();
            InMemoryPermissionRepository repository = new InMemoryPermissionRepository();
            foreach (Permission r in permrecs)
            {
                repository.Add(r);
            }

            // Arrange
            Regex pattern = new Regex("^[^\u003c\u003e\u0026\u0022\u0027\u002f]{1,2000}$");

            var controller = GetHomeController(repository);

            // Act
            var result = controller.Index();

            // Assert
            var model = (IEnumerable<Permission>)result.ViewData.Model;

            string modelString = System.Convert.ToString(model);
            StringAssert.Matches(modelString, pattern);
        }
        public void T9_Illegal_Record()
        {
            // Arrange
            Regex pattern = new Regex("^[^\u003c\u003e\u0026\u0022\u0027\u002f]{1,2000}$");
            Permission PermissionIllegal = GetPermissionIllegal();
            InMemoryPermissionRepository repository = new InMemoryPermissionRepository();
            repository.Add(PermissionIllegal);

            var controller = GetHomeController(repository);

            // Act
            var result = controller.Index();

            // Assert
            var model = (IEnumerable<Permission>)result.ViewData.Model;
            string modelString = System.Convert.ToString(model.ToList());
            StringAssert.Matches(modelString, pattern);
        }
        public void T6_Create_Post_ReturnsViewIfRepositoryThrowsException()
        {
            // Arrange
            InMemoryPermissionRepository repository = new InMemoryPermissionRepository();
            Exception exception = new Exception();
            repository.ExceptionToThrow = exception;
            HomeController controller = GetHomeController(repository);
            Permission model = GetPermissionID_1();

            // Act
            var result = (ViewResult)controller.Create(model);

            // Assert
            Assert.AreEqual("Create", result.ViewName);
            ModelState modelState = result.ViewData.ModelState[""];
            Assert.IsNotNull(modelState);
            Assert.IsTrue(modelState.Errors.Any());
            Assert.AreEqual(exception, modelState.Errors[0].Exception);
        }