public void DuplicateSecurableRelationshipsAreNotReturned() { // Arrange var exampleMappingConfigurations = new ISecuredRelationshipBuilder[] { _exampleSecuredRelationshipBuilder, _exampleSecuredRelationshipBuilder2 }; var securedMappingsCache = new MappingsCache(exampleMappingConfigurations); // Act var securedMappings = securedMappingsCache.GetRelationships <ExampleLeaf>().ToList(); // Assert securedMappings.Should().NotBeNull(); securedMappings.Should().HaveCount(2); }
public void DuplicateSecurableRelationshipsAreNotReturned() { // Arrange var exampleMappingConfigurations = new ISecuredRelationshipBuilder[] { _exampleSecuredRelationshipBuilder, _exampleSecuredRelationshipBuilder2 }; var securedMappingsCache = new MappingsCache(exampleMappingConfigurations); // Act var securedMappings = securedMappingsCache.GetRelationships<ExampleLeaf>().ToList(); // Assert securedMappings.Should().NotBeNull(); securedMappings.Should().HaveCount(2); }
public void CanResolveSecuredMappingsForExampleSecuredMappings() { // Arrange var exampleMappingConfigurations = new ISecuredRelationshipBuilder[] { _exampleSecuredRelationshipBuilder }; var securedMappingsCache = new MappingsCache(exampleMappingConfigurations); // Act var securedMappings = securedMappingsCache.GetRelationships <ExampleLeaf>().ToList(); // Assert securedMappings.Should().NotBeNull(); securedMappings.Should().HaveCount(2); }
public void CanResolveSecuredMappingsForExampleSecuredMappings() { // Arrange var exampleMappingConfigurations = new ISecuredRelationshipBuilder[] { _exampleSecuredRelationshipBuilder }; var securedMappingsCache = new MappingsCache(exampleMappingConfigurations); // Act var securedMappings = securedMappingsCache.GetRelationships<ExampleLeaf>().ToList(); // Assert securedMappings.Should().NotBeNull(); securedMappings.Should().HaveCount(2); }
/// <summary> /// Returns an <see cref="Expression{T}"/> of <see cref="Func{T, TResult}"/> of <see cref="T:T"/>, <see cref="bool"/> that is used to secure an entity set by the include path represented in the IncludedPropertyPath property. /// </summary> /// <typeparam name="T">The <see cref="System.Type"/> to be .</typeparam> /// <param name="entitlements">Contains information about which entities the user has access to.</param> /// <param name="mappingCache"></param> /// <returns></returns> public Expression <Func <T, bool> > GenerateSecurityPredicate <T>(IEntitlementProvider entitlements, MappingsCache mappingCache) { if (!IncludedPropertyDetails.Any()) { // If there are no included properties, we have nothing to do. return(null); } // We need to start at the leaf property and work our way back up, so we reverse the list. var reversedPropertyDetails = IncludedPropertyDetails.Reverse().ToList(); var leafProperty = reversedPropertyDetails.First(); var leafPropertyRelationships = mappingCache.GetRelationships(leafProperty.DeclaringType); if (leafPropertyRelationships == null) { // If the leaf property's declaring type has no relationships, we have nothing to do. return(null); } // Find the relationship that is by the leaf property's type. var Relationship = leafPropertyRelationships.SingleOrDefault(x => x.SecuredBy == leafProperty.PropertySingularType); if (!RelationshipNeedsToBe <T>(entitlements, Relationship)) { return(null); } var entitledIds = entitlements.GetEntitledIds(Relationship.SecuredBy); var filterLambda = Relationship.GetSimplePredicate(entitledIds); reversedPropertyDetails.Remove(leafProperty); foreach (var propertyAccessMetadata in reversedPropertyDetails) { if (propertyAccessMetadata.IsEnumerable) { filterLambda = GetLambdaForEnumerableProperty <T>(propertyAccessMetadata, filterLambda); } else { filterLambda = GetLambdaForSimpleProperty <T>(propertyAccessMetadata, filterLambda); } } return((Expression <Func <T, bool> >)filterLambda); }