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 ClaimSetsController(IGetClaimSetByIdQuery getClaimSetByIdQuery
                            , IGetApplicationsByClaimSetIdQuery getApplicationsByClaimSetIdQuery
                            , IGetResourcesByClaimSetIdQuery getResourcesByClaimSetIdQuery
                            , IGetClaimSetsByApplicationNameQuery getClaimSetsByApplicationNameQuery
                            , IGetAuthStrategiesByApplicationNameQuery getAuthStrategiesByApplicationNameQuery
                            , ITabDisplayService tabDisplayService
                            , CopyClaimSetCommand copyClaimSetCommand
                            , AddClaimSetCommand addClaimSetCommand
                            , EditClaimSetCommand editClaimSetCommand
                            , GetResourceClaimsQuery getResourceClaimsQuery
                            , GetChildResourceClaimsForParentQuery getChildResourceClaimsForParentQuery
                            , DeleteClaimSetCommand deleteClaimSetCommand
                            , EditResourceOnClaimSetCommand editResourceOnClaimSetCommand
                            , DeleteResourceOnClaimSetCommand deleteResourceOnClaimSetCommand
                            , ClaimSetFileExportCommand claimSetFileExportCommand
                            , ClaimSetFileImportCommand claimSetFileImportCommand
                            , OverrideDefaultAuthorizationStrategyCommand overrideDefaultAuthorizationStrategyCommand
                            , ResetToDefaultAuthStrategyCommand resetToDefaultAuthStrategyCommand)
 {
     _getClaimSetByIdQuery                    = getClaimSetByIdQuery;
     _getApplicationsByClaimSetIdQuery        = getApplicationsByClaimSetIdQuery;
     _getResourcesByClaimSetIdQuery           = getResourcesByClaimSetIdQuery;
     _getClaimSetsByApplicationNameQuery      = getClaimSetsByApplicationNameQuery;
     _getAuthStrategiesByApplicationNameQuery = getAuthStrategiesByApplicationNameQuery;
     _tabDisplayService      = tabDisplayService;
     _copyClaimSetCommand    = copyClaimSetCommand;
     _addClaimSetCommand     = addClaimSetCommand;
     _editClaimSetCommand    = editClaimSetCommand;
     _getClaimSetByIdQuery   = getClaimSetByIdQuery;
     _getResourceClaimsQuery = getResourceClaimsQuery;
     _getChildResourceClaimsForParentQuery = getChildResourceClaimsForParentQuery;
     _deleteClaimSetCommand                       = deleteClaimSetCommand;
     _editResourceOnClaimSetCommand               = editResourceOnClaimSetCommand;
     _deleteResourceOnClaimSetCommand             = deleteResourceOnClaimSetCommand;
     _claimSetFileExportCommand                   = claimSetFileExportCommand;
     _claimSetFileImportCommand                   = claimSetFileImportCommand;
     _overrideDefaultAuthorizationStrategyCommand = overrideDefaultAuthorizationStrategyCommand;
     _resetToDefaultAuthStrategyCommand           = resetToDefaultAuthStrategyCommand;
 }