public void ShouldDeleteChildResourceOnClaimSet()
        {
            var testApplication = new Application
            {
                ApplicationName = $"Test Application {DateTime.Now:O}"
            };

            Save(testApplication);

            var testClaimSet = new ClaimSet {
                ClaimSetName = "TestClaimSet", Application = testApplication
            };

            Save(testClaimSet);

            var testResources = SetupParentResourceClaimsWithChildren(testClaimSet, testApplication);

            var parentResourcesOnClaimSetOriginalCount =
                testResources.Count(x => x.ResourceClaim.ParentResourceClaim == null);

            var testParentResource = testResources.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestParentResourceClaim1");
            var childResourcesForParentOriginalCount = testResources.Count(x => x.ResourceClaim.ParentResourceClaimId == testParentResource.ResourceClaimId);
            var testChildResourceToDelete            = testResources.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestChildResourceClaim1" && x.ParentResourceClaimId == testParentResource.ResourceClaimId);

            var deleteResourceOnClaimSetModel = new DeleteClaimSetResourceModel
            {
                ClaimSetId      = testClaimSet.ClaimSetId,
                ResourceClaimId = testChildResourceToDelete.ResourceClaimId,
                ClaimSetName    = testClaimSet.ClaimSetName,
                ResourceName    = testChildResourceToDelete.ResourceName
            };

            Scoped <ISecurityContext>(securityContext =>
            {
                var command = new DeleteResourceOnClaimSetCommand(securityContext);
                command.Execute(deleteResourceOnClaimSetModel);
            });

            var resourceClaimsForClaimSet =
                Scoped <IGetResourcesByClaimSetIdQuery, List <Management.ClaimSetEditor.ResourceClaim> >(
                    query => query.AllResources(testClaimSet.ClaimSetId).ToList());

            resourceClaimsForClaimSet.Count.ShouldBe(parentResourcesOnClaimSetOriginalCount);

            Transaction(securityContext =>
            {
                var resultChildResources =
                    securityContext.ClaimSetResourceClaims.Where(x => x.ClaimSet.ClaimSetId == testClaimSet.ClaimSetId && x.ResourceClaim.ParentResourceClaimId == testParentResource.ResourceClaimId);
                resultChildResources.Count().ShouldBe(childResourcesForParentOriginalCount - 1);

                var resultResourceClaim = resultChildResources.SingleOrDefault(x => x.ResourceClaim.ResourceClaimId == testChildResourceToDelete.ResourceClaimId);

                resultResourceClaim.ShouldBeNull();
            });
        }
Exemple #2
0
        public void ShouldDeleteParentResourceOnClaimSet()
        {
            var testApplication = new Application
            {
                ApplicationName = $"Test Application {DateTime.Now:O}"
            };

            Save(testApplication);

            var testClaimSet = new ClaimSet {
                ClaimSetName = "TestClaimSet", Application = testApplication
            };

            Save(testClaimSet);

            var testResources = SetupParentResourceClaimsWithChildren(testClaimSet, testApplication);

            var parentResourcesOnClaimSetOriginalCount =
                testResources.Count(x => x.ResourceClaim.ParentResourceClaim == null);

            var testResourceToDelete = testResources.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestParentResourceClaim1");

            var deleteResourceOnClaimSetModel = new DeleteClaimSetResourceModel
            {
                ClaimSetId      = testClaimSet.ClaimSetId,
                ResourceClaimId = testResourceToDelete.ResourceClaimId,
                ClaimSetName    = testClaimSet.ClaimSetName,
                ResourceName    = testResourceToDelete.ResourceName
            };

            var command = new DeleteResourceOnClaimSetCommand(TestContext);

            command.Execute(deleteResourceOnClaimSetModel);

            var resourceClaimsForClaimSet =
                TestContext.ClaimSetResourceClaims.Where(x => x.ClaimSet.ClaimSetId == testClaimSet.ClaimSetId && x.ResourceClaim.ParentResourceClaimId == null);

            resourceClaimsForClaimSet.Count().ShouldBe(parentResourcesOnClaimSetOriginalCount - 1);

            var resultResourceClaim = resourceClaimsForClaimSet.SingleOrDefault(x => x.ResourceClaim.ResourceClaimId == testResourceToDelete.ResourceClaimId);

            resultResourceClaim.ShouldBeNull();
        }
 public ActionResult DeleteResourceOnClaimSet(DeleteClaimSetResourceModel model)
 {
     _deleteResourceOnClaimSetCommand.Execute(model);
     return(RedirectToAction("EditClaimSet", "ClaimSets", new { claimSetId = model.ClaimSetId }));
 }