Ejemplo n.º 1
0
        public void MultipleManyToManyFetchingWorks()
        {
            // setup the factory
            var config      = new CustomConfig();
            var selectQuery =
                new SelectQuery <Post>(new Mock <ISelectQueryExecutor>().Object).FetchMany(p => p.Tags)
                .ThenFetch(p => p.ElTag)
                .FetchMany(p => p.DeletedTags)
                .ThenFetch(t => t.ElTag) as SelectQuery <Post>;
            var writer  = new SelectWriter(new SqlServer2012Dialect(), config);
            var result  = writer.GenerateSql(selectQuery);
            var mapper  = new MultiCollectionMapperGenerator(config);
            var funcFac = mapper.GenerateMultiCollectionMapper <Post>(result.FetchTree).Item1;

            // setup the scenario
            var post1 = new Post {
                PostId = 1
            };
            var tag1 = new Tag {
                TagId = 1
            };
            var tag2 = new Tag {
                TagId = 2
            };
            var tag3 = new Tag {
                TagId = 3
            };
            var postTag1 = new PostTag {
                PostTagId = 1
            };
            var postTag2 = new PostTag {
                PostTagId = 2
            };
            var postTag3 = new PostTag {
                PostTagId = 3
            };

            // act
            Post         currentRoot  = null;
            IList <Post> results      = new List <Post>();
            var          dict0        = new Dictionary <int, PostTag>();
            var          hashsetPair0 = new HashSet <Tuple <int, int> >();
            var          dict1        = new Dictionary <int, PostTag>();
            var          hashsetPair1 = new HashSet <Tuple <int, int> >();

            var func = (Func <object[], Post>)funcFac.DynamicInvoke(currentRoot, results, dict0, hashsetPair0, dict1, hashsetPair1);

            func(new object[] { post1, postTag2, tag2, postTag1, tag1 });
            func(new object[] { post1, postTag3, tag3, postTag1, tag1 });

            Assert.Equal(1, results.Count);
            Assert.Equal(1, results[0].Tags.Count);
            Assert.Equal(1, results[0].Tags[0].PostTagId);
            Assert.Equal(2, results[0].DeletedTags.Count);
            Assert.Equal(2, results[0].DeletedTags[0].PostTagId);
            Assert.Equal(3, results[0].DeletedTags[1].PostTagId);
        }
Ejemplo n.º 2
0
 public DelegateQueryCreator(IConfiguration configuration)
 {
     this.nonCollectionMapperGenerator    = new NonCollectionMapperGenerator(configuration);
     this.singleCollectionMapperGenerator = new SingleCollectionMapperGenerator(configuration);
     this.multiCollectionMapperGenerator  = new MultiCollectionMapperGenerator(configuration);
     this.configuration   = configuration;
     this.mapperFactories = new ConcurrentDictionary <Tuple <Type, string>, Tuple <Delegate, Type[]> >();
     this.multiCollectionMapperFactories = new ConcurrentDictionary <Tuple <Type, string>, Tuple <Delegate, Type[], Type[]> >();
     this.collectionQueries        = new ConcurrentDictionary <Tuple <Type, string>, Delegate>();
     this.asyncCollectionQueries   = new ConcurrentDictionary <Tuple <Type, string>, Delegate>();
     this.noCollectionQueries      = new ConcurrentDictionary <Tuple <Type, string>, Delegate>();
     this.asyncNoCollectionQueries = new ConcurrentDictionary <Tuple <Type, string>, Delegate>();
 }
Ejemplo n.º 3
0
        private static Delegate GenerateMultiMapper()
        {
            var config      = new CustomConfig();
            var selectQuery =
                new SelectQuery <Post>(new Mock <ISelectQueryExecutor>().Object).Fetch(p => p.Comments).Fetch(p => p.Tags) as SelectQuery <Post>;
            var writer = new SelectWriter(new SqlServer2012Dialect(), config);
            var result = writer.GenerateSql(selectQuery);

            var mapper = new MultiCollectionMapperGenerator(config);
            var func   = mapper.GenerateMultiCollectionMapper <Post>(result.FetchTree);

            return(func.Item1);
        }
