Example #1
0
        public void create_post()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            _systemRepository.Add(system);
            var controller = new RoleController(_repository, _systemRepository);
            var roleAdmin  = new Role()
            {
                RoleId = 1, SystemId = 1, Name = "admin", System = system
            };

            _repository.Add(roleAdmin);

            var result = controller.Create(new Role()
            {
                RoleId = 2, SystemId = 1, Name = "user", System = system
            });

            result.Should().BeRedirectToRouteResult().WithAction("Index").WithController("Role");
            _repository.All.Count().Should().Be(2);
            _repository.GetById(2).System.Name.Should().Be("App 1");
            _repository.GetById(2).Name.Should().Be("user");
        }
Example #2
0
        public void create_post_removing_spaces_for_the_name_field()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            _systemRepository.Add(system);
            var controller = new RoleController(_repository, _systemRepository);
            var roleAdmin  = new Role()
            {
                RoleId = 1, SystemId = 1, Name = "admin", System = system
            };

            _repository.Add(roleAdmin);

            var entity = new Role()
            {
                RoleId = 2, SystemId = 1, Name = "  user  ", System = system
            };

            controller.Create(entity);

            _repository.GetById(2).Name.Should().Be("user");
        }
Example #3
0
        public void update_role_in_system()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App"
            };

            _repository.Add(system);
            var adminRole = new Role()
            {
                RoleId = 1, Name = "Admin", SystemId = 1
            };
            var userRole = new Role()
            {
                RoleId = 2, Name = "User", SystemId = 1
            };

            var systemUpdate = _repository.GetById(1);

            systemUpdate.Roles.Add(adminRole);
            systemUpdate.Roles.Add(userRole);
            _repository.Update(systemUpdate);

            var testRole = _repository.GetById(1).Roles.FirstOrDefault(p => p.RoleId == 2);

            testRole.SystemId.Should().Be(1);
            testRole.System.Name.Should().Be("App");
        }
Example #4
0
        public void edit_post_removing_spaces_for_the_name_field()
        {
            var controller = new RoleController(_repository, _systemRepository);
            var system     = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            _systemRepository.Add(system);
            _repository.Add(new Role()
            {
                RoleId = 1, Name = "admin", SystemId = 1, System = system
            });
            _repository.Add(new Role()
            {
                RoleId = 2, Name = "user", SystemId = 1, System = system
            });
            var entity = _repository.GetById(2);

            entity.Name = "  test  ";

            controller.Edit(entity);

            _repository.GetById(2).Name.Should().Be("test");
        }
