Modernize tests, remove Tester project, and automate amalgamation pipeline
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,55 +1,55 @@
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Test standard dynamic access ORM. With out schema information from database.</summary>
|
||||
[TestClass]
|
||||
public class DynamicNoSchemaAccessTests : DynamicAccessTests
|
||||
{
|
||||
/// <summary>Setup test parameters.</summary>
|
||||
[TestInitialize]
|
||||
public override void SetUp()
|
||||
{
|
||||
CreateTestDatabase();
|
||||
CreateDynamicDatabase(
|
||||
DynamicDatabaseOptions.SingleConnection |
|
||||
DynamicDatabaseOptions.SingleTransaction |
|
||||
DynamicDatabaseOptions.SupportLimitOffset);
|
||||
}
|
||||
|
||||
/// <summary>Create table using specified method.</summary>
|
||||
/// <returns>Dynamic table.</returns>
|
||||
public override dynamic GetTestTable()
|
||||
{
|
||||
return Database.Table("users", new string[] { "id" });
|
||||
}
|
||||
}
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Test standard dynamic access ORM. With out schema information from database.</summary>
|
||||
[TestFixture]
|
||||
public class DynamicNoSchemaAccessTests : DynamicAccessTests
|
||||
{
|
||||
/// <summary>Setup test parameters.</summary>
|
||||
[SetUp]
|
||||
public override void SetUp()
|
||||
{
|
||||
CreateTestDatabase();
|
||||
CreateDynamicDatabase(
|
||||
DynamicDatabaseOptions.SingleConnection |
|
||||
DynamicDatabaseOptions.SingleTransaction |
|
||||
DynamicDatabaseOptions.SupportLimitOffset);
|
||||
}
|
||||
|
||||
/// <summary>Create table using specified method.</summary>
|
||||
/// <returns>Dynamic table.</returns>
|
||||
public override dynamic GetTestTable()
|
||||
{
|
||||
return Database.Table("users", new string[] { "id" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,45 @@
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using DynamORM.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Test standard dynamic access ORM. With out schema information from database.</summary>
|
||||
[TestClass]
|
||||
public class DynamicTypeSchemaAccessTests : DynamicNoSchemaAccessTests
|
||||
{
|
||||
/// <summary>Create table using specified method.</summary>
|
||||
/// <returns>Dynamic table.</returns>
|
||||
public override dynamic GetTestTable()
|
||||
{
|
||||
return Database.Table<users>();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using DynamORM.Tests.Helpers;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Test standard dynamic access ORM. With out schema information from database.</summary>
|
||||
[TestFixture]
|
||||
public class DynamicTypeSchemaAccessTests : DynamicNoSchemaAccessTests
|
||||
{
|
||||
/// <summary>Create table using specified method.</summary>
|
||||
/// <returns>Dynamic table.</returns>
|
||||
public override dynamic GetTestTable()
|
||||
{
|
||||
return Database.Table<users>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,321 +1,321 @@
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using DynamORM.Builders;
|
||||
using DynamORM.Builders.Implementation;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Tests of legacy parser methods.</summary>
|
||||
[TestClass]
|
||||
public class LegacyParserTests : TestsBase
|
||||
{
|
||||
/// <summary>Setup test parameters.</summary>
|
||||
[TestInitialize]
|
||||
public virtual void SetUp()
|
||||
{
|
||||
CreateTestDatabase();
|
||||
CreateDynamicDatabase(
|
||||
DynamicDatabaseOptions.SingleConnection |
|
||||
DynamicDatabaseOptions.SingleTransaction |
|
||||
DynamicDatabaseOptions.SupportLimitOffset);
|
||||
}
|
||||
|
||||
/// <summary>Tear down test objects.</summary>
|
||||
[TestCleanup]
|
||||
public virtual void TearDown()
|
||||
{
|
||||
DestroyDynamicDatabase();
|
||||
DestroyTestDatabase();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" = [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereBracketsEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetEndBlock());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE ((u.\"Deleted\" = [${0}]) AND (u.\"IsActive\" = [${1}]))", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets and or condition.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereBracketsOrEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetOr().SetEndBlock());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE ((u.\"Deleted\" = [${0}]) OR (u.\"IsActive\" = [${1}]))", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereBracketsOrEq2()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Id_User").Greater(1))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetOr().SetEndBlock());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Id_User\" > [${0}]) AND ((u.\"Deleted\" = [${1}]) OR (u.\"IsActive\" = [${2}]))",
|
||||
cmd.Parameters.Keys.ToArray()[0], cmd.Parameters.Keys.ToArray()[1], cmd.Parameters.Keys.ToArray()[2]), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereBracketsOrEqForgotToEnd()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Id_User").Greater(1))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetOr());
|
||||
|
||||
using (var con = Database.Open())
|
||||
using (var c = con.CreateCommand())
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Id_User\" > @0) AND ((u.\"Deleted\" = @1) OR (u.\"IsActive\" = @2))"),
|
||||
c.SetCommand(cmd).CommandText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression not equal.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereNotEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Not(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" <> [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression greater.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereGreater()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Greater(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" > [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression greater or equal.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereGreaterOrEqual()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").GreaterOrEqual(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" >= [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression less.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereLess()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Less(1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" < [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression less or equal.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereLessOrEqual()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").LessOrEqual(1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" <= [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression like.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereLike()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Like("%1"));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" LIKE [${0}]", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression not like.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereNotLike()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").NotLike("%1"));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" NOT LIKE [${0}]", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression between.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereBetween()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Between(0, 1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" BETWEEN [${0}] AND [${1}]", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression in.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereIn()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").In(0, 1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" IN([${0}], [${1}])", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression using anonymous types.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestWhereAnon()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new { Deleted = 0, IsActive = 1, _table = "u" });
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" = [${0}]) AND (u.\"IsActive\" = [${1}])", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the order by column.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestOrderByCol()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.OrderByColumn(new DynamicColumn("u.Name").Desc());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u ORDER BY u.\"Name\" DESC"), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the order by column number.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestOrderByNum()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.OrderByColumn(new DynamicColumn("u.Name").SetAlias("1").Desc());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u ORDER BY 1 DESC"), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the group by column.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestGroupByCol()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.GroupByColumn(new DynamicColumn("u.Name"));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u GROUP BY u.\"Name\""), cmd.CommandText());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using DynamORM.Builders;
|
||||
using DynamORM.Builders.Implementation;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Tests of legacy parser methods.</summary>
|
||||
[TestFixture]
|
||||
public class LegacyParserTests : TestsBase
|
||||
{
|
||||
/// <summary>Setup test parameters.</summary>
|
||||
[SetUp]
|
||||
public virtual void SetUp()
|
||||
{
|
||||
CreateTestDatabase();
|
||||
CreateDynamicDatabase(
|
||||
DynamicDatabaseOptions.SingleConnection |
|
||||
DynamicDatabaseOptions.SingleTransaction |
|
||||
DynamicDatabaseOptions.SupportLimitOffset);
|
||||
}
|
||||
|
||||
/// <summary>Tear down test objects.</summary>
|
||||
[TearDown]
|
||||
public virtual void TearDown()
|
||||
{
|
||||
DestroyDynamicDatabase();
|
||||
DestroyTestDatabase();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" = [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereBracketsEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetEndBlock());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE ((u.\"Deleted\" = [${0}]) AND (u.\"IsActive\" = [${1}]))", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets and or condition.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereBracketsOrEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetOr().SetEndBlock());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE ((u.\"Deleted\" = [${0}]) OR (u.\"IsActive\" = [${1}]))", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereBracketsOrEq2()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Id_User").Greater(1))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetOr().SetEndBlock());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Id_User\" > [${0}]) AND ((u.\"Deleted\" = [${1}]) OR (u.\"IsActive\" = [${2}]))",
|
||||
cmd.Parameters.Keys.ToArray()[0], cmd.Parameters.Keys.ToArray()[1], cmd.Parameters.Keys.ToArray()[2]), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression equal with brackets.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereBracketsOrEqForgotToEnd()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Id_User").Greater(1))
|
||||
.Where(new DynamicColumn("u.Deleted").Eq(0).SetBeginBlock())
|
||||
.Where(new DynamicColumn("u.IsActive").Eq(1).SetOr());
|
||||
|
||||
using (var con = Database.Open())
|
||||
using (var c = con.CreateCommand())
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Id_User\" > @0) AND ((u.\"Deleted\" = @1) OR (u.\"IsActive\" = @2))"),
|
||||
c.SetCommand(cmd).CommandText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression not equal.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereNotEq()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Not(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" <> [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression greater.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereGreater()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Greater(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" > [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression greater or equal.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereGreaterOrEqual()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").GreaterOrEqual(0));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" >= [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression less.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereLess()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Less(1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" < [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression less or equal.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereLessOrEqual()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").LessOrEqual(1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" <= [${0}])", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression like.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereLike()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Like("%1"));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" LIKE [${0}]", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression not like.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereNotLike()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").NotLike("%1"));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" NOT LIKE [${0}]", cmd.Parameters.Keys.First()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression between.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereBetween()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").Between(0, 1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" BETWEEN [${0}] AND [${1}]", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression in.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereIn()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new DynamicColumn("u.Deleted").In(0, 1));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE u.\"Deleted\" IN([${0}], [${1}])", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the where expression using anonymous types.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestWhereAnon()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.Where(new { Deleted = 0, IsActive = 1, _table = "u" });
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u WHERE (u.\"Deleted\" = [${0}]) AND (u.\"IsActive\" = [${1}])", cmd.Parameters.Keys.First(), cmd.Parameters.Keys.Last()), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the order by column.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestOrderByCol()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.OrderByColumn(new DynamicColumn("u.Name").Desc());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u ORDER BY u.\"Name\" DESC"), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the order by column number.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestOrderByNum()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.OrderByColumn(new DynamicColumn("u.Name").SetAlias("1").Desc());
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u ORDER BY 1 DESC"), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the group by column.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGroupByCol()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(x => x.dbo.Users.As(x.u))
|
||||
.GroupByColumn(new DynamicColumn("u.Name"));
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT * FROM \"dbo\".\"Users\" AS u GROUP BY u.\"Name\""), cmd.CommandText());
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,150 +1,150 @@
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DynamORM.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Test typed ORM.</summary>
|
||||
[TestClass]
|
||||
public class RenamedTypedAccessTests : TypedAccessTests<Users>
|
||||
{
|
||||
/// <summary>Test something fancy... like: <code>select "first", count("first") aggregatefield from "users" group by "first" order by 2 desc;</code>.</summary>
|
||||
[TestMethod]
|
||||
public override void TestTypedFancyAggregateQuery()
|
||||
{
|
||||
var v = (GetTestTable().Query(type: typeof(Users), columns: "first,first:AggregateField:count", group: "first", order: ":desc:2") as IEnumerable<dynamic>).ToList();
|
||||
|
||||
Assert.IsNotNull(v);
|
||||
Assert.AreEqual(187, v.Count());
|
||||
Assert.AreEqual(4, v.First().AggregateField);
|
||||
Assert.AreEqual("Logan", v.First().First);
|
||||
Assert.AreEqual(2, v.Take(10).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Take(11).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Last().AggregateField);
|
||||
}
|
||||
|
||||
/// <summary>Test something fancy... like: <code>select "first", count("first") aggregatefield from "users" group by "first" order by 2 desc;</code>.</summary>
|
||||
[TestMethod]
|
||||
public override void TestGenericFancyAggregateQuery()
|
||||
{
|
||||
var v = (GetTestTable().Query<Users>(columns: "first,first:AggregateField:count", group: "first", order: ":desc:2") as IEnumerable<dynamic>).ToList();
|
||||
|
||||
Assert.IsNotNull(v);
|
||||
Assert.AreEqual(187, v.Count());
|
||||
Assert.AreEqual(4, v.First().AggregateField);
|
||||
Assert.AreEqual("Logan", v.First().First);
|
||||
Assert.AreEqual(2, v.Take(10).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Take(11).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Last().AggregateField);
|
||||
}
|
||||
|
||||
/// <summary>Test typed <c>First</c> method.</summary>
|
||||
[TestMethod]
|
||||
public override void TestTypedFirst()
|
||||
{
|
||||
Assert.AreEqual(1, GetTestTable().First(type: typeof(Users), columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test typed <c>Last</c> method.</summary>
|
||||
[TestMethod]
|
||||
public override void TestTypedLast()
|
||||
{
|
||||
Assert.AreEqual(200, GetTestTable().Last(type: typeof(Users), columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test typed <c>Single</c> multi.</summary>
|
||||
[TestMethod]
|
||||
public override void TestTypedSingleObject()
|
||||
{
|
||||
var exp = new { id = 19, first = "Ori", last = "Ellis" };
|
||||
var o = GetTestTable().Single(type: typeof(Users), columns: "id,first,last", id: 19);
|
||||
|
||||
Assert.AreEqual(exp.id, o.Id);
|
||||
Assert.AreEqual(exp.first, o.First);
|
||||
Assert.AreEqual(exp.last, o.Last);
|
||||
}
|
||||
|
||||
/// <summary>Test typed where expression equal.</summary>
|
||||
[TestMethod]
|
||||
public override void TestTypedWhereEq()
|
||||
{
|
||||
Assert.AreEqual("hoyt.tran", GetTestTable().Single(type: typeof(Users), where: new DynamicColumn("id").Eq(100)).Login);
|
||||
}
|
||||
|
||||
/// <summary>Test typed where expression like.</summary>
|
||||
[TestMethod]
|
||||
public override void TestTypedWhereLike()
|
||||
{
|
||||
Assert.AreEqual(100, GetTestTable().Single(type: typeof(Users), where: new DynamicColumn("login").Like("Hoyt.%")).Id);
|
||||
}
|
||||
|
||||
/// <summary>Test generic <c>First</c> method.</summary>
|
||||
[TestMethod]
|
||||
public override void TestGenericFirst()
|
||||
{
|
||||
Assert.AreEqual(1, GetTestTable().First<Users>(columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test generic <c>Last</c> method.</summary>
|
||||
[TestMethod]
|
||||
public override void TestGenericLast()
|
||||
{
|
||||
Assert.AreEqual(200, GetTestTable().Last<Users>(columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test generic <c>Single</c> multi.</summary>
|
||||
[TestMethod]
|
||||
public override void TestGenericSingleObject()
|
||||
{
|
||||
var exp = new { id = 19, first = "Ori", last = "Ellis" };
|
||||
var o = GetTestTable().Single<Users>(columns: "id,first,last", id: 19);
|
||||
|
||||
Assert.AreEqual(exp.id, o.Id);
|
||||
Assert.AreEqual(exp.first, o.First);
|
||||
Assert.AreEqual(exp.last, o.Last);
|
||||
}
|
||||
|
||||
/// <summary>Test generic where expression equal.</summary>
|
||||
[TestMethod]
|
||||
public override void TestGenericWhereEq()
|
||||
{
|
||||
Assert.AreEqual("hoyt.tran", GetTestTable().Single<Users>(where: new DynamicColumn("id").Eq(100)).Login);
|
||||
}
|
||||
|
||||
/// <summary>Test generic where expression like.</summary>
|
||||
[TestMethod]
|
||||
public override void TestGenericWhereLike()
|
||||
{
|
||||
Assert.AreEqual(100, GetTestTable().Single<Users>(where: new DynamicColumn("login").Like("Hoyt.%")).Id);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* DynamORM - Dynamic Object-Relational Mapping library.
|
||||
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DynamORM.Tests.Helpers;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Test typed ORM.</summary>
|
||||
[TestFixture]
|
||||
public class RenamedTypedAccessTests : TypedAccessTests<Users>
|
||||
{
|
||||
/// <summary>Test something fancy... like: <code>select "first", count("first") aggregatefield from "users" group by "first" order by 2 desc;</code>.</summary>
|
||||
[Test]
|
||||
public override void TestTypedFancyAggregateQuery()
|
||||
{
|
||||
var v = (GetTestTable().Query(type: typeof(Users), columns: "first,first:AggregateField:count", group: "first", order: ":desc:2") as IEnumerable<dynamic>).ToList();
|
||||
|
||||
Assert.IsNotNull(v);
|
||||
Assert.AreEqual(187, v.Count());
|
||||
Assert.AreEqual(4, v.First().AggregateField);
|
||||
Assert.AreEqual("Logan", v.First().First);
|
||||
Assert.AreEqual(2, v.Take(10).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Take(11).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Last().AggregateField);
|
||||
}
|
||||
|
||||
/// <summary>Test something fancy... like: <code>select "first", count("first") aggregatefield from "users" group by "first" order by 2 desc;</code>.</summary>
|
||||
[Test]
|
||||
public override void TestGenericFancyAggregateQuery()
|
||||
{
|
||||
var v = (GetTestTable().Query<Users>(columns: "first,first:AggregateField:count", group: "first", order: ":desc:2") as IEnumerable<dynamic>).ToList();
|
||||
|
||||
Assert.IsNotNull(v);
|
||||
Assert.AreEqual(187, v.Count());
|
||||
Assert.AreEqual(4, v.First().AggregateField);
|
||||
Assert.AreEqual("Logan", v.First().First);
|
||||
Assert.AreEqual(2, v.Take(10).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Take(11).Last().AggregateField);
|
||||
Assert.AreEqual(1, v.Last().AggregateField);
|
||||
}
|
||||
|
||||
/// <summary>Test typed <c>First</c> method.</summary>
|
||||
[Test]
|
||||
public override void TestTypedFirst()
|
||||
{
|
||||
Assert.AreEqual(1, GetTestTable().First(type: typeof(Users), columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test typed <c>Last</c> method.</summary>
|
||||
[Test]
|
||||
public override void TestTypedLast()
|
||||
{
|
||||
Assert.AreEqual(200, GetTestTable().Last(type: typeof(Users), columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test typed <c>Single</c> multi.</summary>
|
||||
[Test]
|
||||
public override void TestTypedSingleObject()
|
||||
{
|
||||
var exp = new { id = 19, first = "Ori", last = "Ellis" };
|
||||
var o = GetTestTable().Single(type: typeof(Users), columns: "id,first,last", id: 19);
|
||||
|
||||
Assert.AreEqual(exp.id, o.Id);
|
||||
Assert.AreEqual(exp.first, o.First);
|
||||
Assert.AreEqual(exp.last, o.Last);
|
||||
}
|
||||
|
||||
/// <summary>Test typed where expression equal.</summary>
|
||||
[Test]
|
||||
public override void TestTypedWhereEq()
|
||||
{
|
||||
Assert.AreEqual("hoyt.tran", GetTestTable().Single(type: typeof(Users), where: new DynamicColumn("id").Eq(100)).Login);
|
||||
}
|
||||
|
||||
/// <summary>Test typed where expression like.</summary>
|
||||
[Test]
|
||||
public override void TestTypedWhereLike()
|
||||
{
|
||||
Assert.AreEqual(100, GetTestTable().Single(type: typeof(Users), where: new DynamicColumn("login").Like("Hoyt.%")).Id);
|
||||
}
|
||||
|
||||
/// <summary>Test generic <c>First</c> method.</summary>
|
||||
[Test]
|
||||
public override void TestGenericFirst()
|
||||
{
|
||||
Assert.AreEqual(1, GetTestTable().First<Users>(columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test generic <c>Last</c> method.</summary>
|
||||
[Test]
|
||||
public override void TestGenericLast()
|
||||
{
|
||||
Assert.AreEqual(200, GetTestTable().Last<Users>(columns: "id").Id);
|
||||
}
|
||||
|
||||
/// <summary>Test generic <c>Single</c> multi.</summary>
|
||||
[Test]
|
||||
public override void TestGenericSingleObject()
|
||||
{
|
||||
var exp = new { id = 19, first = "Ori", last = "Ellis" };
|
||||
var o = GetTestTable().Single<Users>(columns: "id,first,last", id: 19);
|
||||
|
||||
Assert.AreEqual(exp.id, o.Id);
|
||||
Assert.AreEqual(exp.first, o.First);
|
||||
Assert.AreEqual(exp.last, o.Last);
|
||||
}
|
||||
|
||||
/// <summary>Test generic where expression equal.</summary>
|
||||
[Test]
|
||||
public override void TestGenericWhereEq()
|
||||
{
|
||||
Assert.AreEqual("hoyt.tran", GetTestTable().Single<Users>(where: new DynamicColumn("id").Eq(100)).Login);
|
||||
}
|
||||
|
||||
/// <summary>Test generic where expression like.</summary>
|
||||
[Test]
|
||||
public override void TestGenericWhereLike()
|
||||
{
|
||||
Assert.AreEqual(100, GetTestTable().Single<Users>(where: new DynamicColumn("login").Like("Hoyt.%")).Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user