Beispiel #1
0
        public async Task MoveAsync()
        {
            var ou1 = await _organizationUnitRepository.GetAsync("OU1");

            var ou2 = await _organizationUnitRepository.GetAsync("OU2");

            await _organizationUnitManager.MoveAsync(ou1.Id, ou2.Id);

            ou1 = await _organizationUnitRepository.GetAsync("OU1");

            ou1.ParentId.ShouldBe(ou2.Id);
            ou1.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2));

            var ou11 = await _organizationUnitRepository.GetAsync("OU11");

            ou11.ParentId.ShouldBe(ou1.Id);
            ou11.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1));

            var ou111 = await _organizationUnitRepository.GetAsync("OU111");

            ou111.ParentId.ShouldBe(ou11.Id);
            ou111.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 1));

            var ou112 = await _organizationUnitRepository.GetAsync("OU112");

            ou112.ParentId.ShouldBe(ou11.Id);
            ou112.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 2));

            var ou12 = await _organizationUnitRepository.GetAsync("OU12");

            ou12.ParentId.ShouldBe(ou1.Id);
            ou12.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 2));
        }
Beispiel #2
0
        public virtual async Task <string> GetNextChildCodeAsync(Guid?parentId)
        {
            var lastChild = await GetLastChildOrNullAsync(parentId);

            if (lastChild != null)
            {
                return(OrganizationUnit.CalculateNextCode(lastChild.Code));
            }

            var parentCode = parentId != null
                ? await GetCodeOrDefaultAsync(parentId.Value)
                : null;

            return(OrganizationUnit.AppendCode(
                       parentCode,
                       OrganizationUnit.CreateCode(1)
                       ));
        }
        /* Creates OU tree as shown below:
         *
         * - OU1
         *   - OU11
         *     - OU111
         *     - OU112
         *   - OU12
         * - OU2
         *   - OU21
         */
        private async Task AddOrganizationUnits()
        {
            var ou1 = await CreateOU("OU1", OrganizationUnit.CreateCode(1));

            var ou11 = await CreateOU("OU11", OrganizationUnit.CreateCode(1, 1), ou1.Id);

            _ou112 = await CreateOU("OU112", OrganizationUnit.CreateCode(1, 1, 2), ou11.Id);

            var ou12 = await CreateOU("OU12", OrganizationUnit.CreateCode(1, 2), ou1.Id);

            var ou2 = await CreateOU("OU2", OrganizationUnit.CreateCode(2));

            var ou21 = await CreateOU("OU21", OrganizationUnit.CreateCode(2, 1), ou2.Id);

            _ou111      = new OrganizationUnit(_guidGenerator.Create(), "OU111", ou11.Id);
            _ou111.Code = OrganizationUnit.CreateCode(1, 1, 1);
            _ou111.AddRole(_moderatorRole.Id);
            _ou111.AddRole(_managerRole.Id);
            await _organizationUnitRepository.InsertAsync(_ou111);
        }
 public async Task GetAllChildrenWithParentCodeAsync()
 {
     (await _organizationUnitRepository.GetAllChildrenWithParentCodeAsync(OrganizationUnit.CreateCode(0),
                                                                          _guidGenerator.Create())).ShouldNotBeNull();
 }