Ejemplo n.º 4
0
        public void NestedMultipleOneToManyFetchingWorksTrackingEnabled()
        {
            // setup the factory
            var config      = new CustomConfig();
            var selectQuery =
                new SelectQuery <Blog>(new Mock <ISelectQueryExecutor>().Object).FetchMany(b => b.Posts)
                .ThenFetchMany(p => p.Tags)
                .ThenFetch(t => t.ElTag)
                .FetchMany(b => b.Posts)
                .ThenFetchMany(p => p.DeletedTags)
                .ThenFetch(t => t.ElTag)
                .FetchMany(p => p.Posts)
                .ThenFetch(p => p.Author) as SelectQuery <Blog>;
            var writer  = new SelectWriter(new SqlServer2012Dialect(), config);
            var result  = writer.GenerateSql(selectQuery);
            var mapper  = new MultiCollectionMapperGenerator(config);
            var funcFac = mapper.GenerateMultiCollectionMapper <Blog>(result.FetchTree).Item1;

            // setup the scenario
            var blog1 = new Blog {
                BlogId = 1
            };
            var blog2 = new Blog {
                BlogId = 2
            };
            var post1 = new Post {
                PostId = 1
            };
            var post2 = new Post {
                PostId = 2
            };
            var post3 = new Post {
                PostId = 3
            };
            var posttag1 = new PostTag {
                PostTagId = 1
            };
            var posttag2 = new PostTag {
                PostTagId = 2
            };
            var posttag3 = new PostTag {
                PostTagId = 3
            };
            var tag1 = new Tag {
                TagId = 1
            };
            var tag2 = new Tag {
                TagId = 2
            };
            var tag3 = new Tag {
                TagId = 3
            };
            var tag4 = new Tag {
                TagId = 4
            };
            var delPostTag1 = new PostTag {
                PostTagId = 3
            };
            var delPostTag2 = new PostTag {
                PostTagId = 4
            };
            var delPostTag3 = new PostTag {
                PostTagId = 5
            };
            var author1 = new User {
                UserId = 1
            };
            var author2 = new User {
                UserId = 2
            };

            // act
            Blog         currentRoot  = null;
            IList <Blog> results      = new List <Blog>();
            var          dict0        = new Dictionary <int, Post>();
            var          hashsetPair0 = new HashSet <Tuple <int, int> >();
            var          dict1        = new Dictionary <int, PostTag>();
            var          hashsetPair1 = new HashSet <Tuple <int, int> >();
            var          dict2        = new Dictionary <int, PostTag>();
            var          hashsetPair2 = new HashSet <Tuple <int, int> >();

            var func =
                (Func <object[], Blog>)funcFac.DynamicInvoke(currentRoot, results, dict0, hashsetPair0, dict1, hashsetPair1, dict2, hashsetPair2);

            func(new object[] { blog1, post1, author1, null, null, posttag1, tag1 });
            func(new object[] { blog1, post1, author1, null, null, posttag2, tag2 });
            func(new object[] { blog1, post2, author2, delPostTag1, tag3, null, null });
            func(new object[] { blog1, post2, author2, delPostTag2, tag4, null, null });
            func(new object[] { blog2, post3, author1, delPostTag1, tag3, posttag1, tag1 });
            func(new object[] { blog2, post3, author1, delPostTag2, tag4, posttag1, tag1 });
            func(new object[] { blog2, post3, author1, delPostTag3, tag4, posttag1, tag1 });
            func(new object[] { blog2, post3, author1, delPostTag1, tag3, posttag2, tag2 });
            func(new object[] { blog2, post3, author1, delPostTag2, tag4, posttag2, tag2 });
            func(new object[] { blog2, post3, author1, delPostTag3, tag4, posttag2, tag2 });
            func(new object[] { blog2, post3, author1, delPostTag1, tag3, posttag3, tag3 });
            func(new object[] { blog2, post3, author1, delPostTag2, tag4, posttag3, tag3 });
            func(new object[] { blog2, post3, author1, delPostTag3, tag4, posttag3, tag3 });

            Assert.True(((ITrackedEntity)results[0]).IsTrackingEnabled());
            Assert.True(((ITrackedEntity)results[0].Posts[0]).IsTrackingEnabled());
            Assert.True(((ITrackedEntity)results[0].Posts[0].Author).IsTrackingEnabled());
            Assert.True(((ITrackedEntity)results[0].Posts[0].Tags[0]).IsTrackingEnabled());
            Assert.True(((ITrackedEntity)results[0].Posts[0].Tags[0].ElTag).IsTrackingEnabled());
        }
