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"); }
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"); }
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"); }
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"); }
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); }
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); }
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" })); }
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"); }
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"); }
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"); }
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); }
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"); }
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"); }
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); }
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); }
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); }
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"); }
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"); }