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

            Save(testApplication);

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

            Save(testClaimSet);

            SetupParentResourceClaimsWithChildren(testClaimSet, testApplication);

            var existingResources = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper()).AllResources(testClaimSet.ClaimSetId)
                                    .ToList();

            var duplicateResource = existingResources.Single(x => x.Name == "TestParentResourceClaim1");

            var editResourceOnClaimSetModel = new EditClaimSetResourceModel
            {
                ClaimSetId             = testClaimSet.ClaimSetId,
                ResourceClaim          = duplicateResource,
                ExistingResourceClaims = existingResources
            };

            var validator         = new EditClaimSetResourceModelValidator();
            var validationResults = validator.Validate(editResourceOnClaimSetModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Single().ErrorMessage.ShouldBe("Only unique resource claims can be added. The following is a duplicate resource:\nTestParentResourceClaim1");
        }
        public void ShouldNotAddInvalidResourcesToClaimSetDuringEdit()
        {
            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 testResource = testResources.Single(x => x.ResourceClaim.ResourceName == "TestParentResourceClaim1").ResourceClaim;

            var invalidResource = new ResourceClaim
            {
                Id     = testResource.ResourceClaimId,
                Name   = testResource.ResourceName,
                Create = false,
                Read   = false,
                Update = false,
                Delete = false
            };

            var editResourceOnClaimSetModel = new EditClaimSetResourceModel
            {
                ClaimSetId             = testClaimSet.ClaimSetId,
                ResourceClaim          = invalidResource,
                ExistingResourceClaims = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper()).AllResources(testClaimSet.ClaimSetId)
                                         .ToList()
            };

            var validator         = new EditClaimSetResourceModelValidator();
            var validationResults = validator.Validate(editResourceOnClaimSetModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Single().ErrorMessage.ShouldBe("Only valid resources can be added. A resource must have at least one action associated with it to be added. The following is an invalid resource:\nTestParentResourceClaim1");
        }