Beispiel #1
0
        public void SeedPermissions_BranchesWithoutId()
        {
            RoleView view = ObjectFactory.CreateRoleView();

            service.SeedPermissions(view);

            IEnumerable <JsTreeNode> nodes    = view.Permissions.Nodes;
            IEnumerable <JsTreeNode> branches = GetBranchNodes(nodes);

            Assert.Empty(branches.Where(branch => branch.Id != null));
        }
Beispiel #2
0
        public void SeedPermissions_LeafsWithId()
        {
            RoleView view = ObjectFactory.CreateRoleView();

            service.SeedPermissions(view);

            IEnumerable <JsTreeNode> nodes = view.Permissions.Nodes;
            IEnumerable <JsTreeNode> leafs = GetLeafNodes(nodes);

            Assert.Empty(leafs.Where(leaf => leaf.Id == null));
        }
        public RolesControllerTests()
        {
            validator = Substitute.For <IRoleValidator>();
            service   = Substitute.For <IRoleService>();

            role = ObjectFactory.CreateRoleView();

            controller = Substitute.ForPartsOf <RolesController>(validator, service);
            controller.ControllerContext           = new ControllerContext();
            controller.ControllerContext.RouteData = new RouteData();
        }
Beispiel #4
0
        public void Edit_EditsRole()
        {
            RoleView expected = service.GetView(role.Id);

            expected.Name += "EditedName";
            service.Edit(expected);

            Role actual = context.Set <Role>().SingleOrDefault();

            Assert.AreEqual(expected.EntityDate, actual.EntityDate);
            Assert.AreEqual(expected.Name, actual.Name);
        }
Beispiel #5
0
        public ActionResult Create([ModelBinder(typeof(RoleViewModelBinder))] RoleView RoleView)//[ModelBinder(typeof(RoleViewModelBinder))],string[] selectedAvailableFunctions
        {
            UserAccessRepository rep = new UserAccessRepository();

            // Get the list of roles in the system
            List <AvailableFunction> allFunctions = rep.GetAllAvailableFunctions();

            RoleView.Roles = rep.GetAllRoles();



            if (ModelState.IsValid)
            {
                Role newRole = new Role(Guid.NewGuid(), RoleView.Name, RoleView.Description);
                newRole.AvailableFunctions = new List <AvailableFunction>();

                for (int i = 0; i < allFunctions.Count(); i++)
                {
                    foreach (var item in RoleView.AvailableFunctions)
                    {
                        if (Guid.Parse(item.Value).Equals(allFunctions[i].ID))
                        {
                            newRole.AvailableFunctions.Add(new AvailableFunction(Guid.Parse(allFunctions[i].ID.ToString()), allFunctions[i].FunctionName));
                        }
                    }
                }

                if (rep.CreateRole(newRole) == true)
                {
                    return(RedirectToAction("Create", "Roles", new { message = "Your role '" + RoleView.Name + "' was created successfully!" }));
                }
                else
                {
                    return(RedirectToAction("Create", "Roles", new { message = "There was an error creating your role. Please contact your administrator." }));
                }
            }

            RoleView.Roles = rep.GetAllRoles();

            if (RoleView.AvailableFunctions == null)
            {
                RoleView.AvailableFunctions = new List <CheckBoxListInfo>();
            }

            RoleView.AvailableFunctions.Clear();

            foreach (var item in allFunctions)
            {
                RoleView.AvailableFunctions.Add(new CheckBoxListInfo(item.ID.ToString(), item.FunctionName, false));
            }

            return(View("Create", RoleView));
        }
Beispiel #6
0
    public void cardClickEvent(RoleView view)
    {
        //新手引导不能点
        if (GuideManager.Instance.isLessThanStep(GuideGlobal.NEWOVERSID))
        {
            MaskWindow.UnlockUI();
            return;
        }
        GetPlayerCardInfoFPort fport = FPortManager.Instance.getFPort("GetPlayerCardInfoFPort") as GetPlayerCardInfoFPort;

        fport.getCard(uid, view.card.uid, null);
    }
 private object OnOpenRolePanel(params object[] objs)
 {
     if (roleView == null)
     {
         roleView = new RoleView();
     }
     else
     {
         roleView.Show();
     }
     return(null);
 }
