public void TestSqlStatementTableName()
 {
     MockBO bo = new MockBO();
     InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     InsertSqlStatement statement = (InsertSqlStatement)statementCol.First();
     Assert.AreEqual("MockBO", statement.TableName);
 }
 public void TestAutoIncrementObjNotApplicable()
 {
     MockBO bo = new MockBO();
     InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     InsertSqlStatement statement = (InsertSqlStatement)statementCol.First();
     Assert.AreEqual(null, statement.SupportsAutoIncrementingField);
 }
 public void TestSqlStatementType()
 {
     MockBO bo = new MockBO();
     InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     var sqlStatements = statementCol.ToList();
     Assert.AreEqual(1, sqlStatements.Count);
     Assert.AreSame(typeof(InsertSqlStatement), sqlStatements[0].GetType());
     
 }
 public void TestAutoIncrementObj()
 {
     ClassDef.ClassDefs.Clear();
     TestAutoInc.LoadClassDefWithAutoIncrementingID();
     TestAutoInc bo = new TestAutoInc();
     InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     InsertSqlStatement statement = (InsertSqlStatement)statementCol.First();
     Assert.AreSame(typeof(SupportsAutoIncrementingFieldBO), statement.SupportsAutoIncrementingField.GetType());
 }
 public void TestSingleTableInheritanceHierarchy_SharedDiscriminators()
 {
     //---------------Set up test pack-------------------
     FilledCircleNoPrimaryKey.GetClassDefWithSingleInheritanceHierarchy();
     FilledCircleNoPrimaryKey filledCircle = new FilledCircleNoPrimaryKey();
     InsertStatementGenerator gen = new InsertStatementGenerator(filledCircle, DatabaseConnection.CurrentConnection);
     //---------------Execute Test ----------------------
     var sqlStatementCollection = gen.Generate();
     //---------------Test Result -----------------------
     var sqlStatements = sqlStatementCollection.ToList();
     Assert.AreEqual(1, sqlStatements.Count);
     ISqlStatement sqlStatement = sqlStatements[0];
     string sql = sqlStatement.Statement.ToString();
     int index = sql.IndexOf("ShapeType");
     Assert.IsTrue(index > 0);
     index = sql.IndexOf("ShapeType", index + 1);
     Assert.IsTrue(index < 0, "There were two ShapeType fields specified");
     Assert.AreEqual("FilledCircleNoPrimaryKey", sqlStatement.Parameters[4].Value);
 }
 public void TestInsertStatementExcludesNonPersistable_InheritanceProps()
 {
     //---------------Set up test pack-------------------
     const string nonPersistablePropertyName = "NonPersistableProp";
     FilledCircleNoPrimaryKey.GetClassDefWithSingleInheritanceHierarchy_NonPersistableProp(nonPersistablePropertyName);
     var filledCircle = new FilledCircleNoPrimaryKey();
     var gen = new InsertStatementGenerator(filledCircle, DatabaseConnection.CurrentConnection);
     //---------------Execute Test ----------------------
     var sqlStatementCollection = gen.Generate();
     //---------------Test Result -----------------------
     var sqlStatements = sqlStatementCollection.ToList();
     Assert.AreEqual(1, sqlStatements.Count);
     var sqlStatement = sqlStatements[0];
     var sql = sqlStatement.Statement.ToString();
     Assert.IsFalse(sql.Contains(nonPersistablePropertyName));
 }
 public void TestSingleTableInheritanceHierarchy_DifferentDiscriminators()
 {
     //---------------Set up test pack-------------------
     FilledCircleNoPrimaryKey.GetClassDefWithSingleInheritanceHierarchyDifferentDiscriminators();
     FilledCircleNoPrimaryKey filledCircle = new FilledCircleNoPrimaryKey();
     InsertStatementGenerator gen = new InsertStatementGenerator(filledCircle, DatabaseConnection.CurrentConnection);
     //---------------Execute Test ----------------------
     var sqlStatementCollection = gen.Generate();
     //---------------Test Result -----------------------
     var sqlStatements = sqlStatementCollection.ToList();
     Assert.AreEqual(1, sqlStatements.Count);
     ISqlStatement sqlStatement = sqlStatements[0];
     string sql = sqlStatement.Statement.ToString();
     StringAssert.Contains("ShapeType", sql);
     StringAssert.Contains("CircleType", sql);
 }
        public void TestInsertStatementExcludesReadOnlyProps()
        {
            ClassDef.ClassDefs.Clear();
            const string newPropName = "NewProp";
            MockBO bo = StatementGeneratorTestHelper.CreateMockBOWithExtraReadOnlyProp(newPropName);

            InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
            var statementCol = gen.Generate();
            InsertSqlStatement statement = (InsertSqlStatement)statementCol.First();
            Assert.IsFalse(statement.Statement.ToString().Contains(newPropName));
        }       
 /// <summary>
 /// Returns an "insert" sql statement list for inserting this object
 /// </summary>
 /// <returns>Returns a collection of sql statements</returns>
 private IEnumerable<ISqlStatement> GetInsertSql()
 {
     InsertStatementGenerator gen = new InsertStatementGenerator(BusinessObject, _databaseConnection);
     return gen.Generate();
 }
 public void TestInsertSql()
 {
     Shape shape = new Shape();
     var insertSql = new InsertStatementGenerator(shape, DatabaseConnection.CurrentConnection).Generate();
     var sqlStatements = insertSql.ToList();
     Assert.AreEqual(1, sqlStatements.Count, "There should only be one insert statement.");
     Assert.AreEqual("INSERT INTO `Shape_table` (`ShapeID_field`, `ShapeName`) VALUES (?Param0, ?Param1)",
                     sqlStatements[0].Statement.ToString(), "Insert Sql is being created incorrectly");
 }
        public void TestInsertStatementExcludesAutoField()
        {
            ClassDef.ClassDefs.Clear();
            TestAutoInc.LoadClassDefWithAutoIncrementingID();
            TestAutoInc bo = new TestAutoInc();
            InsertStatementGenerator gen = new InsertStatementGenerator(bo, DatabaseConnection.CurrentConnection);
            var statementCol = gen.Generate();
            InsertSqlStatement statement = (InsertSqlStatement)statementCol.First();

            Assert.AreEqual("INSERT INTO `testautoinc` (`testfield`) VALUES (?Param0)", statement.Statement.ToString());
        }
예제 #12
0
        /// <summary>
        /// Returns an "insert" sql statement list for inserting this object
        /// </summary>
        /// <returns>Returns a collection of sql statements</returns>
        private IEnumerable <ISqlStatement> GetInsertSql()
        {
            InsertStatementGenerator gen = new InsertStatementGenerator(BusinessObject, _databaseConnection);

            return(gen.Generate());
        }