Exemplo n.º 1
0
        public void ShouldReturnLimitedResultsFromCollection()
        {
            // Arrange
            IEntitlementProvider sessionGovernor = MockRepository.GenerateMock <IEntitlementProvider>();

            sessionGovernor.Expect(x => x.IsEntitledToAll(typeof(ExampleRoot))).Return(false);
            sessionGovernor.Expect(x => x.GetEntitledIds(typeof(ExampleRoot))).Return(new long[] { 1, 2, 3 });

            var securedMappingsCache = new MappingsCache(new ISecuredRelationshipBuilder[] { new NullPermissiveExampleSecuredRelationshipBuilder() });
            var context         = new InMemoryDomainContext <ExampleDomain>(sessionGovernor, securedMappingsCache);
            var nonMatchingLeaf = new ExampleLeaf
            {
                SecuredRoots = new[] { new ExampleRoot {
                                           Id = 4
                                       } }
            };
            var matchingLeaf = new ExampleLeaf
            {
                SecuredRoots = new[] { new ExampleRoot {
                                           Id = 3
                                       } }
            };

            context.Add(nonMatchingLeaf);
            context.Add(matchingLeaf);
            context.Commit();

            // Act
            var exampleLeaves = context.AsQueryable <ExampleLeaf>();
            var results       = exampleLeaves.ToList();

            //Assert
            results.Should().HaveCount(1);
        }
Exemplo n.º 2
0
        public void ShouldReturnCorrectIntersationOfMatchingAndNonMatchingRecordsForNullPropertiesOnNullPermissiveMappings()
        {
            // Arrange
            IEntitlementProvider sessionGovernor = MockRepository.GenerateMock <IEntitlementProvider>();

            sessionGovernor.Expect(x => x.IsEntitledToAll(typeof(ExampleRoot))).Return(false);
            sessionGovernor.Expect(x => x.GetEntitledIds(typeof(ExampleRoot))).Return(new long[] { 1, 2, 3 });

            var securedMappingsCache = new MappingsCache(new ISecuredRelationshipBuilder[] { new NullPermissiveExampleSecuredRelationshipBuilder() });
            var context = new InMemoryDomainContext <ExampleDomain>(sessionGovernor, securedMappingsCache);
            var singleNonMatchingLeaf = new ExampleLeaf
            {
                SecuredRoot = new ExampleRoot {
                    Id = 4
                },
                SecuredRoots = new[]
                {
                    new ExampleRoot {
                        Id = 5
                    }
                }
            };
            var pluralNonMatchingLeaf = new ExampleLeaf
            {
                SecuredRoot = new ExampleRoot {
                    Id = 4
                },
                SecuredRoots = new[]
                {
                    new ExampleRoot {
                        Id = 5
                    }
                }
            };
            var combinedNonMatchingLeaf = new ExampleLeaf
            {
                SecuredRoot = new ExampleRoot
                {
                    Id = 5
                },
                SecuredRoots = new[]
                {
                    new ExampleRoot {
                        Id = 6
                    },
                    new ExampleRoot {
                        Id = 7
                    }
                }
            };
            var combinedMatchingLeaf = new ExampleLeaf
            {
                SecuredRoot = new ExampleRoot
                {
                    Id = 1
                },
                SecuredRoots = new[]
                {
                    new ExampleRoot {
                        Id = 2
                    },
                    new ExampleRoot {
                        Id = 3
                    }
                }
            };
            var combinedNullMatchingLeaf = new ExampleLeaf();
            var singleNullMatchingLeaf   = new ExampleLeaf
            {
                SecuredRoots = new[]
                {
                    new ExampleRoot {
                        Id = 1
                    }
                }
            };
            var pluralNullMatchingLeaf = new ExampleLeaf
            {
                SecuredRoot = new ExampleRoot {
                    Id = 1
                },
            };

            context.Add(singleNonMatchingLeaf);
            context.Add(pluralNonMatchingLeaf);
            context.Add(combinedNonMatchingLeaf);
            context.Add(combinedMatchingLeaf);
            context.Add(combinedNullMatchingLeaf);
            context.Add(singleNullMatchingLeaf);
            context.Add(pluralNullMatchingLeaf);
            context.Commit();

            // Act
            var exampleLeaves = context.AsQueryable <ExampleLeaf>();
            var results       = exampleLeaves.ToList();

            //Assert
            results.Should().HaveCount(4);
        }