public void TestDelimitedTableNameWithSpaces()
 {
     ClassDef.ClassDefs.Clear();
     TestAutoInc.LoadClassDefWithAutoIncrementingID();
     TestAutoInc bo = new TestAutoInc();
     bo.Save();
     ClassDef.ClassDefs[typeof(TestAutoInc)].TableName = "test autoinc";
     bo.TestField = TestUtil.GetRandomString();
     UpdateStatementGenerator gen = new UpdateStatementGenerator(bo, DatabaseConnection.CurrentConnection);
     var statementCol = gen.Generate();
     ISqlStatement statement = statementCol.First();
     StringAssert.Contains("`test autoinc`", statement.Statement.ToString());
 }
        public void TestUpdateStatementExcludesNonPersistableProps()
        {
           
            const string newPropName = "NewProp";
            MockBO bo = StatementGeneratorTestHelper.CreateMockBOWithExtraNonPersistableProp(newPropName);
            bo.SetPropertyValue(newPropName, "newvalue323");
            bo.SetPropertyValue("MockBOProp2", "dfggjh");

            UpdateStatementGenerator gen = new UpdateStatementGenerator(bo, DatabaseConnection.CurrentConnection);
            var statementCol = gen.Generate();
            var sqlStatements = statementCol.ToList();
            Assert.AreEqual(1, sqlStatements.Count);
            ISqlStatement statement = sqlStatements[0];
            Assert.IsFalse(statement.Statement.ToString().Contains(newPropName));
        }
        public void TestUpdateWhenOnlyOneLevelUpdates()
        {
            var myCircle = new FilledCircleInheritsCircleNoPK();
            var committer = new TransactionCommitterStub();
            committer.AddBusinessObject(myCircle);
            committer.CommitTransaction();
            myCircle.SetPropertyValue("Colour", 4);

            var myUpdateSql =
                new UpdateStatementGenerator(myCircle, DatabaseConnection.CurrentConnection).Generate();
            Assert.AreEqual(1, myUpdateSql.Count());
        }
        public virtual IEnumerable <ISqlStatement> GetPersistSql()
        {
            UpdateStatementGenerator gen = new UpdateStatementGenerator(RelatedBO, _databaseConnection);

            return(gen.GenerateForRelationship(Relationship, RelatedBO));
        }
 /// <summary>
 /// Returns an "update" sql statement list for updating this object
 /// </summary>
 /// <returns>Returns a collection of sql statements</returns>
 private IEnumerable<ISqlStatement> GetUpdateSql()
 {
     UpdateStatementGenerator gen = new UpdateStatementGenerator(BusinessObject, _databaseConnection);
     return gen.Generate();
 }
 public void TestUpdateStatementExcludesNonPersistable_InheritanceProps()
 {
     //---------------Set up test pack-------------------
     const string nonPersistablePropertyName = "NonPersistableProp";
     FilledCircleNoPrimaryKey.GetClassDefWithSingleInheritanceHierarchy_NonPersistableProp(nonPersistablePropertyName);
     var filledCircle = new FilledCircleNoPrimaryKey();
     filledCircle.Props[nonPersistablePropertyName].Value = TestUtil.GetRandomString();
     var gen = new UpdateStatementGenerator(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 virtual IEnumerable<ISqlStatement> GetPersistSql()
 {
     UpdateStatementGenerator gen = new UpdateStatementGenerator(RelatedBO, _databaseConnection);
     return gen.GenerateForRelationship(Relationship, RelatedBO);
 }
        public void TestUpdateWhenOnlyOneLevelUpdates()
        {
            IMock connectionControl = new DynamicMock(typeof (IDatabaseConnection));
           // IDatabaseConnection connection = (IDatabaseConnection) connectionControl.MockInstance;
            //connectionControl.ExpectAndReturn("LoadDataReader", null, new object[] {null});
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection());
            //connectionControl.ExpectAndReturn("ExecuteSql", 3, new object[] { null, null });

            FilledCircle myCircle = new FilledCircle();
//            myCircle.SetDatabaseConnection(connection);
            TransactionCommitterStub committer = new TransactionCommitterStub();
            committer.AddBusinessObject(myCircle);
            committer.CommitTransaction();
            //myCircle.Save();
            myCircle.SetPropertyValue("Colour", 4);

            var myUpdateSql = new UpdateStatementGenerator(myCircle, DatabaseConnection.CurrentConnection).Generate();
            Assert.AreEqual(1, myUpdateSql.Count());
            connectionControl.Verify();
        }
        public void TestUpdateWhenOnlyOneLevelUpdates()
        {
            IMock connectionControl = new DynamicMock(typeof (IDatabaseConnection));
            IDatabaseConnection connection = (IDatabaseConnection) connectionControl.MockInstance;
            FilledCircleInheritsCircleNoPK myCircle = new FilledCircleInheritsCircleNoPK();
            TransactionCommitterStub committer = new TransactionCommitterStub();
            committer.AddBusinessObject(myCircle);
            committer.CommitTransaction();
            myCircle.SetPropertyValue("Colour", 4);

            var myUpdateSql =
                new UpdateStatementGenerator(myCircle, DatabaseConnection.CurrentConnection).Generate();
            Assert.AreEqual(1, myUpdateSql.Count());
            connectionControl.Verify();
        }
        public void Test_UpdateSqlStatement()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            OrganisationTestBO organisationTestBO = new OrganisationTestBO();

            SingleRelationship<OrganisationTestBO> singleRelationship = contactPersonTestBO.Relationships.GetSingle<OrganisationTestBO>("Organisation");
            singleRelationship.SetRelatedObject(organisationTestBO);
            IRelationship relationship = organisationTestBO.Relationships.GetMultiple<ContactPersonTestBO>("ContactPeople");
            //TransactionalSingleRelationship_Added tsr = new TransactionalSingleRelationship_Added(singleRelationship);
            UpdateStatementGenerator generator = new UpdateStatementGenerator(contactPersonTestBO, DatabaseConnection.CurrentConnection);
            //---------------Assert PreConditions--------------- 

            //---------------Execute Test ----------------------
            var sql = generator.GenerateForRelationship(relationship, contactPersonTestBO);
            //---------------Test Result -----------------------
            var sqlStatements = sql.ToList();
            Assert.AreEqual(1, sqlStatements.Count);
            Assert.AreEqual("UPDATE `contact_person` SET `OrganisationID` = ?Param0 WHERE `ContactPersonID` = ?Param1", sqlStatements[0].Statement.ToString());
            Assert.AreEqual(organisationTestBO.OrganisationID.Value.ToString("B").ToUpper(), sqlStatements[0].Parameters[0].Value);
            Assert.AreEqual(contactPersonTestBO.ContactPersonID.ToString("B").ToUpper(), sqlStatements[0].Parameters[1].Value);           
        }
        public void Test_UpdateSqlStatement_CompositeKey()
        {
            //---------------Set up test pack-------------------
            TestUsingDatabase.SetupDBDataAccessor();
            Car car = new Car();
            car.Save();

            ContactPersonCompositeKey contactPerson = new ContactPersonCompositeKey();
            contactPerson.PK1Prop1 = TestUtil.GetRandomString();
            contactPerson.PK1Prop2 = TestUtil.GetRandomString();
            contactPerson.Save();

            contactPerson.GetCarsDriven().Add(car);

            SingleRelationship<ContactPersonCompositeKey> singleRelationship = car.Relationships.GetSingle<ContactPersonCompositeKey>("Driver");
            singleRelationship.SetRelatedObject(contactPerson);
            IRelationship relationship = contactPerson.Relationships.GetMultiple<Car>("Driver");
            UpdateStatementGenerator generator = new UpdateStatementGenerator(car, DatabaseConnection.CurrentConnection);
            //---------------Assert PreConditions--------------- 

            //---------------Execute Test ----------------------
            var sql = generator.GenerateForRelationship(relationship, car);
            //---------------Test Result -----------------------
            var sqlStatements = sql.ToList();
            Assert.AreEqual(1, sqlStatements.Count);
            Assert.AreEqual("UPDATE `car_table` SET `Driver_FK1` = ?Param0, `Driver_FK2` = ?Param1 WHERE `CAR_ID` = ?Param2", sqlStatements[0].Statement.ToString());
            Assert.AreEqual(contactPerson.PK1Prop1, sqlStatements[0].Parameters[0].Value);
            Assert.AreEqual(contactPerson.PK1Prop2, sqlStatements[0].Parameters[1].Value);
            Assert.AreEqual(car.CarID.ToString("B").ToUpper(), sqlStatements[0].Parameters[2].Value);

            //---------------Tear Down -------------------------                  
        }
Exemplo n.º 12
0
        /// <summary>
        /// Returns an "update" sql statement list for updating this object
        /// </summary>
        /// <returns>Returns a collection of sql statements</returns>
        private IEnumerable <ISqlStatement> GetUpdateSql()
        {
            UpdateStatementGenerator gen = new UpdateStatementGenerator(BusinessObject, _databaseConnection);

            return(gen.Generate());
        }