public void EntityInsertTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityDataProvider provider = new TestEntityDataProvider(fakeDb);
            TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 };

            String expectedSql = "INSERT INTO TestTable ( TestColumn1,TestColumn2,TestColumn3,TestColumn4,TestColumn5,TestColumn6,TestColumn7,TestColumn8 ) " +
                "VALUES ( @PN_IDX_0,@PN_IDX_1,@PN_IDX_2,@PN_IDX_3,@PN_IDX_4,@PN_IDX_5,@PN_IDX_6,@PN_IDX_7 )";
            SqlParameter[] expectedParameter = new SqlParameter[8]
            {
                SqlParameter.InternalCreate(fakeDb, "TestColumn1", 0, entity.Test1),
                SqlParameter.InternalCreate(fakeDb, "TestColumn2", 1, entity.Test2),
                SqlParameter.InternalCreate(fakeDb, "TestColumn3", 2, entity.Test3),
                SqlParameter.InternalCreate(fakeDb, "TestColumn4", 3, entity.Test4),
                SqlParameter.InternalCreate(fakeDb, "TestColumn5", 4, DbType.Int32, entity.Test5),
                SqlParameter.InternalCreate(fakeDb, "TestColumn6", 5, DbType.Double, entity.Test6),
                SqlParameter.InternalCreate(fakeDb, "TestColumn7", 6, DbType.DateTime, entity.Test7),
                SqlParameter.InternalCreate(fakeDb, "TestColumn8", 7, DbType.Int16, entity.Test8)
            };

            InsertCommand cmd = fakeDb.CreateInsertCommand(provider.TableName).Add(entity);
            String actualSql = cmd.GetCommandText().Trim();
            SqlParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);

            for (Int32 i = 0; i < actualParameter.Length; i++)
            {
                Assert.AreEqual(expectedParameter[i], actualParameter[i]);
            }
        }
        public void EntityUpdateTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityRepository repository = new TestEntityRepository(fakeDb);
            TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 };

            String expectedSql = "UPDATE TestTable SET TestColumn1=@PN_IDX_0,TestColumn2=@PN_IDX_1,TestColumn3=@PN_IDX_2,TestColumn4=@PN_IDX_3,TestColumn5=@PN_IDX_4,TestColumn6=@PN_IDX_5,TestColumn7=@PN_IDX_6,TestColumn8=@PN_IDX_7";
            DataParameter[] expectedParameter = new DataParameter[8]
            {
                DataParameter.InternalCreate(fakeDb, "TestColumn1", "0", entity.Test1),
                DataParameter.InternalCreate(fakeDb, "TestColumn2", "1", entity.Test2),
                DataParameter.InternalCreate(fakeDb, "TestColumn3", "2", entity.Test3),
                DataParameter.InternalCreate(fakeDb, "TestColumn4", "3", entity.Test4),
                DataParameter.InternalCreate(fakeDb, "TestColumn5", "4", DataType.Int32, entity.Test5),
                DataParameter.InternalCreate(fakeDb, "TestColumn6", "5", DataType.Double, entity.Test6),
                DataParameter.InternalCreate(fakeDb, "TestColumn7", "6", DataType.DateTime, entity.Test7),
                DataParameter.InternalCreate(fakeDb, "TestColumn8", "7", DataType.Int16, entity.Test8)
            };

            UpdateCommand cmd = fakeDb.CreateUpdateCommand(repository.TableName).Set(entity);
            String actualSql = cmd.GetCommandText().Trim();
            DataParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);

            for (Int32 i = 0; i < actualParameter.Length; i++)
            {
                Assert.AreEqual(expectedParameter[i], actualParameter[i]);
            }
        }
        public void LinqInsertTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityRepository repository = new TestEntityRepository(fakeDb);
            TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 };

            String expectedSql = "INSERT INTO TestTable ( TestColumn1,TestColumn2,TestColumn3,TestColumn4,TestColumn5,TestColumn6,TestColumn7,TestColumn8 ) " +
                "VALUES ( @PN_IDX_0,@PN_IDX_1,@PN_IDX_2,@PN_IDX_3,@PN_IDX_4,@PN_IDX_5,@PN_IDX_6,@PN_IDX_7 )";
            DataParameter[] expectedParameter = new DataParameter[8]
            {
                DataParameter.InternalCreate(fakeDb, "TestColumn1", "0", entity.Test1),
                DataParameter.InternalCreate(fakeDb, "TestColumn2", "1", entity.Test2),
                DataParameter.InternalCreate(fakeDb, "TestColumn3", "2", entity.Test3),
                DataParameter.InternalCreate(fakeDb, "TestColumn4", "3", entity.Test4),
                DataParameter.InternalCreate(fakeDb, "TestColumn5", "4", DataType.Int32, entity.Test5),
                DataParameter.InternalCreate(fakeDb, "TestColumn6", "5", DataType.Double, entity.Test6),
                DataParameter.InternalCreate(fakeDb, "TestColumn7", "6", DataType.DateTime, entity.Test7),
                DataParameter.InternalCreate(fakeDb, "TestColumn8", "7", DataType.Int16, entity.Test8)
            };

            InsertCommand cmd = fakeDb.CreateInsertCommand(repository.TableName)
                .Set<TestEntity>(c => c.Test1, entity.Test1)
                .Set<TestEntity>(c => c.Test2, entity.Test2)
                .Set<TestEntity>(c => c.Test3, entity.Test3)
                .Set<TestEntity>(c => c.Test4, entity.Test4)
                .Set<TestEntity>(c => c.Test5, entity.Test5)
                .Set<TestEntity>(c => c.Test6, entity.Test6)
                .Set<TestEntity>(c => c.Test7, entity.Test7)
                .Set<TestEntity>(c => c.Test8, entity.Test8);

            String actualSql = cmd.GetCommandText().Trim();
            DataParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);

            for (Int32 i = 0; i < actualParameter.Length; i++)
            {
                Assert.AreEqual(expectedParameter[i], actualParameter[i]);
            }
        }
        public void LinqUpdateTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityDataProvider provider = new TestEntityDataProvider(fakeDb);
            TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 };

            String expectedSql = "UPDATE TestTable SET TestColumn1=@PN_IDX_0,TestColumn2=@PN_IDX_1,TestColumn3=@PN_IDX_2,TestColumn4=@PN_IDX_3,TestColumn5=@PN_IDX_4,TestColumn6=@PN_IDX_5,TestColumn7=@PN_IDX_6,TestColumn8=@PN_IDX_7";
            SqlParameter[] expectedParameter = new SqlParameter[8]
            {
                SqlParameter.InternalCreate(fakeDb, "TestColumn1", 0, entity.Test1),
                SqlParameter.InternalCreate(fakeDb, "TestColumn2", 1, entity.Test2),
                SqlParameter.InternalCreate(fakeDb, "TestColumn3", 2, entity.Test3),
                SqlParameter.InternalCreate(fakeDb, "TestColumn4", 3, entity.Test4),
                SqlParameter.InternalCreate(fakeDb, "TestColumn5", 4, DbType.Int32, entity.Test5),
                SqlParameter.InternalCreate(fakeDb, "TestColumn6", 5, DbType.Double, entity.Test6),
                SqlParameter.InternalCreate(fakeDb, "TestColumn7", 6, DbType.DateTime, entity.Test7),
                SqlParameter.InternalCreate(fakeDb, "TestColumn8", 7, DbType.Int16, entity.Test8)
            };

            UpdateCommand cmd = fakeDb.CreateUpdateCommand(provider.TableName)
                .Set<TestEntity>(c => c.Test1, entity.Test1)
                .Set<TestEntity>(c => c.Test2, entity.Test2)
                .Set<TestEntity>(c => c.Test3, entity.Test3)
                .Set<TestEntity>(c => c.Test4, entity.Test4)
                .Set<TestEntity>(c => c.Test5, entity.Test5)
                .Set<TestEntity>(c => c.Test6, entity.Test6)
                .Set<TestEntity>(c => c.Test7, entity.Test7)
                .Set<TestEntity>(c => c.Test8, entity.Test8);

            String actualSql = cmd.GetCommandText().Trim();
            SqlParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);

            for (Int32 i = 0; i < actualParameter.Length; i++)
            {
                Assert.AreEqual(expectedParameter[i], actualParameter[i]);
            }
        }
        public void EntityInsertTest()
        {
            AbstractDatabase     fakeDb     = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityRepository repository = new TestEntityRepository(fakeDb);
            TestEntity           entity     = new TestEntity()
            {
                Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8
            };

            String expectedSql = "INSERT INTO TestTable ( TestColumn1,TestColumn2,TestColumn3,TestColumn4,TestColumn5,TestColumn6,TestColumn7,TestColumn8 ) " +
                                 "VALUES ( @PN_IDX_0,@PN_IDX_1,@PN_IDX_2,@PN_IDX_3,@PN_IDX_4,@PN_IDX_5,@PN_IDX_6,@PN_IDX_7 )";

            DataParameter[] expectedParameter = new DataParameter[8]
            {
                DataParameter.InternalCreate(fakeDb, "TestColumn1", "0", entity.Test1),
                DataParameter.InternalCreate(fakeDb, "TestColumn2", "1", entity.Test2),
                DataParameter.InternalCreate(fakeDb, "TestColumn3", "2", entity.Test3),
                DataParameter.InternalCreate(fakeDb, "TestColumn4", "3", entity.Test4),
                DataParameter.InternalCreate(fakeDb, "TestColumn5", "4", DataType.Int32, entity.Test5),
                DataParameter.InternalCreate(fakeDb, "TestColumn6", "5", DataType.Double, entity.Test6),
                DataParameter.InternalCreate(fakeDb, "TestColumn7", "6", DataType.DateTime, entity.Test7),
                DataParameter.InternalCreate(fakeDb, "TestColumn8", "7", DataType.Int16, entity.Test8)
            };

            InsertCommand cmd       = fakeDb.CreateInsertCommand(repository.TableName).Set(entity);
            String        actualSql = cmd.GetCommandText().Trim();

            DataParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);

            for (Int32 i = 0; i < actualParameter.Length; i++)
            {
                Assert.AreEqual(expectedParameter[i], actualParameter[i]);
            }
        }
        public void LinqIncreaseTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityRepository repository = new TestEntityRepository(fakeDb);
            TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 };

            String expectedSql = "UPDATE TestTable SET TestColumn2=(TestColumn2+1)";
            DataParameter[] expectedParameter = new DataParameter[0];

            UpdateCommand cmd = fakeDb.CreateUpdateCommand(repository.TableName).Increase<TestEntity>(c => c.Test2);
            String actualSql = cmd.GetCommandText().Trim();
            DataParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);
            Assert.AreEqual(expectedParameter.Length, actualParameter.Length);
        }
        public void LinqCreateNotInConditionTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            SelectCommand expectedCommand = new SelectCommand(fakeDb, "");
            SelectCommand actualCommand = new SelectCommand(fakeDb, "");

            SqlInsideParametersCondition expectedCondition = SqlCondition.NotIn(expectedCommand, "TestColumn1", "1");
            SqlInsideParametersCondition actualCondition = SqlLinqCondition.Create<TestEntity>(actualCommand, c => c.Test1.NotIn("1")) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition, actualCondition);

            SqlInsideParametersCondition expectedCondition2 = SqlCondition.NotIn(expectedCommand, "TestColumn1", "1", "2", "3", "4", "5");
            SqlInsideParametersCondition actualCondition2 = SqlLinqCondition.Create<TestEntity>(actualCommand, c => c.Test1.NotIn("1", "2", "3", "4", "5")) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition2, actualCondition2);

            SqlInsideParametersCondition expectedCondition3 = SqlCondition.NotIn(expectedCommand, "TestColumn2", 1, 2, 3, 4, 5);
            SqlInsideParametersCondition actualCondition3 = SqlLinqCondition.Create<TestEntity>(actualCommand, c => c.Test2.NotIn(1, 2, 3, 4, 5)) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition3, actualCondition3);

            SqlInsideParametersCondition expectedCondition4 = SqlCondition.NotIn(expectedCommand, "TestColumn5", 1, 2, 3, 4, 5);
            SqlInsideParametersCondition actualCondition4 = SqlLinqCondition.Create<TestEntity>(actualCommand, c => c.Test5.NotIn(1, 2, 3, 4, 5)) as SqlInsideParametersCondition;

            Assert.AreEqual(expectedCondition4, actualCondition4);

            TestEntityDataProvider provider = new TestEntityDataProvider(fakeDb);
            TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 };
            SelectCommand cmd = fakeDb.CreateSelectCommand(provider.TableName)
                .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);

            SqlInsideCommandCondition expectedCondition5 = SqlCondition.NotIn(expectedCommand, "TestColumn4", cmd);
            SqlInsideCommandCondition actualCondition5 = SqlLinqCondition.Create<TestEntity>(actualCommand, c => c.Test4.NotIn(cmd)) as SqlInsideCommandCondition;

            Assert.AreEqual(expectedCondition5, actualCondition5);
        }
        public void LinqIncreaseTest()
        {
            AbstractDatabase fakeDb = DatabaseFactory.CreateDatabase("", "System.Data.SqlClient") as AbstractDatabase;
            TestEntityDataProvider provider = new TestEntityDataProvider(fakeDb);
            TestEntity entity = new TestEntity() { Test1 = "1", Test2 = 2, Test3 = 3.0, Test4 = DateTime.Now, Test8 = 8 };

            String expectedSql = "UPDATE TestTable SET TestColumn2=TestColumn2+1";
            SqlParameter[] expectedParameter = new SqlParameter[1] { SqlParameter.InternalCreateCustomAction(fakeDb, "TestColumn2", "TestColumn2+1") };

            UpdateCommand cmd = fakeDb.CreateUpdateCommand(provider.TableName).Increase<TestEntity>(c => c.Test2);
            String actualSql = cmd.GetCommandText().Trim();
            SqlParameter[] actualParameter = cmd.GetAllParameters();

            Assert.AreEqual(expectedSql, actualSql);
        }