public void LinqCreateInConditionTest() { AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase; SelectCommand expectedCommand = fakeDb.CreateSelectCommand(""); SelectCommand actualCommand = fakeDb.CreateSelectCommand(""); SqlConditionBuilder expectedConditionBuilder = expectedCommand.ConditionBuilder; SqlInsideParametersCondition expectedCondition = expectedConditionBuilder.InThese("TestColumn1", "1"); SqlInsideParametersCondition actualCondition = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.InThese("1")) as SqlInsideParametersCondition; Assert.AreEqual(expectedCondition, actualCondition); SqlInsideParametersCondition expectedCondition2 = expectedConditionBuilder.InThese("TestColumn1", "1", "2", "3", "4", "5"); SqlInsideParametersCondition actualCondition2 = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test1.InThese("1", "2", "3", "4", "5")) as SqlInsideParametersCondition; Assert.AreEqual(expectedCondition2, actualCondition2); SqlInsideParametersCondition expectedCondition3 = expectedConditionBuilder.InThese("TestColumn2", 1, 2, 3, 4, 5); SqlInsideParametersCondition actualCondition3 = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test2.InThese(1, 2, 3, 4, 5)) as SqlInsideParametersCondition; Assert.AreEqual(expectedCondition3, actualCondition3); SqlInsideParametersCondition expectedCondition4 = expectedConditionBuilder.InThese("TestColumn5", 1, 2, 3, 4, 5); SqlInsideParametersCondition actualCondition4 = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test5.InThese(1, 2, 3, 4, 5)) as SqlInsideParametersCondition; Assert.AreEqual(expectedCondition4, actualCondition4); TestEntityRepository repository = new TestEntityRepository(fakeDb); TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 }; SqlInsideCommandCondition expectedCondition5 = expectedConditionBuilder.In("TestColumn4", repository.TableName, s => { s.Query("TestColumn4") .Paged(10, 2) .Where <TestEntity>(c => c.Test1 == "test" && c.Test2 != 222 && c.Test4 < DateTime.Now) .OrderBy <TestEntity>(c => c.Test3, SqlOrderType.Desc); }); Action <SelectCommand> createAnotherSelect = s => { s.Query("TestColumn4") .Paged(10, 2) .Where <TestEntity>(sc => sc.Test1 == "test" && sc.Test2 != 222 && sc.Test4 < DateTime.Now) .OrderBy <TestEntity>(sc => sc.Test3, SqlOrderType.Desc); }; SqlInsideCommandCondition actualCondition5 = SqlLinqCondition.Create <TestEntity>(actualCommand, c => c.Test4.In <TestEntity>(createAnotherSelect)) as SqlInsideCommandCondition; Assert.AreEqual(expectedCondition5, actualCondition5); }
public void CreateInConditionTest() { AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase; SelectCommand expectedCommand = fakeDb.CreateSelectCommand(""); SelectCommand actualCommand = fakeDb.CreateSelectCommand(""); SqlConditionBuilder expectedConditionBuilder = expectedCommand.ConditionBuilder; SqlConditionBuilder actualConditionBuilder = actualCommand.ConditionBuilder; SqlInsideParametersCondition expectedCondition = expectedConditionBuilder.InThese("TestColumn2", 1, 2, 3, 4, 5); SqlInsideParametersCondition actualCondition = actualConditionBuilder.InInt32("TestColumn2", "1, 2, 3, 4, 5", ','); Assert.AreEqual(expectedCondition, actualCondition); }