Example #5
0
        public void edit_post()
        {
            var controller = new RoleController(_repository, _systemRepository);
            var system     = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            _systemRepository.Add(system);
            _repository.Add(new Role()
            {
                RoleId = 1, Name = "admin", SystemId = 1, System = system
            });
            _repository.Add(new Role()
            {
                RoleId = 2, Name = "user", SystemId = 1, System = system
            });
            var entity = _repository.GetById(2);

            entity.Name = "test";

            var result = controller.Edit(entity);

            result.Should().BeRedirectToRouteResult().WithAction("Index").WithController("Role");
            _repository.All.Count().Should().Be(2);
            _repository.GetById(2).Name.Should().Be("test");
        }
        public void edit_post_add()
        {
            var controller = new SystemController(_repository);
            var entity     = new Domain.Entities.System()
            {
                SystemId = 0, Name = "App"
            };

            var result = controller.Edit(entity);

            result.Should().BeRedirectToRouteResult().WithAction("Index").WithController("System");
            _repository.All.Should().HaveCount(1);
            _repository.GetById(0).Name.Should().Be("App");
        }
        public void get_all()
        {
            var system = new Domain.Entities.System {
                SystemId = 1, Name = "App 1"
            };

            Repository.Add(new Method {
                MethodId = 1, Name = "MethodOne", SystemId = 1, System = system
            });
            Repository.Add(new Method {
                MethodId = 2, Name = "MethodTwo", SystemId = 1, System = system
            });

            Repository.All.Should().HaveCount(2);
        }
        public void add_method()
        {
            var system = new Domain.Entities.System {
                SystemId = 1, Name = "App 1"
            };

            Repository.Add(new Method {
                MethodId = 1, Name = "MethodOne", SystemId = 1, System = system
            });
            Repository.Add(new Method {
                MethodId = 2, Name = "MethodTwo", SystemId = 1, System = system
            });

            Repository.All.Should().HaveCount(2);
            Repository.GetById(2).Name.Should().Be("MethodTwo");
        }
        public void the_name_field_is_required()
        {
            var entity = new Domain.Entities.System()
            {
                SystemId = 2, Name = ""
            };
            var validationContext = new ValidationContext(entity, null, null);
            var validationResult  = new List <ValidationResult>();

            var valid = Validator.TryValidateObject(entity, validationContext, validationResult, true);

            valid.Should().BeFalse();
            var failure = Assert.Single(validationResult, x => x.ErrorMessage == "The Name field is required.");

            Assert.Single(failure.MemberNames, x => x == "Name");
        }
        public void edit_post_removing_spaces_for_the_name_field()
        {
            var controller = new SystemController(_repository);

            _repository.Add(new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            });
            var entity = new Domain.Entities.System()
            {
                SystemId = 0, Name = "  App 2  "
            };

            controller.Edit(entity);

            entity.Name.Trim().Should().Be(_repository.GetById(0).Name);
        }
Example #11
0
        public void get_all()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            Repository.Add(new Role()
            {
                RoleId = 1, SystemId = 1, Name = "App 1 - admin", System = system
            });
            Repository.Add(new Role()
            {
                RoleId = 2, SystemId = 1, Name = "App 1 - user", System = system
            });

            Repository.All.Should().HaveCount(2);
        }
Example #12
0
        public IActionResult Edit(Domain.Entities.System system)
        {
            if (!ModelState.IsValid)
            {
                return(View(system));
            }

            system.Name = system.Name.Trim();
            if (system.SystemId == 0)
            {
                _systemRepository.Add(system);
            }
            else
            {
                _systemRepository.Update(system);
            }

            return(RedirectToRoute("default", new { action = "Index", controller = "System" }));
        }
Example #13
0
        public void add_role()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            Repository.Add(new Role()
            {
                RoleId = 1, SystemId = 1, Name = "App 1 - admin", System = system
            });
            Repository.Add(new Role()
            {
                RoleId = 2, SystemId = 1, Name = "App 1 - user", System = system
            });

            Repository.All.Should().HaveCount(2);
            Repository.GetById(2).Name.Should().Be("App 1 - user");
        }
Example #14
0
        public void index_get_system_methods()
        {
            var systemApp1 = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };
            var systemApp2 = new Domain.Entities.System()
            {
                SystemId = 2, Name = "App 2"
            };

            _systemRepository.Add(systemApp1);
            _systemRepository.Add(systemApp2);

            var controller = new MethodController(_repository, _systemRepository);

            _repository.Add(new Method()
            {
                MethodId = 1, Name = "MethodOneInApp1", SystemId = 1
            });
            _repository.Add(new Method()
            {
                MethodId = 2, Name = "MethodOne", SystemId = 2
            });
            _repository.Add(new Method()
            {
                MethodId = 3, Name = "MethodTwo", SystemId = 2
            });
            _repository.Add(new Method()
            {
                MethodId = 4, Name = "MethodThree", SystemId = 2
            });

            var result = controller.Index(systemApp2.SystemId);

            result.Should().BeViewResult().ModelAs <IEnumerable <Method> >().Should().HaveCount(3);
            result.Should()
            .BeViewResult()
            .ModelAs <IEnumerable <Method> >()
            .First(p => p.MethodId == 3)
            .Name.Should()
            .Be("MethodTwo");
        }
        public void update_method()
        {
            var system = new Domain.Entities.System {
                SystemId = 1, Name = "App 1"
            };

            Repository.Add(new Method {
                MethodId = 1, Name = "MethodOne", SystemId = 1, System = system
            });
            Repository.Add(new Method {
                MethodId = 2, Name = "MethodTwo", SystemId = 1, System = system
            });

            var method = Repository.GetById(2);

            method.Name = "Test";
            Repository.Update(method);

            Repository.GetById(2).Name.Should().Be("Test");
        }