Beispiel #8
0
        public void Edit_EditsRolePrivileges()
        {
            RoleView roleView = service.GetView(role.Id);

            roleView.PrivilegesTree.SelectedIds = roleView.PrivilegesTree.SelectedIds.Take(1).ToList();
            service.Edit(roleView);

            IEnumerable <String> expected = roleView.PrivilegesTree.SelectedIds;
            IEnumerable <String> actual   = context.Set <Role>().SingleOrDefault().RolePrivileges.Select(rolePriv => rolePriv.PrivilegeId).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
        public void Create_Role()
        {
            RoleView view = ObjectsFactory.CreateRoleView(role.Id + 1);

            service.Create(view);

            Role     actual   = Assert.Single(context.Set <Role>(), model => model.Id != role.Id);
            RoleView expected = view;

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Title, actual.Title);
        }
Beispiel #10
0
        public void CanCreate_UsedTitle_ReturnsFalse()
        {
            RoleView view = ObjectsFactory.CreateRoleView(1);

            view.Title = role.Title.ToLower();

            Boolean canCreate = validator.CanCreate(view);

            Assert.False(canCreate);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <RoleView>("UniqueTitle"), validator.ModelState["Title"].Errors.Single().ErrorMessage);
        }
Beispiel #11
0
        public ActionResult Edit(RoleView role)
        {
            if (!Validator.CanEdit(role))
            {
                Service.SeedPrivilegesTree(role);
                return(View(role));
            }

            Service.Edit(role);

            return(RedirectIfAuthorized("Index"));
        }
Beispiel #12
0
        public void GetView_ReturnsViewById()
        {
            service.When(sub => sub.SeedPermissions(Arg.Any <RoleView>())).DoNotCallBase();

            RoleView expected = Mapper.Map <RoleView>(role);
            RoleView actual   = service.GetView(role.Id);

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.NotEmpty(actual.Permissions.SelectedIds);
            Assert.Equal(expected.Title, actual.Title);
            Assert.Equal(expected.Id, actual.Id);
        }
        public void CanEdit_UsedTitle_ReturnsFalse()
        {
            RoleView view = ObjectFactory.CreateRoleView(2);

            view.Title = role.Title.ToLower();

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueTitle, validator.ModelState["Title"].Errors.Single().ErrorMessage);
        }
Beispiel #14
0
        public void Create_Role()
        {
            RoleView view = ObjectFactory.CreateRoleView(2);

            service.Create(view);

            Role     actual   = context.Set <Role>().AsNoTracking().Single(model => model.Id != role.Id);
            RoleView expected = view;

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Title, actual.Title);
        }
        public void GetView_SeedsPrivilegesTree()
        {
            service.When(sub => sub.SeedPrivilegesTree(Arg.Any <RoleView>())).DoNotCallBase();
            Role role = ObjectFactory.CreateRole();

            context.Set <Role>().Add(role);
            context.SaveChanges();

            RoleView roleView = service.GetView(role.Id);

            service.Received().SeedPrivilegesTree(roleView);
        }
Beispiel #16
0
        public void IsSpecified_Null_ReturnsFalse()
        {
            RoleView view = new RoleView();

            Boolean isSpecified = validator.BaseIsSpecified(view, role => role.Title);
            String  message     = String.Format(Validations.Required, ResourceProvider.GetPropertyTitle <RoleView, String>(role => role.Title));

            Assert.False(isSpecified);
            Assert.Empty(validator.Alerts);
            Assert.Single(validator.ModelState);
            Assert.Equal(message, validator.ModelState["Title"].Errors.Single().ErrorMessage);
        }
        public void IsSpecified_Null_ReturnsFalse()
        {
            RoleView view = new RoleView();

            Boolean isSpecified = validator.BaseIsSpecified(view, role => role.Title);
            String  message     = Validation.For("Required", Resource.ForProperty <RoleView, String?>(role => role.Title));

            Assert.False(isSpecified);
            Assert.Empty(validator.Alerts);
            Assert.Single(validator.ModelState);
            Assert.Equal(message, validator.ModelState[nameof(RoleView.Title)].Errors.Single().ErrorMessage);
        }