Ejemplo n.º 5
0
        private static Delegate GenerateMultiMapper() {
            var config = new CustomConfig();
            var selectQuery =
                new SelectQuery<Post>(new Mock<ISelectQueryExecutor>().Object).Fetch(p => p.Comments).Fetch(p => p.Tags) as SelectQuery<Post>;
            var writer = new SelectWriter(new SqlServer2012Dialect(), config);
            var result = writer.GenerateSql(selectQuery);

            var mapper = new MultiCollectionMapperGenerator(config);
            var func = mapper.GenerateMultiCollectionMapper<Post>(result.FetchTree);
            return func.Item1;
        }
Ejemplo n.º 6
0
        public void NestedMultipleOneToManyFetchingWorksTrackingEnabledLast() {
            // setup the factory
            var config = new CustomConfig();
            var selectQuery =
                new SelectQuery<Blog>(new Mock<ISelectQueryExecutor>().Object).FetchMany(b => b.Posts)
                                                                              .ThenFetchMany(p => p.Tags)
                                                                              .ThenFetch(t => t.ElTag)
                                                                              .FetchMany(b => b.Posts)
                                                                              .ThenFetchMany(p => p.DeletedTags)
                                                                              .ThenFetch(t => t.ElTag)
                                                                              .FetchMany(p => p.Posts)
                                                                              .ThenFetch(p => p.Author) as SelectQuery<Blog>;
            var writer = new SelectWriter(new SqlServer2012Dialect(), config);
            var result = writer.GenerateSql(selectQuery);
            var mapper = new MultiCollectionMapperGenerator(config);
            var funcFac = mapper.GenerateMultiCollectionMapper<Blog>(result.FetchTree).Item1;

            // setup the scenario
            var blog1 = new Blog { BlogId = 1 };
            var blog2 = new Blog { BlogId = 2 };
            var post1 = new Post { PostId = 1 };
            var post2 = new Post { PostId = 2 };
            var post3 = new Post { PostId = 3 };
            var posttag1 = new PostTag { PostTagId = 1 };
            var posttag2 = new PostTag { PostTagId = 2 };
            var posttag3 = new PostTag { PostTagId = 3 };
            var tag1 = new Tag { TagId = 1 };
            var tag2 = new Tag { TagId = 2 };
            var tag3 = new Tag { TagId = 3 };
            var tag4 = new Tag { TagId = 4 };
            var delPostTag1 = new PostTag { PostTagId = 3 };
            var delPostTag2 = new PostTag { PostTagId = 4 };
            var delPostTag3 = new PostTag { PostTagId = 5 };
            var author1 = new User { UserId = 1 };
            var author2 = new User { UserId = 2 };

            // act
            Blog currentRoot = null;
            IList<Blog> results = new List<Blog>();
            var dict0 = new Dictionary<int, Post>();
            var hashsetPair0 = new HashSet<Tuple<int, int>>();
            var dict1 = new Dictionary<int, PostTag>();
            var hashsetPair1 = new HashSet<Tuple<int, int>>();
            var dict2 = new Dictionary<int, PostTag>();
            var hashsetPair2 = new HashSet<Tuple<int, int>>();

            var func =
                (Func<object[], Blog>)funcFac.DynamicInvoke(currentRoot, results, dict0, hashsetPair0, dict1, hashsetPair1, dict2, hashsetPair2);
            func(new object[] { blog1, post1, author1, null, null, posttag1, tag1 });
            func(new object[] { blog1, post1, author1, null, null, posttag2, tag2 });
            func(new object[] { blog1, post2, author2, delPostTag1, tag3, null, null });
            func(new object[] { blog1, post2, author2, delPostTag2, tag4, null, null });
            func(new object[] { blog2, post3, author1, delPostTag1, tag3, posttag1, tag1 });
            func(new object[] { blog2, post3, author1, delPostTag2, tag4, posttag1, tag1 });
            func(new object[] { blog2, post3, author1, delPostTag3, tag4, posttag1, tag1 });
            func(new object[] { blog2, post3, author1, delPostTag1, tag3, posttag2, tag2 });
            func(new object[] { blog2, post3, author1, delPostTag2, tag4, posttag2, tag2 });
            func(new object[] { blog2, post3, author1, delPostTag3, tag4, posttag2, tag2 });
            func(new object[] { blog2, post3, author1, delPostTag1, tag3, posttag3, tag3 });
            func(new object[] { blog2, post3, author1, delPostTag2, tag4, posttag3, tag3 });
            func(new object[] { blog2, post3, author1, delPostTag3, tag4, posttag3, tag3 });

            Assert.False(((ITrackedEntity)results[0]).GetDirtyProperties().Any());
            Assert.False(((ITrackedEntity)results[0].Posts[0]).GetDirtyProperties().Any());
            Assert.False(((ITrackedEntity)results[0].Posts[0].Author).GetDirtyProperties().Any());
            Assert.False(((ITrackedEntity)results[0].Posts[0].Tags[0]).GetDirtyProperties().Any());
            Assert.False(((ITrackedEntity)results[0].Posts[0].Tags[0].ElTag).GetDirtyProperties().Any());
        }
