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

            Save(testApplication);

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

            Save(testClaimSet);

            var testResourceClaims = SetupParentResourceClaimsWithChildren(testClaimSet, testApplication);

            var newClaimSet = new Mock <ICopyClaimSetModel>();

            newClaimSet.Setup(x => x.Name).Returns("TestClaimSet_Copy");
            newClaimSet.Setup(x => x.OriginalId).Returns(testClaimSet.ClaimSetId);
            var command = new CopyClaimSetCommand(TestContext);

            var copyClaimSetId = command.Execute(newClaimSet.Object);

            var copiedClaimSet = TestContext.ClaimSets.Single(x => x.ClaimSetId == copyClaimSetId);

            copiedClaimSet.ClaimSetName.ShouldBe(newClaimSet.Object.Name);
            Transaction <SqlServerSecurityContext>(securityContext =>
            {
                var query = new GetResourcesByClaimSetIdQuery(securityContext, GetMapper());

                var results = query.AllResources(copiedClaimSet.ClaimSetId).ToArray();

                var testParentResourceClaimsForId =
                    testResourceClaims.Where(x => x.ClaimSet.ClaimSetId == testClaimSet.ClaimSetId && x.ResourceClaim.ParentResourceClaim == null).Select(x => x.ResourceClaim).ToArray();

                results.Length.ShouldBe(testParentResourceClaimsForId.Length);
                results.Select(x => x.Name).ShouldBe(testParentResourceClaimsForId.Select(x => x.ResourceName), true);
                results.Select(x => x.Id).ShouldBe(testParentResourceClaimsForId.Select(x => x.ResourceClaimId), true);
                results.All(x => x.Create).ShouldBe(true);

                foreach (var testParentResourceClaim in testParentResourceClaimsForId)
                {
                    var testChildren = securityContext.ResourceClaims.Where(x =>
                                                                            x.ParentResourceClaimId == testParentResourceClaim.ResourceClaimId).ToList();
                    var parentResult = results.First(x => x.Id == testParentResourceClaim.ResourceClaimId);
                    parentResult.Children.Select(x => x.Name).ShouldBe(testChildren.Select(x => x.ResourceName), true);
                    parentResult.Children.Select(x => x.Id).ShouldBe(testChildren.Select(x => x.ResourceClaimId), true);
                    parentResult.Children.All(x => x.Create).ShouldBe(true);
                }
            });
            Transaction <SqlServerUsersContext>(usersContext =>
            {
                usersContext.Applications.Count(x => x.ClaimSetName == copiedClaimSet.ClaimSetName).ShouldBe(0);
            });
        }
 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;
 }