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); } }
public void Inheritance_Insert_WithAllModesWithBothSubClasses_ShouldEqualWhenLoaded() { 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_Insert_WithAllModesWithBothSubClasses_ShouldEqualWhenLoaded With attributes"); break; case TYPE_EXTERNAL: LogManager.GetLogger(typeof(DbGateInheritancePersistTests)).Info( "Inheritance_Insert_WithAllModesWithBothSubClasses_ShouldEqualWhenLoaded With externals"); break; case TYPE_FIELD: LogManager.GetLogger(typeof(DbGateInheritancePersistTests)).Info( "Inheritance_Insert_WithAllModesWithBothSubClasses_ShouldEqualWhenLoaded 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); IInheritanceTestSuperEntity loadedEntityA = CreateObjectEmptyTypeA(type); IInheritanceTestSuperEntity loadedEntityB = CreateObjectEmptyTypeB(type); LoadEntityWithTypeA(transaction, loadedEntityA, idA); LoadEntityWithTypeB(transaction, loadedEntityB, idB); transaction.Commit(); bool compareResult = CompareEntities(entityA, loadedEntityA); Assert.IsTrue(compareResult); compareResult = CompareEntities(entityB, loadedEntityB); Assert.IsTrue(compareResult); } connection.Close(); } catch (System.Exception e) { LogManager.GetLogger(typeof(DbGateInheritancePersistTests)).Fatal("Exception during test", e); Assert.Fail(e.Message); } }