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 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)); }
public void TestInsertStatementExcludesAutoField_MySql() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); TestAutoInc bo = new TestAutoInc(); InsertStatementGenerator gen = CreateInsertStatementGenerator(bo, DatabaseConfig.MySql); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var statementCol = gen.Generate(); //---------------Test Result ----------------------- var statement = statementCol.First(); Assert.AreEqual("INSERT INTO `testautoinc` (`testfield`) VALUES (?Param0)", statement.Statement.ToString()); }
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 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_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 Form1() { InitializeComponent(); insertTable = new InsertStatementGenerator(); }