public void ShouldEditParentResourcesOnClaimSet() { 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 testResource1ToEdit = testResources.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestParentResourceClaim1"); var testResource2ToNotEdit = testResources.Select(x => x.ResourceClaim).Single(x => x.ResourceName == "TestParentResourceClaim2"); var editedResource = new ResourceClaim { Id = testResource1ToEdit.ResourceClaimId, Name = testResource1ToEdit.ResourceName, Create = false, Read = false, Update = true, Delete = true }; var editResourceOnClaimSetModel = new Mock <IEditResourceOnClaimSetModel>(); editResourceOnClaimSetModel.Setup(x => x.ClaimSetId).Returns(testClaimSet.ClaimSetId); editResourceOnClaimSetModel.Setup(x => x.ResourceClaim).Returns(editedResource); var command = new EditResourceOnClaimSetCommand(TestContext); command.Execute(editResourceOnClaimSetModel.Object); var resourceClaimsForClaimSet = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper()).AllResources(testClaimSet.ClaimSetId).ToList(); var parentResources = testResources.Where(x => x.ClaimSet.ClaimSetId == testClaimSet.ClaimSetId && x.ResourceClaim.ParentResourceClaim == null).Select(x => x.ResourceClaim).ToList(); resourceClaimsForClaimSet.Count().ShouldBe(parentResources.Count); var resultResourceClaim1 = resourceClaimsForClaimSet.Single(x => x.Id == editedResource.Id); resultResourceClaim1.Create.ShouldBe(editedResource.Create); resultResourceClaim1.Read.ShouldBe(editedResource.Read); resultResourceClaim1.Update.ShouldBe(editedResource.Update); resultResourceClaim1.Delete.ShouldBe(editedResource.Delete); var resultResourceClaim2 = resourceClaimsForClaimSet.Single(x => x.Id == testResource2ToNotEdit.ResourceClaimId); resultResourceClaim2.Create.ShouldBe(true); resultResourceClaim2.Read.ShouldBe(false); resultResourceClaim2.Update.ShouldBe(false); resultResourceClaim2.Delete.ShouldBe(false); }
public void ShouldAddChildResourcesToClaimSet() { var testApplication = new Application { ApplicationName = $"Test Application {DateTime.Now:O}" }; Save(testApplication); var testClaimSet = new ClaimSet { ClaimSetName = "TestClaimSet", Application = testApplication }; Save(testClaimSet); var testResources = SetupResourceClaims(testApplication); var testParentResource1 = testResources.Single(x => x.ResourceName == "TestParentResourceClaim1"); var testChildResource1ToAdd = Transaction(securityContext => securityContext.ResourceClaims.Single(x => x.ResourceName == "TestChildResourceClaim1" && x.ParentResourceClaimId == testParentResource1.ResourceClaimId)); var resourceToAdd = new ResourceClaim() { Id = testChildResource1ToAdd.ResourceClaimId, Name = testChildResource1ToAdd.ResourceName, Create = true, Read = false, Update = true, Delete = false }; var existingResources = ResourceClaimsForClaimSet(testClaimSet.ClaimSetId); var editResourceOnClaimSetModel = new EditClaimSetResourceModel { ClaimSetId = testClaimSet.ClaimSetId, ResourceClaim = resourceToAdd, ExistingResourceClaims = existingResources }; Scoped <ISecurityContext>(securityContext => { var command = new EditResourceOnClaimSetCommand(securityContext); command.Execute(editResourceOnClaimSetModel); }); var resourceClaimsForClaimSet = ResourceClaimsForClaimSet(testClaimSet.ClaimSetId); var resultChildResourceClaim1 = resourceClaimsForClaimSet.Single(x => x.Name == testChildResource1ToAdd.ResourceName); resultChildResourceClaim1.Create.ShouldBe(resourceToAdd.Create); resultChildResourceClaim1.Read.ShouldBe(resourceToAdd.Read); resultChildResourceClaim1.Update.ShouldBe(resourceToAdd.Update); resultChildResourceClaim1.Delete.ShouldBe(resourceToAdd.Delete); }
public void ShouldAddParentResourceToClaimSet() { var testApplication = new Application { ApplicationName = $"Test Application {DateTime.Now:O}" }; Save(testApplication); var testClaimSet = new ClaimSet { ClaimSetName = "TestClaimSet", Application = testApplication }; Save(testClaimSet); var testResources = SetupResourceClaims(testApplication); var testResourceToAdd = testResources.Single(x => x.ResourceName == "TestParentResourceClaim1"); var resourceToAdd = new ResourceClaim() { Id = testResourceToAdd.ResourceClaimId, Name = testResourceToAdd.ResourceName, Create = true, Read = false, Update = true, Delete = false }; var existingResources = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper()).AllResources(testClaimSet.ClaimSetId) .ToList(); var editResourceOnClaimSetModel = new EditClaimSetResourceModel { ClaimSetId = testClaimSet.ClaimSetId, ResourceClaim = resourceToAdd, ExistingResourceClaims = existingResources }; var command = new EditResourceOnClaimSetCommand(TestContext); command.Execute(editResourceOnClaimSetModel); var resourceClaimsForClaimSet = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper()).AllResources(testClaimSet.ClaimSetId).ToList(); var resultResourceClaim1 = resourceClaimsForClaimSet.Single(x => x.Name == testResourceToAdd.ResourceName); resultResourceClaim1.Create.ShouldBe(resourceToAdd.Create); resultResourceClaim1.Read.ShouldBe(resourceToAdd.Read); resultResourceClaim1.Update.ShouldBe(resourceToAdd.Update); resultResourceClaim1.Delete.ShouldBe(resourceToAdd.Delete); }
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; }
public void ShouldEditChildResourcesOnClaimSet() { 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 testParentResource = testResources.Single(x => x.ResourceClaim.ResourceName == "TestParentResourceClaim1"); var testChildResource1ToEdit = Transaction(securityContext => securityContext.ResourceClaims.Single(x => x.ResourceName == "TestChildResourceClaim1" && x.ParentResourceClaimId == testParentResource.ResourceClaim.ResourceClaimId)); var testChildResource2NotToEdit = Transaction(securityContext => securityContext.ResourceClaims.Single(x => x.ResourceName == "TestChildResourceClaim2" && x.ParentResourceClaimId == testParentResource.ResourceClaim.ResourceClaimId)); var editedResource = new ResourceClaim { Id = testChildResource1ToEdit.ResourceClaimId, Name = testChildResource1ToEdit.ResourceName, Create = false, Read = false, Update = true, Delete = true }; var editResourceOnClaimSetModel = new Mock <IEditResourceOnClaimSetModel>(); editResourceOnClaimSetModel.Setup(x => x.ClaimSetId).Returns(testClaimSet.ClaimSetId); editResourceOnClaimSetModel.Setup(x => x.ResourceClaim).Returns(editedResource); Scoped <ISecurityContext>(securityContext => { var command = new EditResourceOnClaimSetCommand(securityContext); command.Execute(editResourceOnClaimSetModel.Object); }); var resourceClaimsForClaimSet = ResourceClaimsForClaimSet(testClaimSet.ClaimSetId); var parentResources = testResources.Where(x => x.ClaimSet.ClaimSetId == testClaimSet.ClaimSetId && x.ResourceClaim.ParentResourceClaim == null).Select(x => x.ResourceClaim).ToList(); resourceClaimsForClaimSet.Count.ShouldBe(parentResources.Count); var resultParentResourceClaim = resourceClaimsForClaimSet.Single(x => x.Id == testParentResource.ResourceClaim.ResourceClaimId); resultParentResourceClaim.Create.ShouldBe(true); resultParentResourceClaim.Read.ShouldBe(false); resultParentResourceClaim.Update.ShouldBe(false); resultParentResourceClaim.Delete.ShouldBe(false); var resultChildResourceClaim1 = resultParentResourceClaim.Children.Single(x => x.Id == editedResource.Id); resultChildResourceClaim1.Create.ShouldBe(editedResource.Create); resultChildResourceClaim1.Read.ShouldBe(editedResource.Read); resultChildResourceClaim1.Update.ShouldBe(editedResource.Update); resultChildResourceClaim1.Delete.ShouldBe(editedResource.Delete); var resultChildResourceClaim2 = resultParentResourceClaim.Children.Single(x => x.Id == testChildResource2NotToEdit.ResourceClaimId); resultChildResourceClaim2.Create.ShouldBe(true); resultChildResourceClaim2.Read.ShouldBe(false); resultChildResourceClaim2.Update.ShouldBe(false); resultChildResourceClaim2.Delete.ShouldBe(false); }
public void ShouldImportClaimSet() { var testApplication = new Application { ApplicationName = $"Test Application {DateTime.Now:O}" }; Save(testApplication); SetupResourceClaims(testApplication); var testJSON = @"{ ""title"": ""testfile"", ""template"": { ""claimSets"": [ { ""name"": ""Test Claimset"", ""resourceClaims"": [ { ""Name"": ""TestParentResourceClaim1"", ""Read"": true, ""Create"": false, ""Update"": false, ""Delete"": false, ""Children"": [] }, { ""Name"": ""TestParentResourceClaim2"", ""Read"": true, ""Create"": false, ""Update"": false, ""Delete"": false, ""Children"": [] }, { ""Name"": ""TestParentResourceClaim3"", ""Read"": true, ""Create"": true, ""Update"": true, ""Delete"": true, ""Children"": [] } ] } ] } }"; var importModel = GetImportModel(testJSON); var getResourceByClaimSetIdQuery = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper()); var addClaimSetCommand = new AddClaimSetCommand(TestContext); var getResourceClaimsQuery = new GetResourceClaimsQuery(TestContext); var editResourceOnClaimSetCommand = new EditResourceOnClaimSetCommand(TestContext); var command = new ClaimSetFileImportCommand(addClaimSetCommand, editResourceOnClaimSetCommand, getResourceClaimsQuery); command.Execute(importModel); var testClaimSet = TestContext.ClaimSets.SingleOrDefault(x => x.ClaimSetName == "Test Claimset"); testClaimSet.ShouldNotBeNull(); var resourcesForClaimSet = getResourceByClaimSetIdQuery.AllResources(testClaimSet.ClaimSetId).ToList(); resourcesForClaimSet.Count.ShouldBeGreaterThan(0); var testResources = resourcesForClaimSet.Where(x => x.ParentId == 0).ToArray(); testResources.Count().ShouldBe(3); var testResource1 = testResources[0]; MatchActions(testResource1, "TestParentResourceClaim1", new bool[] { false, true, false, false }); var testResource2 = testResources[1]; MatchActions(testResource2, "TestParentResourceClaim2", new bool[] { false, true, false, false }); var testResource3 = testResources[2]; MatchActions(testResource3, "TestParentResourceClaim3", new bool[] { true, true, true, true }); }