Пример #1
0
        public void Sort_Only_Query_No_Where()
        {
            // Arrange
            var db = new DataMapper(System.Data.SqlClient.SqlClientFactory.Instance, "Data Source=a;Initial Catalog=a;User Id=a;Password=a;");
            QueryBuilder<Person> builder = new QueryBuilder<Person>(db, new SqlServerDialect());
            builder.OrderBy(p => p.ID).OrderBy(p => p.Name);

            // Act
            string generatedSql = builder.BuildQuery();

            // Assert
            Assert.IsTrue(generatedSql.Contains("SELECT [t0].[ID],[t0].[Name],[t0].[Age],[t0].[BirthDate],[t0].[IsHappy] "));
            Assert.IsTrue(generatedSql.Contains("FROM [PersonTable]"));
            Assert.IsFalse(generatedSql.Contains("WHERE"));
            Assert.IsTrue(generatedSql.Contains("ORDER BY [t0].[ID],[t0].[Name]"));
        }
Пример #2
0
        public void should_use_sortDirection_supplied_in_overload()
        {
            // Arrange
            var db = new DataMapper(System.Data.SqlClient.SqlClientFactory.Instance, "Data Source=a;Initial Catalog=a;User Id=a;Password=a;");
            QueryBuilder<Person> builder = new QueryBuilder<Person>(db, new SqlServerDialect());
            builder.OrderBy(p => p.ID, SortDirection.Asc).OrderBy(p => p.Name, SortDirection.Desc);

            // Act
            string generatedSql = builder.BuildQuery();

            // Assert
            Assert.IsTrue(generatedSql.Contains("SELECT [t0].[ID],[t0].[Name],[t0].[Age],[t0].[BirthDate],[t0].[IsHappy] "));
            Assert.IsTrue(generatedSql.Contains("FROM [PersonTable]"));
            Assert.IsFalse(generatedSql.Contains("WHERE"));
            Assert.IsTrue(generatedSql.Contains("ORDER BY [t0].[ID],[t0].[Name] DESC"));
        }
Пример #3
0
        public void ManualOrderByClause()
        {
            // Arrange
            var db = new DataMapper(System.Data.SqlClient.SqlClientFactory.Instance, "Data Source=a;Initial Catalog=a;User Id=a;Password=a;");
            QueryBuilder<Person> builder = new QueryBuilder<Person>(db, new SqlServerDialect());
            builder
                .OrderBy("RAND()");

            // Act
            string generatedSql = builder.BuildQuery();

            // Assert
            Assert.IsTrue(generatedSql.Contains("SELECT [t0].[ID],[t0].[Name],[t0].[Age],[t0].[BirthDate],[t0].[IsHappy] "));
            Assert.IsTrue(generatedSql.Contains("FROM [PersonTable] [t0]"));
            Assert.IsTrue(generatedSql.Contains("ORDER BY RAND()"));
        }