示例#1
0
        private IInheritanceTestSubEntityB CreateObjectEmptyTypeB(int type)
        {
            IInheritanceTestSubEntityB entity = null;

            entity = (type == TYPE_ATTRIBUTE)
                         ? new InheritanceTestSubEntityBAttributes()
                         : (type == TYPE_FIELD)
                               ? (IInheritanceTestSubEntityB) new InheritanceTestSubEntityBFields()
                               : new InheritanceTestSubEntityBExt();
            return(entity);
        }
示例#2
0
        private IInheritanceTestSubEntityB CreateObjectWithDataTypeB(int id, int type)
        {
            IInheritanceTestSubEntityB entity = null;

            entity = (type == TYPE_ATTRIBUTE)
                         ? new InheritanceTestSubEntityBAttributes()
                         : (type == TYPE_FIELD)
                               ? (IInheritanceTestSubEntityB) new InheritanceTestSubEntityBFields()
                               : new InheritanceTestSubEntityBExt();
            entity.IdCol = id;
            entity.Name  = "typeB-name";
            entity.NameB = "typeB-nameB";

            return(entity);
        }
示例#3
0
        public void Inheritance_Delete_WithAllModesWithBothSubClasses_ShouldDelete()
        {
            try
            {
                var types = new[] { TYPE_ATTRIBUTE, TYPE_EXTERNAL, TYPE_FIELD };
                var idAs  = new[] { 35, 45, 55 };
                var idBs  = new[] { 36, 46, 56 };

                IDbConnection connection = SetupTables();

                for (int i = 0; i < types.Length; i++)
                {
                    int type = types[i];
                    int idA  = idAs[i];
                    int idB  = idBs[i];

                    switch (type)
                    {
                    case TYPE_ATTRIBUTE:
                        LogManager.GetLogger(typeof(DbGateInheritancePersistTests)).Info(
                            "Inheritance_Delete_WithAllModesWithBothSubClasses_ShouldDelete With attributes");
                        break;

                    case TYPE_EXTERNAL:
                        LogManager.GetLogger(typeof(DbGateInheritancePersistTests)).Info(
                            "Inheritance_Delete_WithAllModesWithBothSubClasses_ShouldDelete With externals");
                        break;

                    case TYPE_FIELD:
                        LogManager.GetLogger(typeof(DbGateInheritancePersistTests)).Info(
                            "Inheritance_Delete_WithAllModesWithBothSubClasses_ShouldDelete With fields");
                        break;
                    }

                    ClearTables(connection);

                    TransactionFactory.DbGate.ClearCache();
                    if (type == TYPE_EXTERNAL)
                    {
                        RegisterForExternal();
                    }

                    IInheritanceTestSuperEntity entityA = CreateObjectWithDataTypeA(idA, type);
                    IInheritanceTestSuperEntity entityB = CreateObjectWithDataTypeB(idB, type);

                    ITransaction transaction = CreateTransaction(connection);
                    entityA.Persist(transaction);
                    entityB.Persist(transaction);
                    transaction.Commit();

                    transaction = CreateTransaction(connection);
                    IInheritanceTestSubEntityA loadedEntityA = CreateObjectEmptyTypeA(type);
                    IInheritanceTestSubEntityB loadedEntityB = CreateObjectEmptyTypeB(type);
                    LoadEntityWithTypeA(transaction, loadedEntityA, idA);
                    LoadEntityWithTypeB(transaction, loadedEntityB, idB);

                    loadedEntityA.Name   = "typeA-changed-name";
                    loadedEntityA.NameA  = "changed-nameA";
                    loadedEntityA.Status = EntityStatus.Deleted;

                    loadedEntityB.Name   = "typeB-changed-name";
                    loadedEntityB.NameB  = "changed-nameB";
                    loadedEntityB.Status = EntityStatus.Deleted;

                    loadedEntityA.Persist(transaction);
                    loadedEntityB.Persist(transaction);

                    IInheritanceTestSubEntityA reLoadedEntityA = CreateObjectEmptyTypeA(type);
                    IInheritanceTestSubEntityB reLoadedEntityB = CreateObjectEmptyTypeB(type);

                    bool reLoadedA     = LoadEntityWithTypeA(transaction, reLoadedEntityA, idA);
                    bool existesSuperA = ExistsSuper(transaction, idA);
                    bool existesSubA   = ExistsSubA(transaction, idA);
                    bool reLoadedB     = LoadEntityWithTypeB(transaction, reLoadedEntityB, idB);
                    bool existesSuperB = ExistsSuper(transaction, idB);
                    bool existesSubB   = ExistsSubB(transaction, idB);

                    Assert.IsFalse(reLoadedA);
                    Assert.IsFalse(existesSuperA);
                    Assert.IsFalse(existesSubA);
                    Assert.IsFalse(reLoadedB);
                    Assert.IsFalse(existesSuperB);
                    Assert.IsFalse(existesSubB);
                    transaction.Commit();
                }

                connection.Close();
            }
            catch (System.Exception e)
            {
                LogManager.GetLogger(typeof(DbGateInheritancePersistTests)).Fatal("Exception during test", e);
                Assert.Fail(e.Message);
            }
        }