public void OrderByForeignKeyDesc()
        {
            Expression <Func <Post, Blog> > cls = p => p.Blog;
            var  clause = new OrderClause <Post>(cls, ListSortDirection.Descending);
            var  writer = new OrderClauseWriter(new CustomConfig(), new SqlServerDialect());
            bool containsPrimaryKeyClause = false;
            var  result = writer.GetOrderClause(clause, null, out containsPrimaryKeyClause);

            Assert.Equal("[BlogId] desc", result);
        }
        public void SimpleClauseDescendingCorrect()
        {
            Expression <Func <Post, string> > cls = p => p.Title;
            var  clause = new OrderClause <Post>(cls, ListSortDirection.Descending);
            var  writer = new OrderClauseWriter(new CustomConfig(), new SqlServerDialect());
            bool containsPrimaryKeyClause = false;
            var  result = writer.GetOrderClause(clause, null, out containsPrimaryKeyClause);

            Assert.Equal("[Title] desc", result);
        }
        public void OrderByPrimaryKeyContainsPrimaryKeyClause()
        {
            Expression <Func <Post, int> > cls = p => p.PostId;
            var  clause = new OrderClause <Post>(cls, ListSortDirection.Ascending);
            var  writer = new OrderClauseWriter(new CustomConfig(), new SqlServerDialect());
            bool containsPrimaryKeyClause = false;
            var  result = writer.GetOrderClause(clause, null, out containsPrimaryKeyClause);

            Assert.True(containsPrimaryKeyClause);
        }
        public void OrderByNestedForeignKeyDesc()
        {
            var  query                    = new SelectQuery <Post>(new NonExecutingSelectQueryExecutor()).Fetch(p => p.Blog).OrderByDescending(p => p.Blog.CreateDate);
            var  config                   = new CustomConfig();
            var  dialect                  = new SqlServerDialect();
            var  writer                   = new OrderClauseWriter(config, dialect);
            var  fetchTreeWriter          = new FetchTreeWriter(dialect, config);
            bool containsPrimaryKeyClause = false;
            var  result                   = writer.GetOrderClause(
                ((SelectQuery <Post>)query).OrderClauses.Dequeue(),
                fetchTreeWriter.GetFetchTree((SelectQuery <Post>)query),
                out containsPrimaryKeyClause);

            Assert.Equal("t_1.[CreateDate] desc", result);
        }
        public void OrderAcrossOneToOneWorks()
        {
            var query                    = new SelectQuery <OneToOneLeft>(new NonExecutingSelectQueryExecutor()).Fetch(o => o.Right).OrderBy(o => o.Right.Name);
            var config                   = new OneToOneConfig();
            var dialect                  = new SqlServer2012Dialect();
            var writer                   = new OrderClauseWriter(config, dialect);
            var fetchTreeWriter          = new FetchTreeWriter(dialect, config);
            var containsPrimaryKeyClause = false;
            var result                   = writer.GetOrderClause(
                ((SelectQuery <OneToOneLeft>)query).OrderClauses.Dequeue(),
                fetchTreeWriter.GetFetchTree((SelectQuery <OneToOneLeft>)query),
                out containsPrimaryKeyClause);

            Assert.Equal("t_1.[Name] asc", result);
        }
        public void OrderByNestedNestedPropAsc()
        {
            var  query                    = new SelectQuery <Comment>(new NonExecutingSelectQueryExecutor()).Fetch(c => c.Post.Blog).OrderBy(c => c.Post.Blog.Title);
            var  config                   = new CustomConfig();
            var  dialect                  = new SqlServerDialect();
            var  writer                   = new OrderClauseWriter(config, dialect);
            var  fetchTreeWriter          = new FetchTreeWriter(dialect, config);
            bool containsPrimaryKeyClause = false;
            var  result                   = writer.GetOrderClause(
                ((SelectQuery <Comment>)query).OrderClauses.Dequeue(),
                fetchTreeWriter.GetFetchTree((SelectQuery <Comment>)query),
                out containsPrimaryKeyClause);

            Assert.Equal("t_2.[Title] asc", result);
        }
        public void OrderByNotFetchedThrows()
        {
            var  query                    = new SelectQuery <Comment>(new NonExecutingSelectQueryExecutor()).OrderByDescending(c => c.Post.Title);
            var  config                   = new CustomConfig();
            var  dialect                  = new SqlServerDialect();
            var  writer                   = new OrderClauseWriter(config, dialect);
            var  fetchTreeWriter          = new FetchTreeWriter(dialect, config);
            bool containsPrimaryKeyClause = false;

            Assert.Throws <InvalidOperationException>(
                () =>
                writer.GetOrderClause(
                    ((SelectQuery <Comment>)query).OrderClauses.Dequeue(),
                    fetchTreeWriter.GetFetchTree((SelectQuery <Comment>)query),
                    out containsPrimaryKeyClause));
        }