public void TypeOfPreLoadDiscardedColumn()
        {
            string methodName    = new StackTrace().GetFrame(0).GetMethod().Name;
            string tableInfoName = "TableInfoFor_" + methodName;
            string preLoadDiscardedColumnName = "PreLoadDiscardedColumnFor_" + methodName;

            TableInfo toCleanup = CatalogueRepository.GetAllObjects <TableInfo>().SingleOrDefault(t => t.Name.Equals(tableInfoName));
            PreLoadDiscardedColumn toCleanupCol = CatalogueRepository.GetAllObjects <PreLoadDiscardedColumn>()
                                                  .SingleOrDefault(c => c.RuntimeColumnName.Equals(preLoadDiscardedColumnName));

            //must delete pre load discarded first
            if (toCleanupCol != null)
            {
                toCleanupCol.DeleteInDatabase();
            }

            if (toCleanup != null)
            {
                toCleanup.DeleteInDatabase();
            }

            var lmd = new LoadMetadata(CatalogueRepository);

            try
            {
                var pt  = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustStaging);
                var pta = new ProcessTaskArgument(CatalogueRepository, pt);

                pta.SetType(typeof(PreLoadDiscardedColumn));

                var tableInfo = new TableInfo(CatalogueRepository, tableInfoName);

                PreLoadDiscardedColumn preloadDiscardedColumn = new PreLoadDiscardedColumn(CatalogueRepository, tableInfo, preLoadDiscardedColumnName);
                try
                {
                    pta.SetValue(preloadDiscardedColumn);
                    pta.SaveToDatabase();

                    var newInstanceOfPTA = CatalogueRepository.GetObjectByID <ProcessTaskArgument>(pta.ID);
                    Assert.AreEqual(newInstanceOfPTA.Value, pta.Value);

                    PreLoadDiscardedColumn p1 = (PreLoadDiscardedColumn)pta.GetValueAsSystemType();
                    PreLoadDiscardedColumn p2 = (PreLoadDiscardedColumn)newInstanceOfPTA.GetValueAsSystemType();

                    Assert.AreEqual(p1.ID, p2.ID);
                }
                finally
                {
                    preloadDiscardedColumn.DeleteInDatabase();
                    tableInfo.DeleteInDatabase();
                }
            }
            finally
            {
                lmd.DeleteInDatabase();
            }
        }
        public void TypeOfTableInfo(bool declareAsInterface)
        {
            string tableInfoName = "TableInfoFor_" + new StackTrace().GetFrame(0).GetMethod().Name;

            TableInfo toCleanup = CatalogueRepository.GetAllObjects <TableInfo>().SingleOrDefault(t => t.Name.Equals(tableInfoName));

            if (toCleanup != null)
            {
                toCleanup.DeleteInDatabase();
            }

            var loadMetadata = new LoadMetadata(CatalogueRepository);

            try
            {
                var pt  = new ProcessTask(CatalogueRepository, loadMetadata, LoadStage.AdjustStaging);
                var pta = new ProcessTaskArgument(CatalogueRepository, pt);

                if (declareAsInterface)
                {
                    pta.SetType(typeof(ITableInfo));
                }
                else
                {
                    pta.SetType(typeof(TableInfo));
                }

                var tableInfo = new TableInfo(CatalogueRepository, tableInfoName);
                try
                {
                    pta.SetValue(tableInfo);
                    pta.SaveToDatabase();

                    var newInstanceOfPTA = CatalogueRepository.GetObjectByID <ProcessTaskArgument>(pta.ID);

                    Assert.AreEqual(newInstanceOfPTA.Value, pta.Value);

                    TableInfo t1 = (TableInfo)pta.GetValueAsSystemType();
                    TableInfo t2 = (TableInfo)newInstanceOfPTA.GetValueAsSystemType();

                    Assert.AreEqual(t1.ID, t2.ID);
                }
                finally
                {
                    tableInfo.DeleteInDatabase();
                }
            }
            finally
            {
                loadMetadata.DeleteInDatabase();
            }
        }
        public void TableInfoType_FetchAfterDelete_ReturnsNull()
        {
            string tableInfoName = "TableInfoFor_" + new StackTrace().GetFrame(0).GetMethod().Name;

            TableInfo toCleanup = CatalogueRepository.GetAllObjects <TableInfo>().SingleOrDefault(t => t.Name.Equals(tableInfoName));

            if (toCleanup != null)
            {
                toCleanup.DeleteInDatabase();
            }

            var lmd = new LoadMetadata(CatalogueRepository);

            try
            {
                var pt  = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustStaging);
                var pta = new ProcessTaskArgument(CatalogueRepository, pt);

                //Prepare to receive a TableInfo object
                pta.SetType(typeof(TableInfo));

                var tableInfo = new TableInfo(CatalogueRepository, tableInfoName);

                //Heres the TableInfo object
                pta.SetValue(tableInfo);
                pta.SaveToDatabase();

                //Lolz I just deleted it out of the database
                tableInfo.DeleteInDatabase();

                //give the object back now please? - returns null because it's gone (new behaviour)
                Assert.IsNull(pta.GetValueAsSystemType());

                //old behaviour

                /*var ex = Assert.Throws<KeyNotFoundException>(()=>pta.GetValueAsSystemType());
                 * StringAssert.Contains("Could not find TableInfo with ID",ex.Message);*/
            }
            finally
            {
                lmd.DeleteInDatabase();
            }
        }