public void ShouldModifyTheQueryInExpressionToHaveAnAdditionalWhere()
        {
            //Arrange
            var domain      = new TestDomain();
            var interceptor = new AppendWhere <Foo>(1, foo => foo.Name == "Test", typeof(AllFoos));

            domain.Events = new List <IInterceptor>
            {
                interceptor
            };
            domain.ConnectionString = Settings.Default.Connection;

            //act
            var inMemoryDomainContext = new InMemoryDomainContext <TestDomain>();

            inMemoryDomainContext.Add(new Foo()
            {
                Name = "Test"
            });
            inMemoryDomainContext.Add(new Foo()
            {
                Name = "Should Not Show up"
            });
            inMemoryDomainContext.Commit();
            var repository = new DomainRepository <TestDomain>(inMemoryDomainContext, domain);
            var emptyQuery = new AllFoos();
            var results    = repository.Find(emptyQuery);

            //assert
            results.Count().Should().Be(1);
        }
Esempio n. 2
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);
        }
        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);
        }
        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);
        }
Esempio n. 5
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);
        }