Example #16
0
        public void get_role_from_system_by_id()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App"
            };

            system.Roles.Add(new Role()
            {
                RoleId = 1, Name = "Admin", SystemId = 1
            });
            system.Roles.Add(new Role()
            {
                RoleId = 2, Name = "User", SystemId = 1
            });

            _repository.Add(system);

            system.Roles.FirstOrDefault(p => p.RoleId == 2).Name.Should().Be("User");
        }
Example #17
0
        public void get_roles_from_system()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App"
            };

            system.Roles.Add(new Role()
            {
                RoleId = 1, Name = "Admin", SystemId = 1
            });
            system.Roles.Add(new Role()
            {
                RoleId = 2, Name = "User", SystemId = 1
            });

            _repository.Add(system);

            _repository.GetById(1).Roles.Should().HaveCount(2);
        }
Example #18
0
        public void edit_redirect_to_action_if_role_id_does_not_exist()
        {
            var controller = new RoleController(_repository, _systemRepository);
            var system     = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            _repository.Add(new Role()
            {
                RoleId = 1, Name = "admin", SystemId = 1, System = system
            });
            _repository.Add(new Role()
            {
                RoleId = 2, Name = "user", SystemId = 1, System = system
            });

            var result = controller.Edit(3);

            result.Should().BeRedirectToRouteResult().WithAction("Index").WithController("System");
        }
        public void edit_post_update()
        {
            var controller = new SystemController(_repository);

            _repository.Add(new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            });
            _repository.Add(new Domain.Entities.System()
            {
                SystemId = 2, Name = "App 2"
            });
            var entity = new Domain.Entities.System()
            {
                SystemId = 2, Name = "Test"
            };

            var result = controller.Edit(entity);

            result.Should().BeRedirectToRouteResult().WithAction("Index").WithController("System");
            _repository.GetById(2).Name.Should().Be("Test");
        }
Example #20
0
        public void index_get_system_roles()
        {
            var systemApp1 = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };
            var systemApp2 = new Domain.Entities.System()
            {
                SystemId = 2, Name = "App 2"
            };

            _systemRepository.Add(systemApp1);
            _systemRepository.Add(systemApp2);

            var controller = new RoleController(_repository, _systemRepository);

            _repository.Add(new Role()
            {
                RoleId = 1, Name = "admin", SystemId = 1, System = systemApp1
            });
            _repository.Add(new Role()
            {
                RoleId = 2, Name = "user", SystemId = 1, System = systemApp1
            });
            _repository.Add(new Role()
            {
                RoleId = 3, Name = "adminTest", SystemId = 2, System = systemApp2
            });
            _repository.Add(new Role()
            {
                RoleId = 4, Name = "userTest", SystemId = 2, System = systemApp2
            });

            var result = controller.Index(2);

            result.Should().BeViewResult().ModelAs <RoleModel>().Roles.Should().HaveCount(2);
            result.Should().BeViewResult().ModelAs <RoleModel>().System.Name.Should().Be("App 2");
            result.Should().BeViewResult().ModelAs <RoleModel>().Roles.First(p => p.RoleId == 4).Name.Should().Be("userTest");
        }