Ejemplo n.º 7
0
        public void MultipleManyToManyFetchingWorks() {
            // setup the factory
            var config = new CustomConfig();
            var selectQuery =
                new SelectQuery<Post>(new Mock<ISelectQueryExecutor>().Object).FetchMany(p => p.Tags)
                                                                              .ThenFetch(p => p.ElTag)
                                                                              .FetchMany(p => p.DeletedTags)
                                                                              .ThenFetch(t => t.ElTag) as SelectQuery<Post>;
            var writer = new SelectWriter(new SqlServer2012Dialect(), config);
            var result = writer.GenerateSql(selectQuery);
            var mapper = new MultiCollectionMapperGenerator(config);
            var funcFac = mapper.GenerateMultiCollectionMapper<Post>(result.FetchTree).Item1;

            // setup the scenario
            var post1 = new Post { PostId = 1 };
            var tag1 = new Tag { TagId = 1 };
            var tag2 = new Tag { TagId = 2 };
            var tag3 = new Tag { TagId = 3 };
            var postTag1 = new PostTag { PostTagId = 1 };
            var postTag2 = new PostTag { PostTagId = 2 };
            var postTag3 = new PostTag { PostTagId = 3 };

            // act
            Post currentRoot = null;
            IList<Post> results = new List<Post>();
            var dict0 = new Dictionary<int, PostTag>();
            var hashsetPair0 = new HashSet<Tuple<int, int>>();
            var dict1 = new Dictionary<int, PostTag>();
            var hashsetPair1 = new HashSet<Tuple<int, int>>();

            var func = (Func<object[], Post>)funcFac.DynamicInvoke(currentRoot, results, dict0, hashsetPair0, dict1, hashsetPair1);
            func(new object[] { post1, postTag2, tag2, postTag1, tag1 });
            func(new object[] { post1, postTag3, tag3, postTag1, tag1 });

            Assert.Equal(1, results.Count);
            Assert.Equal(1, results[0].Tags.Count);
            Assert.Equal(1, results[0].Tags[0].PostTagId);
            Assert.Equal(2, results[0].DeletedTags.Count);
            Assert.Equal(2, results[0].DeletedTags[0].PostTagId);
            Assert.Equal(3, results[0].DeletedTags[1].PostTagId);
        }