Пример #1
0
        protected IReadOnlyCollection <ClaimSetResourceClaim> SetupParentResourceClaimsWithChildren(ClaimSet testClaimSet, Application testApplication, int resourceClaimCount = 5, int childResourceClaimCount = 3)
        {
            var actions = ActionName.GetAll().Select(action => new Action {
                ActionName = action.Value, ActionUri = action.Value
            }).ToList();

            Save(actions.Cast <object>().ToArray());

            var parentResourceClaims = Enumerable.Range(1, resourceClaimCount).Select(parentIndex => new ResourceClaim
            {
                ClaimName    = $"TestParentResourceClaim{parentIndex}",
                DisplayName  = $"TestParentResourceClaim{parentIndex}",
                ResourceName = $"TestParentResourceClaim{parentIndex}", Application = testApplication
            }).ToList();

            var childResourceClaims = parentResourceClaims.SelectMany(x => Enumerable.Range(1, childResourceClaimCount)
                                                                      .Select(childIndex => new ResourceClaim
            {
                ClaimName           = $"TestChildResourceClaim{childIndex}",
                DisplayName         = $"TestChildResourceClaim{childIndex}",
                ResourceName        = $"TestChildResourceClaim{childIndex}",
                Application         = testApplication,
                ParentResourceClaim = x
            })).ToList();

            Save(childResourceClaims.Cast <object>().ToArray());

            var claimSetResourceClaims = Enumerable.Range(1, resourceClaimCount)
                                         .Select(index => parentResourceClaims[index - 1]).Select(parentResource => new ClaimSetResourceClaim
            {
                ResourceClaim = parentResource,
                Action        = actions.Single(x => x.ActionName == ActionName.Create.Value), ClaimSet = testClaimSet
            }).ToList();

            var childResources = parentResourceClaims.SelectMany(x => childResourceClaims
                                                                 .Where(child => child.ParentResourceClaimId == x.ResourceClaimId)
                                                                 .Select(child => new ClaimSetResourceClaim
            {
                ResourceClaim = child,
                Action        = actions.Single(a => a.ActionName == ActionName.Create.Value),
                ClaimSet      = testClaimSet
            }).ToList()).ToList();

            claimSetResourceClaims.AddRange(childResources);

            Save(claimSetResourceClaims.Cast <object>().ToArray());

            return(claimSetResourceClaims);
        }
Пример #2
0
        protected IReadOnlyCollection <ResourceClaim> SetupResourceClaims(Application testApplication, int resourceClaimCount = 5, int childResourceClaimCount = 3)
        {
            var parentResourceClaims = new List <ResourceClaim>();
            var childResourceClaims  = new List <ResourceClaim>();
            var actions = new List <Action>();

            foreach (var parentIndex in Enumerable.Range(1, resourceClaimCount))
            {
                var resourceClaim = new ResourceClaim
                {
                    ClaimName    = $"TestParentResourceClaim{parentIndex}",
                    DisplayName  = $"TestParentResourceClaim{parentIndex}",
                    ResourceName = $"TestParentResourceClaim{parentIndex}",
                    Application  = testApplication
                };
                parentResourceClaims.Add(resourceClaim);

                childResourceClaims.AddRange(Enumerable.Range(1, childResourceClaimCount)
                                             .Select(childIndex => new ResourceClaim
                {
                    ClaimName             = $"TestChildResourceClaim{childIndex}",
                    DisplayName           = $"TestChildResourceClaim{childIndex}",
                    ResourceName          = $"TestChildResourceClaim{childIndex}",
                    Application           = testApplication,
                    ParentResourceClaim   = resourceClaim,
                    ParentResourceClaimId = resourceClaim.ResourceClaimId
                }));
            }

            foreach (var action in ActionName.GetAll())
            {
                var actionObject = new Action
                {
                    ActionName = action.Value,
                    ActionUri  = action.Value
                };
                actions.Add(actionObject);
            }

            Save(parentResourceClaims.Cast <object>().ToArray());
            Save(childResourceClaims.Cast <object>().ToArray());
            Save(actions.Cast <object>().ToArray());

            return(parentResourceClaims);
        }