Ejemplo n.º 1
0
        public void CrossReference_PersistWithOne2ManyChild_WithCrossReference_LoadedShouldBeSameAsPersisted()
        {
            try
            {
                IDbConnection connection  = SetupTables();
                ITransaction  transaction = CreateTransaction(connection);

                int id = 45;
                CrossReferenceTestRootEntity entity = new CrossReferenceTestRootEntity();
                entity.IdCol = id;
                entity.Name  = "Org-Name";
                CrossReferenceTestOne2ManyEntity one2ManyEntity = new CrossReferenceTestOne2ManyEntity();
                one2ManyEntity.IdCol      = id;
                one2ManyEntity.IndexNo    = 1;
                one2ManyEntity.Name       = "Child-Entity";
                one2ManyEntity.RootEntity = entity;
                entity.One2ManyEntities.Add(one2ManyEntity);
                entity.Persist(transaction);
                transaction.Commit();

                transaction = CreateTransaction(connection);
                CrossReferenceTestRootEntity loadedEntity = new CrossReferenceTestRootEntity();
                LoadEntityWithId(transaction, loadedEntity, id);

                Assert.IsNotNull(loadedEntity);
                Assert.IsTrue(loadedEntity.One2ManyEntities.Count == 1);
                IEnumerator <CrossReferenceTestOne2ManyEntity> childEnumerator = loadedEntity.One2ManyEntities.GetEnumerator();
                childEnumerator.MoveNext();
                CrossReferenceTestOne2ManyEntity childOne2ManyEntity = childEnumerator.Current;
                Assert.IsNotNull(childOne2ManyEntity);
                Assert.IsTrue(loadedEntity == childOne2ManyEntity.RootEntity);

                transaction.Commit();
                connection.Close();
            }
            catch (System.Exception e)
            {
                LogManager.GetLogger(typeof(DbGateCrossReferenceTest)).Fatal(e.Message, e);
                Assert.Fail(e.Message);
            }
        }
Ejemplo n.º 2
0
        public void CrossReference_PersistWithOne2OneChild_WithCrossReference_LoadedShouldBeSameAsPersisted()
        {
            try
            {
                IDbConnection connection = SetupTables();

                ITransaction transaction            = CreateTransaction(connection);
                int          id                     = 45;
                CrossReferenceTestRootEntity entity = new CrossReferenceTestRootEntity();
                entity.IdCol = id;
                entity.Name  = "Org-Name";
                CrossReferenceTestOne2OneEntity one2OneEntity = new CrossReferenceTestOne2OneEntity();
                one2OneEntity.IdCol      = id;
                one2OneEntity.Name       = "Child-Entity";
                one2OneEntity.RootEntity = entity;
                entity.One2OneEntity     = one2OneEntity;
                entity.Persist(transaction);
                transaction.Commit();

                transaction = CreateTransaction(connection);
                CrossReferenceTestRootEntity loadedEntity = new CrossReferenceTestRootEntity();
                LoadEntityWithId(transaction, loadedEntity, id);
                transaction.Commit();
                connection.Close();

                Assert.IsNotNull(loadedEntity);
                Assert.IsNotNull(loadedEntity.One2OneEntity);
                Assert.IsNotNull(loadedEntity.One2OneEntity.RootEntity);
                Assert.IsTrue(loadedEntity == loadedEntity.One2OneEntity.RootEntity);
            }
            catch (System.Exception e)
            {
                LogManager.GetLogger(typeof(DbGateCrossReferenceTest)).Fatal(e.Message, e);
                Assert.Fail(e.Message);
            }
        }