예제 #1
0
        public void TestMethodInsertOuputSqlAndListOfParameter()
        {
            var created = DateTime.Now.AddDays(-1);

            SqlBuilder raw = new SqlBuilder();

            SqlBuilderInsert insertSqlServer      = raw.InsertFrom("People", SqlServerProvider);
            SqlBuilderInsert insertMysqlServer    = raw.InsertFrom("People", MysqlServerProvider);
            SqlBuilderInsert insertPostgresServer = raw.InsertFrom("People", PostgresServerProvider);

            (string Sql, List <object> Values, object ClassObject)SqlSqlServer      = insertSqlServer.AddColumns("Name", "Created").AddValues("Name 1", created).ToSqlBinding();
            (string Sql, List <object> Values, object ClassObject)SqlMySqlServer    = insertMysqlServer.AddColumns("Name", "Created").AddValues("Name 1", created).ToSqlBinding();
            (string Sql, List <object> Values, object ClassObject)SqlPostgresServer = insertPostgresServer.AddColumns("Name", "Created").AddValues("Name 1", created).ToSqlBinding();

            Assert.AreEqual($"INSERT INTO [People]([Name],[Created]) VALUES(@p0,@p1)", SqlSqlServer.Sql);
            Assert.AreEqual($"INSERT INTO `People`(`Name`,`Created`) VALUES(@p0,@p1)", SqlMySqlServer.Sql);
            Assert.AreEqual($"INSERT INTO \"People\"(\"Name\",\"Created\") VALUES(@p0,@p1)", SqlPostgresServer.Sql);

            Assert.AreEqual("Name 1", SqlSqlServer.Values[0]);
            Assert.AreEqual(created, SqlSqlServer.Values[1]);

            Assert.AreEqual("Name 1", SqlMySqlServer.Values[0]);
            Assert.AreEqual(created, SqlMySqlServer.Values[1]);

            Assert.AreEqual("Name 1", SqlPostgresServer.Values[0]);
            Assert.AreEqual(created, SqlPostgresServer.Values[1]);
        }
예제 #2
0
        public void TestMethodInsertOuputRawSqlNullValue()
        {
            SqlBuilder       raw             = new SqlBuilder();
            SqlBuilderInsert insertSqlServer = raw.InsertFrom("People", SqlServerProvider);

            string strSqlSqlServer = insertSqlServer
                                     .AddColumns("Name", "Created")
                                     .AddValues("Name 1", SqlBuilder.NullValue <DateTime>()).ToRawSql();

            Assert.AreEqual($"INSERT INTO [People]([Name],[Created]) VALUES('Name 1',NULL)", strSqlSqlServer);
        }
예제 #3
0
        public void TestMethodInsertOuputSqlAndListOfParameterWithNull()
        {
            SqlBuilder       raw             = new SqlBuilder();
            SqlBuilderInsert insertSqlServer = raw.InsertFrom("People", SqlServerProvider);

            (string Sql, List <object> Values, object ClassObject)SqlSqlServer = insertSqlServer
                                                                                 .AddColumns("Name", "Created")
                                                                                 .AddValues("Name 1", SqlBuilder.NullValue <DateTime>())
                                                                                 .ToSqlBinding();

            Assert.AreEqual("INSERT INTO [People]([Name],[Created]) VALUES(@p0,@p1)", SqlSqlServer.Sql);

            PropertyInfo[] infoClassObject = SqlSqlServer.ClassObject.GetType().GetProperties();
            Assert.AreEqual("Name 1", infoClassObject[0].GetValue(SqlSqlServer.ClassObject));
            Assert.AreEqual(null, infoClassObject[1].GetValue(SqlSqlServer.ClassObject));
        }
예제 #4
0
        public void TestMethodInsertOuputRawSql()
        {
            var created = DateTime.Now.AddDays(-1);

            SqlBuilder raw = new SqlBuilder();

            SqlBuilderInsert insertSqlServer      = raw.InsertFrom("People", SqlServerProvider);
            SqlBuilderInsert insertMysqlServer    = raw.InsertFrom("People", MysqlServerProvider);
            SqlBuilderInsert insertPostgresServer = raw.InsertFrom("People", PostgresServerProvider);

            string strSqlSqlServer      = insertSqlServer.AddColumns("Name", "Created").AddValues("Name 1", created).ToRawSql();
            string strSqlMySqlServer    = insertMysqlServer.AddColumns("Name", "Created").AddValues("Name 1", created).ToRawSql();
            string strSqlPostgresServer = insertPostgresServer.AddColumns("Name", "Created").AddValues("Name 1", created).ToRawSql();

            Assert.AreEqual($"INSERT INTO [People]([Name],[Created]) VALUES('Name 1','{created}')", strSqlSqlServer);
            Assert.AreEqual($"INSERT INTO `People`(`Name`,`Created`) VALUES('Name 1','{created}')", strSqlMySqlServer);
            Assert.AreEqual($"INSERT INTO \"People\"(\"Name\",\"Created\") VALUES('Name 1','{created}')", strSqlPostgresServer);
        }