Example #21
0
        public void InitializeVariables(Domain.Entities.System system)
        {
            nju = new DomainEntity(Guid.NewGuid(), njuadmin, new Domain.ValueObjects.Resources(10, 20, 30), system);
            pku = new DomainEntity(Guid.NewGuid(), fc, new Domain.ValueObjects.Resources(20, 30, 40), system);
            cjd.JoinDomain(nju);
            cjd.JoinDomain(pku);
            lq.JoinDomain(nju);
            njuadmin.JoinDomain(nju);
            fc.JoinDomain(pku);

            lqproject = new Project(Guid.NewGuid(), lq, nju, new Domain.ValueObjects.Resources(5, 10, 20));
            fcproject = new Project(Guid.NewGuid(), fc, pku, new Domain.ValueObjects.Resources(10, 30, 40));

            lq67project  = new UserProjectAssignment(Guid.NewGuid(), lq, lqproject, new Domain.ValueObjects.Resources(4, 8, 10));
            cjd67project = new UserProjectAssignment(Guid.NewGuid(), cjd, lqproject, new Domain.ValueObjects.Resources(1, 2, 10));
            fcfcproject  = new UserProjectAssignment(Guid.NewGuid(), fc, fcproject, new Domain.ValueObjects.Resources(5, 15, 20));

            cjdlqTokenClaims       = new TokenClaims(false, false, cjd.Id, nju.Id, lqproject.Id, cjd67project.Id, UserRole.Member);
            lqlqTokenClaims        = new TokenClaims(false, false, lq.Id, nju.Id, lqproject.Id, lq67project.Id, UserRole.Admin);
            njuadminnjuTokenClaims = new TokenClaims(false, false, njuadmin.Id, nju.Id, null, null, UserRole.Admin);
            fcfcTokenClaims        = new TokenClaims(false, false, fc.Id, pku.Id, fcproject.Id, fcfcproject.Id, UserRole.Admin);
            systemTokenClaims      = new TokenClaims(true, false, SystemUserId, nju.Id, null, null, UserRole.Admin);
        }
Example #22
0
        public void add_roles_to_system()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App"
            };

            _repository.Add(system);
            var adminRole = new Role()
            {
                RoleId = 1, Name = "Admin", SystemId = 1
            };
            var userRole = new Role()
            {
                RoleId = 2, Name = "User", SystemId = 1
            };

            _repository.GetById(1).Roles.Add(adminRole);
            _repository.GetById(1).Roles.Add(userRole);

            system.Roles.FirstOrDefault(p => p.RoleId == 2).Name.Should().Be("User");
            _repository.GetById(1).Roles.Should().HaveCount(2);
        }
Example #23
0
        public void remove_post()
        {
            var controller = new RoleController(_repository, _systemRepository);
            var system     = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            _systemRepository.Add(system);
            _repository.Add(new Role()
            {
                RoleId = 1, Name = "admin", SystemId = 1, System = system
            });
            _repository.Add(new Role()
            {
                RoleId = 2, Name = "user", SystemId = 1, System = system
            });

            var result = controller.Delete(2);

            result.Should().BeRedirectToRouteResult().WithAction("Index").WithController("Role");
            _repository.All.Should().HaveCount(1);
        }
Example #24
0
        public void update_role()
        {
            var system = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            Repository.Add(new Role()
            {
                RoleId = 1, SystemId = 1, Name = "App 1 - admin", System = system
            });
            Repository.Add(new Role()
            {
                RoleId = 2, SystemId = 1, Name = "App 1 - user", System = system
            });

            var role = Repository.GetById(2);

            role.Name = "Test";
            Repository.Update(role);

            Repository.GetById(2).Name.Should().Be("Test");
        }
Example #25
0
        public void edit_get_role_by_id()
        {
            var controller = new RoleController(_repository, _systemRepository);
            var system     = new Domain.Entities.System()
            {
                SystemId = 1, Name = "App 1"
            };

            _systemRepository.Add(system);
            _repository.Add(new Role()
            {
                RoleId = 1, Name = "admin", SystemId = 1, System = system
            });
            _repository.Add(new Role()
            {
                RoleId = 2, Name = "user", SystemId = 1, System = system
            });

            var result = controller.Edit(2);

            result.Should().BeViewResult().ModelAs <Role>().System.Name.Should().Be("App 1");
            result.Should().BeViewResult().ModelAs <Role>().Name.Should().Be("user");
        }