Beispiel #18
0
        public ActionResult Create([Bind(Exclude = "Id")] RoleView role)
        {
            if (!Validator.CanCreate(role))
            {
                Service.SeedPrivilegesTree(role);
                return(View(role));
            }

            Service.Create(role);

            return(RedirectIfAuthorized("Index"));
        }
        public void GetAs_ReturnsModelAsDestinationModelById()
        {
            context.Add(model);
            context.SaveChanges();

            RoleView expected = Mapper.Map <RoleView>(model);
            RoleView actual   = unitOfWork.GetAs <Role, RoleView>(model.Id) !;

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Title, actual.Title);
            Assert.Equal(expected.Id, actual.Id);
        }
        public void Delete(RoleView roleView, long structureId)
        {
            var role = _dbContext.Roles.Include("Rule").Single(r => r.ContainerPrototypeStructureId == structureId &&
                                                                    r.ContainerPrototypeName ==
                                                                    roleView.ContainerPrototypeName &&
                                                                    r.RoleTypeName == roleView.RoleTypeName &&
                                                                    r.WorkSpaceTypeName == roleView.WorkSpaceTypeName);

            _dbContext.Roles.Remove(role);

            _dbContext.SaveChanges();
        }
Beispiel #21
0
        public ActionResult Edit(RoleView role)
        {
            if (!Validator.CanEdit(role))
            {
                Service.SeedPermissions(role);

                return(View(role));
            }

            Service.Edit(role);

            return(RedirectToAction("Index"));
        }
 public string Update(RoleView obj)
 {
     try
     {
         _app.Update(obj);
     }
     catch (Exception ex)
     {
         Result.Code    = 500;
         Result.Message = ex.InnerException?.Message ?? ex.Message;
     }
     return(JsonHelper.Instance.Serialize(Result));
 }
Beispiel #23
0
        public void CanCreate_AddsErrorMessageThenCanNotCreateWithAlreadyTakenRoleName()
        {
            RoleView roleView = ObjectFactory.CreateRoleView();

            roleView.Name = role.Name.ToLower();
            roleView.Id  += "OtherIdValue";
            validator.CanCreate(roleView);

            String actual   = validator.ModelState["Name"].Errors[0].ErrorMessage;
            String expected = Validations.RoleNameIsAlreadyTaken;

            Assert.AreEqual(expected, actual);
        }
        public ActionResult Create(RoleView role)
        {
            if (!Validator.CanCreate(role))
            {
                Service.Seed(role.Permissions);

                return(View(role));
            }

            Service.Create(role);

            return(RedirectToAction(nameof(Index)));
        }
        public Response Update(RoleView obj)
        {
            var result = new Response();

            try {
                _app.Update(obj);
            } catch (Exception ex) {
                result.Code    = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return(result);
        }
Beispiel #26
0
        public ActionResult Create(RoleView role)
        {
            if (!Validator.CanCreate(role))
            {
                Service.SeedPermissions(role);

                return(View(role));
            }

            Service.Create(role);

            return(RedirectIfAuthorized("Index"));
        }
Beispiel #27
0
        public RolesControllerTests()
        {
            validator = Substitute.For <IRoleValidator>();
            service   = Substitute.For <IRoleService>();

            role = ObjectsFactory.CreateRoleView();

            controller = Substitute.ForPartsOf <RolesController>(validator, service);
            controller.ControllerContext.HttpContext = Substitute.For <HttpContext>();
            controller.TempData = Substitute.For <ITempDataDictionary>();
            controller.ControllerContext.RouteData = new RouteData();
            controller.Url = Substitute.For <IUrlHelper>();
        }
Beispiel #28
0
        public ActionResult Create([BindExcludeId] RoleView role)
        {
            if (!Validator.CanCreate(role))
            {
                Service.SeedPermissions(role);

                return(View(role));
            }

            Service.Create(role);

            return(RedirectToAction("Index"));
        }
 public string Add(RoleView obj)
 {
     try
     {
         App.Add(obj);
     }
     catch (Exception ex)
     {
         Result.Code    = 500;
         Result.Message = ex.Message;
     }
     return(JsonHelper.Instance.Serialize(Result));
 }
        public void Create_CreatesRole()
        {
            RoleView view = ObjectFactory.CreateRoleView();

            service.Create(view);

            Role     actual   = context.Set <Role>().AsNoTracking().SingleOrDefault();
            RoleView expected = view;

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Title, actual.Title);
            Assert.Equal(expected.Id, actual.Id);
        }
Beispiel #31
0
 public ActionResult AddRole(RoleView model)
 {
     try
     {
         App.Add(model);
     }
     catch (Exception ex)
     {
         Result.Code    = 500;
         Result.Message = ex.Message;
     }
     return(View("RoleEdit"));
 }