Exemple #1
0
        private bool LoadEntityWithId(ITransaction transaction, ConstraintTestDeleteCascadeRootEntity loadEntity, int id)
        {
            bool loaded = false;

            IDbCommand cmd = transaction.CreateCommand();

            cmd.CommandText = "select * from constraint_test_root where id_col = ?";

            IDbDataParameter parameter = cmd.CreateParameter();

            cmd.Parameters.Add(parameter);
            parameter.DbType    = DbType.Int32;
            parameter.Direction = ParameterDirection.Input;
            parameter.Value     = id;

            IDataReader dataReader = cmd.ExecuteReader();

            if (dataReader.Read())
            {
                loadEntity.Retrieve(dataReader, transaction);
                loaded = true;
            }

            return(loaded);
        }
Exemple #2
0
        public void ConstraintValidation_DeleteOneToManyChild_WithCascadeConstraint_ShouldDeleteChild()
        {
            try
            {
                IDbConnection connection = SetupTables();

                ITransaction transaction = CreateTransaction(connection);
                int          id          = 45;
                ConstraintTestDeleteCascadeRootEntity entity = new ConstraintTestDeleteCascadeRootEntity();
                entity.IdCol = id;
                entity.Name  = "Org-Name";
                entity.Persist(transaction);
                transaction.Commit();

                transaction = CreateTransaction(connection);
                ConstraintTestOne2ManyEntity one2ManyEntity = new ConstraintTestOne2ManyEntity();
                one2ManyEntity.IdCol   = id;
                one2ManyEntity.IndexNo = 1;
                one2ManyEntity.Name    = "Child-Org-Name";
                one2ManyEntity.Persist(transaction);
                transaction.Commit();

                transaction = CreateTransaction(connection);
                ConstraintTestDeleteCascadeRootEntity loadedEntity = new ConstraintTestDeleteCascadeRootEntity();
                LoadEntityWithId(transaction, loadedEntity, id);
                IEnumerator <ConstraintTestOne2ManyEntity> childEnumarator = loadedEntity.One2ManyEntities.GetEnumerator();
                childEnumarator.MoveNext();
                ConstraintTestOne2ManyEntity loadedOne2ManyEntity = childEnumarator.Current;
                loadedOne2ManyEntity.Status = EntityStatus.Deleted;
                loadedEntity.Persist(transaction);
                transaction.Commit();

                transaction = CreateTransaction(connection);
                bool hasOneToMany = ExistsOne2ManyChild(transaction, id);
                bool hasRoot      = ExistsRoot(transaction, id);
                transaction.Commit();
                connection.Close();

                Assert.IsFalse(hasOneToMany);
                Assert.IsTrue(hasRoot);
            }
            catch (System.Exception e)
            {
                LogManager.GetLogger(typeof(DbGateConstraintValidationTest)).Fatal(e.Message, e);
                Assert.Fail(e.Message);
            }
        }