Ejemplo n.º 1
0
        public async Task CreateOrgUnit_Test()
        {
            CreateOrgUnitDto createOrgUnitDto = new CreateOrgUnitDto()
            {
                ParentId    = null,
                DisplayName = "Ou Test"
            };
            var orgUnitDto = await _orgUnitAppService.CreateAsync(createOrgUnitDto);

            await UsingDbContextAsync(async context =>
            {
                var testOu      = await context.OrganizationUnits.FirstOrDefaultAsync(ou => ou.Id == orgUnitDto.Id);
                testOu.TenantId = 1;
                testOu.DisplayName.ShouldBe("Ou Test");
                testOu.Code.ShouldBe("00001");
            });
        }
Ejemplo n.º 2
0
        private async Task CreateComplexRoleAndOrgUnit()
        {
            // Role 1
            var createRole1Dto = new CreateRoleDto()
            {
                Name               = "Role1",
                DisplayName        = "Role1",
                Description        = "Role1 for test",
                GrantedPermissions = new List <string>()
                {
                    PermissionNames.Pages_Roles
                }
            };
            var role1Dto = await _roleAppService.CreateAsync(createRole1Dto);

            // Role 2
            var createRole2Dto = new CreateRoleDto()
            {
                Name               = "Role2",
                DisplayName        = "Role2",
                Description        = "Role2 for test",
                GrantedPermissions = new List <string>()
                {
                    PermissionNames.Pages_Users, PermissionNames.Pages_Roles
                }
            };
            var role2Dto = await _roleAppService.CreateAsync(createRole2Dto);

            // Role 2
            var createRole3Dto = new CreateRoleDto()
            {
                Name               = "Role3",
                DisplayName        = "Role3",
                Description        = "Role3 for test",
                GrantedPermissions = new List <string>()
                {
                    PermissionNames.Pages_Roles
                }
            };
            var role3Dto = await _roleAppService.CreateAsync(createRole3Dto);

            // OrgUnit with Role1 and Role2
            CreateOrgUnitDto createOrgUnitDto = new CreateOrgUnitDto()
            {
                ParentId    = null,
                DisplayName = "Ou Test"
            };
            var orgUnitDto = await _orgUnitAppService.CreateAsync(createOrgUnitDto);

            SetOrgUnitRoleDto setOrgUnitRole1Dto = new SetOrgUnitRoleDto()
            {
                OrgUnitId = orgUnitDto.Id,
                RoleId    = role1Dto.Id
            };
            await _orgUnitAppService.AddRoleToOrgUnitAsync(setOrgUnitRole1Dto);

            SetOrgUnitRoleDto setOrgUnitRole2Dto = new SetOrgUnitRoleDto()
            {
                OrgUnitId = orgUnitDto.Id,
                RoleId    = role2Dto.Id
            };
            await _orgUnitAppService.AddRoleToOrgUnitAsync(setOrgUnitRole2Dto);
        }