示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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());
        }
示例#4
0
        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());
        }
示例#5
0
        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));
        }
示例#6
0
        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());
        }
示例#7
0
        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);
        }
示例#8
0
        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));
        }
示例#9
0
        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);
        }
示例#10
0
 public Form1()
 {
     InitializeComponent();
     insertTable = new InsertStatementGenerator();
 }