public void CreatePermission_Action_Fails() { // Arrange var permissionDto = TestHelper.PermissionDto(); GenericServiceResponse <bool> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.PermissionService.CreatePermission(permissionDto)).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new CreatePermission <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(permissionDto); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsFalse(result.Success); }
public void Delete() { var permissionId = Guid.Empty; { this.BeginTransaction(); var cmd = new CreatePermission("发布文章2"); var permission = cmd.Execute(); permissionId = permission.Id; this.Commit(); } { var cmd = new DeletePermission(permissionId); cmd.Execute(); } { this.BeginTransaction(); var permission = PermissionCommon.FindById(permissionId, QueryLevel.None); Assert.IsTrue(permission.IsEmpty()); this.Commit(); } }
public CreatePermission ToCreatePermission() { var c = new CreatePermission(); c.PermissionId = this.PermissionId; c.ParentPermissionId = this.ParentPermissionId; c.Name = this.PermissionName; return(c); }
private void AddPermission() { var cmd = new CreatePermission("发布文章") { MarkedCode = "addArticle", Description = "站点编辑人员可以发布文章" }; var permission = cmd.Execute(); this.Fixture.Add(permission); }
protected override DTObject DynamicInvoke(dynamic arg) { var cmd = new CreatePermission(arg.Name) { Description = arg.Description, MarkedCode = arg.MarkedCode }; var permisson = cmd.Execute(); return(DTObject.CreateReusable("{id}", permisson)); }
public void Empty_permission_name_is_not_valid_for_permission_creation() { var model = new CreatePermission { Module = TestDataGenerator.GetRandomString(), Name = null }; var result = _authQueries.GetValidationResult(model); result.IsValid.Should().BeFalse(); result.Errors.Single().ErrorMessage.Should().Be(ErrorsCodes.ModuleOrPermissionNameIsEmpty.ToString()); }
public void Can_create_permission() { var model = new CreatePermission { Module = TestDataGenerator.GetRandomString(), Name = TestDataGenerator.GetRandomString() }; _authCommands.CreatePermission(model); var permission = _authRepository.Permissions.SingleOrDefault(p => p.Name == model.Name && p.Module == model.Module); permission.Should().NotBeNull(); }
public void Duplicate_permission_and_module_name_combination_is_not_valid_for_permission_creation() { var model = new CreatePermission { Module = "Test", Name = "Test" }; _authCommands.CreatePermission(model); var result = _authQueries.GetValidationResult(model); result.IsValid.Should().BeFalse(); result.Errors.Single().ErrorMessage.Should().Be(ErrorsCodes.DuplicatePermission.ToString()); }
public void CreatePermission(CreatePermission model) { var result = _authQueries.GetValidationResult(model); if (result.IsValid == false) { throw new ApplicationException(result.Errors.First().ErrorMessage); } var permission = new Permission { Id = Guid.NewGuid(), Name = model.Name, Module = model.Module }; _repository.Permissions.Add(permission); _repository.SaveChanges(); }
// POST: api/Permission create permission public async Task <HandleResult> Post([FromBody] CreatePermissionDto dto) { var command = new CreatePermission( ObjectId.GenerateNewStringId(), dto.AppSystemId, ObjectId.GenerateNewStringId(), dto.Name, dto.PermissionType, dto.IsVisible, dto.ParentPermission, dto.PermissionUrl, dto.Sort, dto.Describe, dto.ReMark); var result = await ExecuteCommandAsync(command); if (result.IsSuccess()) { return(HandleResult.FromSuccess("创建成功", command.Code)); } return(HandleResult.FromFail(result.GetErrorMessage())); }
public async Task<ActionResult> Index() { serviceId = "AC"; serviceSort = 10000; if (serviceDao.Entities.Where(m => m.Id == serviceId).Count() > 0) { return Content("数据库中已经存在数据库,不需要重新生成。"); } //部门 CreateDepartment(); var service = new CreateService(serviceId, "统一授权中心", 1, "http://int.zhongyi-itl.com/"); await this.commandService.Execute(service); var user = new CreateUser("sysadmin", "系统管理员", "Sysadmin", "*****@*****.**", "15817439909", "系统管理员"); await this.commandService.Execute(user); var role = new CreateRole("系统管理员", 0); await this.commandService.Execute(role); await this.commandService.Execute(new SetUserRoles(user.AggregateRootId, new string[] { role.AggregateRootId })); var menu = new CreateMenu("统一授权中心", (int)MenuType.Web, "", "", serviceSort); await this.commandService.Execute(menu); var menuRoot = menu.AggregateRootId; var module = new CreateModule(serviceId, "System", "系统管理", serviceSort); await this.commandService.Execute(module); var moduleId = module.AggregateRootId; menu = new CreateMenu("系统管理", (int)MenuType.Web, "", "", serviceSort + 10, menuRoot); await this.commandService.Execute(menu); var menuId = menu.AggregateRootId; string moduleId2 = await QuickModule("Sys", "Department", "部门信息", moduleId, menuId, 11); var permission = new CreatePermission("DepartmentUser", "设置用户", moduleId2); await this.commandService.Execute(permission); //角色管理 module = new CreateModule(serviceId, "Role", "角色管理", serviceSort + 16, moduleId); await this.commandService.Execute(module); permission = new CreatePermission("ViewRole", "查看", module.AggregateRootId); await this.commandService.Execute(permission); var viewRolePermissionId = permission.AggregateRootId; menu = new CreateMenu("角色管理", (int)MenuType.Web, "Sys/RoleList.aspx", "", serviceSort + 16, menuId, permission.AggregateRootId); await this.commandService.Execute(menu); permission = new CreatePermission("NewRole", "新增", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("ModifyRole", "编辑", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("DeleteRole", "删除", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("PermissionRole", "分配权限", module.AggregateRootId); await this.commandService.Execute(permission); await this.commandService.Execute(new SetRolePermissions(role.AggregateRootId, new string[] { viewRolePermissionId, permission.AggregateRootId })); //用户管理 moduleId2 = await QuickModule("Sys", "User", "用户管理", moduleId, menuId, 21); await this.commandService.Execute(permission); permission = new CreatePermission("ChangePwdUser", "修改密码", moduleId2); await this.commandService.Execute(permission); permission = new CreatePermission("RoleUser", "分配角色", moduleId2); await this.commandService.Execute(permission); await QuickModule("Sys", "Service", "服务管理", moduleId, menuId, 26); await QuickModule("Sys", "Module", "模块管理", moduleId, menuId, 31); await QuickModule("Sys", "Menu", "菜单管理", moduleId, menuId, 36); await QuickModule("Sys", "Authority", "权限管理", moduleId, menuId, 41); CreateRole(); return Content(""); }
private async void QuickFileModule(string moduleCode, string moduleName, string moduleParentId, string menuParentId, int sort) { var module = new CreateModule(serviceId, moduleCode, moduleName, serviceSort + sort, moduleParentId); await this.commandService.Execute(module); var permission = new CreatePermission("Use" + moduleCode, "使用", module.AggregateRootId); await this.commandService.Execute(permission); var menu = new CreateMenu(moduleName, (int)MenuType.Web, "HardDisk/" + moduleCode + "aspx", "", serviceSort + sort, menuParentId, permission.AggregateRootId); await this.commandService.Execute(menu); permission = new CreatePermission("Upload" + moduleCode, "上传文件", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("ModifyFile" + moduleCode, "编辑文件名", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("DeleteFile" + moduleCode, "删除文件", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("MoveFile" + moduleCode, "移动文件", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("NewFolder" + moduleCode, "新建文件夹", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("ModifyFolder" + moduleCode, "编辑文件夹", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("DeleteFolder" + moduleCode, "删除文件夹", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("MoveFolder" + moduleCode, "移动文件夹", module.AggregateRootId); await this.commandService.Execute(permission); }
//private async void QuickModuleGroup(string moduleCode, string moduleName, string moduleParentId, string menuParentId, int sort, out string moduleId, out string menuId) //{ // var module = new CreateModule(serviceId, moduleCode, moduleName, serviceSort + sort, moduleParentId); // await this.commandService.Execute(module); // moduleId = module.AggregateRootId; // var menu = new CreateMenu(moduleName, (int)MenuType.Web, "", "", serviceSort + sort, menuParentId); // await this.commandService.Execute(menu); // menuId = menu.AggregateRootId; //} private async Task<string> QuickModule(string folder, string moduleCode, string moduleName, string moduleParentId, string menuParentId, int sort, bool canExport = false) { var module = new CreateModule(serviceId, moduleCode, moduleName, serviceSort + sort, moduleParentId); var result = await this.commandService.Execute(module); if (result.Status == CommandStatus.Success) { var permission = new CreatePermission("View" + moduleCode, "查看", module.AggregateRootId); result = await this.commandService.Execute(permission); if (result.Status == CommandStatus.Success) { var menu = new CreateMenu(moduleName, (int)MenuType.Web, folder + "/" + moduleCode + "List.aspx", "", serviceSort + sort, menuParentId, permission.AggregateRootId); await this.commandService.Execute(menu); } permission = new CreatePermission("New" + moduleCode, "新增", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("Modify" + moduleCode, "编辑", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("Delete" + moduleCode, "删除", module.AggregateRootId); await this.commandService.Execute(permission); if (canExport) { permission = new CreatePermission("Upload" + moduleCode, "上传", module.AggregateRootId); await this.commandService.Execute(permission); permission = new CreatePermission("Download" + moduleCode, "下载", module.AggregateRootId); await this.commandService.Execute(permission); } } return module.AggregateRootId; }
public ValidationResult GetValidationResult(CreatePermission model) { var validator = new CreatePermissionValidator(_repository); return(validator.Validate(model)); }