Exemple #1
0
        public void CreateTest()
        {
            var factory = new MySQLCommandFactory();

            Assert.IsAssignableFrom <ISelectBuilder>(factory.CreateSelectBuilder());
            Assert.IsAssignableFrom <IInsertBuilder>(factory.CreateInsertBuilder());
            Assert.IsAssignableFrom <IUpdateBuilder>(factory.CreateUpdateBuilder());
            Assert.IsAssignableFrom <IDeleteBuilder>(factory.CreateDeleteBuilder());
        }
        public void InsertTableOneColumnTest()
        {
            var factory = new MySQLCommandFactory();
            var table   = Utils.RandomName();
            var column  = Utils.RandomName();
            var builder = factory.CreateInsertBuilder()
                          .Into(factory.GetDbObjectFactory().CreateTable(table))
                          .Column(factory.GetDbObjectFactory().CreateColumn(column))
                          .Value(factory.GetDbObjectFactory().CreateParameter(column));

            Assert.Equal($"INSERT INTO `{ table }` ( `{ column }` ) VALUES ( @{ column } )", builder.Build());
        }
        public void InsertTableColumnListTest()
        {
            var factory  = new MySQLCommandFactory();
            var table    = Utils.RandomName();
            var column_1 = Utils.RandomName();
            var column_2 = Utils.RandomName();
            var column_3 = Utils.RandomName();
            var columns  = new[] { column_1, column_2, column_3 };
            var builder  = factory.CreateInsertBuilder()
                           .Into(factory.GetDbObjectFactory().CreateTable(table))
                           .Columns(columns.Select(column => factory.GetDbObjectFactory().CreateColumn(column)))
                           .Values(columns.Select(column => factory.GetDbObjectFactory().CreateParameter(column)));

            Assert.Equal($"INSERT INTO `{ table }` ( `{ column_1 }`, `{ column_2 }`, `{ column_3 }` ) VALUES ( @{ column_1 }, @{ column_2 }, @{ column_3 } )", builder.Build());
        }