Esempio n. 1
0
        public void update_changeAllProperties_pass()
        {
            TableInfo  parent = new TableInfo(CatalogueRepository, "Rokkits");
            ColumnInfo column = new ColumnInfo(CatalogueRepository, "ExplosiveVol", "varchar(1000)", parent)
            {
                Digitisation_specs = "Highly digitizable",
                Format             = "Jpeg",
                Name      = "mycol",
                Source    = "Bazooka",
                Data_type = "Whatever"
            };

            column.SaveToDatabase();

            ColumnInfo columnAfter = CatalogueRepository.GetObjectByID <ColumnInfo>(column.ID);

            Assert.IsTrue(columnAfter.Digitisation_specs == "Highly digitizable");
            Assert.IsTrue(columnAfter.Format == "Jpeg");
            Assert.IsTrue(columnAfter.Name == "mycol");
            Assert.IsTrue(columnAfter.Source == "Bazooka");
            Assert.IsTrue(columnAfter.Data_type == "Whatever");

            columnAfter.DeleteInDatabase();
            parent.DeleteInDatabase();
        }
Esempio n. 2
0
            public void Dispose()
            {
                if (Catalogue != null)
                {
                    Catalogue.DeleteInDatabase();
                }

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

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

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

                if (Credentials != null)
                {
                    Credentials.DeleteInDatabase();
                }
            }
Esempio n. 3
0
        public void CreateLookup_linkWithSelfThrowsException()
        {
            TableInfo  parent = null;
            ColumnInfo child  = null;
            ColumnInfo child2 = null;
            ColumnInfo child3 = null;

            try
            {
                parent = new TableInfo(CatalogueRepository, "unit_test_CreateLookup");
                child  = new ColumnInfo(CatalogueRepository, "unit_test_CreateLookup", "int", parent);
                child2 = new ColumnInfo(CatalogueRepository, "unit_test_CreateLookup", "int", parent);
                child3 = new ColumnInfo(CatalogueRepository, "unit_test_CreateLookup", "int", parent);

                Assert.Throws <ArgumentException>(() => new Lookup(CatalogueRepository, child, child2, child3, ExtractionJoinType.Left, null));
            }
            finally
            {
                //cleanup
                try{ child.DeleteInDatabase(); }catch (Exception) {}
                try{ child2.DeleteInDatabase(); }catch (Exception) {}
                try{ child3.DeleteInDatabase(); }catch (Exception) {}
                try{ parent.DeleteInDatabase(); }catch (Exception) {}
            }
        }
Esempio n. 4
0
        public void CreateNewTableInfoInDatabase_Naming(string tableName, string columnName)
        {
            TableInfo table = new TableInfo(CatalogueRepository, tableName);

            table.Database = "TestDB";
            table.SaveToDatabase();

            ColumnInfo c = new ColumnInfo(CatalogueRepository, columnName, "varchar(100)", table);

            c.ANOTable_ID = -100;

            try
            {
                Assert.AreEqual("ANOMyCol", c.GetRuntimeName());
                Assert.AreEqual("MyCol", c.GetRuntimeName(LoadStage.AdjustRaw));
                Assert.AreEqual("ANOMyCol", c.GetRuntimeName(LoadStage.PostLoad));

                Assert.AreEqual("TestTableName", table.GetRuntimeName());
                Assert.AreEqual("TestTableName", table.GetRuntimeName(LoadBubble.Raw));
                Assert.AreEqual("TestDB_TestTableName_STAGING", table.GetRuntimeName(LoadBubble.Staging));

                Assert.AreEqual("TestTableName_STAGING", table.GetRuntimeName(LoadBubble.Staging, new SuffixBasedNamer()));
                Assert.AreEqual("TestDB_TestTableName_STAGING", table.GetRuntimeName(LoadBubble.Staging, new FixedStagingDatabaseNamer("TestDB")));

                Assert.AreEqual("TestTableName", table.GetRuntimeName(LoadBubble.Live));
            }
            finally
            {
                c.DeleteInDatabase();
                table.DeleteInDatabase();
            }
        }
Esempio n. 5
0
        public void CreateNewColumnInfoInDatabase_NewColumns_NewColumnsAreEqualAfterSave()
        {
            TableInfo  parent = null;
            ColumnInfo child  = null;

            try
            {
                parent = new TableInfo(CatalogueRepository, "CHI");
                child  = new ColumnInfo(CatalogueRepository, "chi", "varchar(10)", parent)
                {
                    Description     = "The community health index, 10 digits of which the first 6 are date of birth",
                    Status          = ColumnInfo.ColumnStatus.Active,
                    RegexPattern    = "\\d*",
                    ValidationRules = "Last digit must be odd for gents and even for ladies"
                };

                child.SaveToDatabase();

                ColumnInfo childAfter = CatalogueRepository.GetObjectByID <ColumnInfo>(child.ID);

                Assert.AreEqual(child.Name, childAfter.Name);
                Assert.AreEqual(child.Description, childAfter.Description);
                Assert.AreEqual(child.Status, childAfter.Status);
                Assert.AreEqual(child.RegexPattern, childAfter.RegexPattern);
                Assert.AreEqual(child.ValidationRules, childAfter.ValidationRules);
            }
            finally
            {
                child.DeleteInDatabase();
                parent.DeleteInDatabase();
            }
        }
Esempio n. 6
0
        public void AddLinkBetween_createNewLink_pass()
        {
            ///////////////Create the things that we are going to create relationships between /////////////////
            var predator        = new Catalogue(CatalogueRepository, "Predator");
            var lazor           = new CatalogueItem(CatalogueRepository, predator, "QuadlzorVelocity");
            var highEnergyTable = new TableInfo(CatalogueRepository, "HighEnergyShizzle");
            var velocityColumn  = new ColumnInfo(CatalogueRepository, "Velocity Of Matter", "int", highEnergyTable);

            ////////////Check the creation worked ok
            Assert.IsNotNull(predator); //catalogue
            Assert.IsNotNull(lazor);

            Assert.IsNotNull(highEnergyTable); //underlying table stuff
            Assert.IsNotNull(velocityColumn);

            ////////////// Create links between stuff and check they were created successfully //////////////

            //create a link between catalogue item lazor and velocity column
            lazor.SetColumnInfo(velocityColumn);
            Assert.IsTrue(lazor.ColumnInfo.ID == velocityColumn.ID);

            ////////////////cleanup ---- Delete everything that we created -------- //////////////
            velocityColumn.DeleteInDatabase(); //delete causes CASCADE: CatalogueItem no longer associated with ColumnInfo because ColumnInfo died

            lazor.RevertToDatabaseState();

            Assert.IsNull(lazor.ColumnInfo);//involves a database query so won't actually invalidate the below

            predator.DeleteInDatabase();

            highEnergyTable.DeleteInDatabase();
        }
Esempio n. 7
0
        public void AddSameLinkTwice()
        {
            Catalogue     predator        = null;
            CatalogueItem lazor           = null;
            TableInfo     highEnergyTable = null;
            ColumnInfo    velocityColumn  = null;

            try
            {
                ///////////////Create the things that we are going to create relationships between /////////////////
                predator        = new Catalogue(CatalogueRepository, "Predator");
                lazor           = new CatalogueItem(CatalogueRepository, predator, "QuadlzorVelocity");
                highEnergyTable = new TableInfo(CatalogueRepository, "HighEnergyShizzle");
                velocityColumn  = new ColumnInfo(CatalogueRepository, "Velocity Of Matter", "int", highEnergyTable);

                //now you can add as many links as you want, it just skips them
                lazor.SetColumnInfo(velocityColumn);
                Assert.AreEqual(lazor.ColumnInfo, velocityColumn);
            }
            finally
            {
                lazor.DeleteInDatabase();           //delete child
                predator.DeleteInDatabase();        //delete parent

                velocityColumn.DeleteInDatabase();  //delete child
                highEnergyTable.DeleteInDatabase(); //delete parent
            }
        }
Esempio n. 8
0
        public void CreateNewColumnInfoInDatabase_valid_pass()
        {
            TableInfo  parent     = new TableInfo(CatalogueRepository, "Lazors");
            ColumnInfo columnInfo = new ColumnInfo(CatalogueRepository, "Lazor Reflection Vol", "varchar(1000)", parent);

            Assert.NotNull(columnInfo);

            columnInfo.DeleteInDatabase();

            var ex = Assert.Throws <KeyNotFoundException>(() => CatalogueRepository.GetObjectByID <ColumnInfo>(columnInfo.ID));

            Assert.IsTrue(ex.Message.StartsWith("Could not find ColumnInfo with ID " + columnInfo.ID), ex.Message);

            parent.DeleteInDatabase();
        }
        public void TestMissingColumnInfos()
        {
            _extractionInfo1.IsExtractionIdentifier = true;
            _extractionInfo1.SaveToDatabase();
            CreateNewCohortDatabaseWizard wizard = new CreateNewCohortDatabaseWizard(null, CatalogueRepository, DataExportRepository, false);

            //it finds it!
            Assert.IsTrue(wizard.GetPrivateIdentifierCandidates().Any(prototype => prototype.RuntimeName.Equals("PrivateIdentifierA")));

            //delete the column info to make it a missing reference
            _c1.DeleteInDatabase();

            //now it should gracefully skip over it
            Assert.IsFalse(wizard.GetPrivateIdentifierCandidates().Any(prototype => prototype.RuntimeName.Equals("PrivateIdentifierA")));
        }
Esempio n. 10
0
        public void DeleteSetupObjects()
        {
            if (cataItem != null)
            {
                cataItem.DeleteInDatabase();
            }

            cata.DeleteInDatabase();

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

            if (ti != null)
            {
                ti.DeleteInDatabase();
            }
        }
Esempio n. 11
0
        public void CreateLookup_linkWithOtherTable(bool memoryRepo)
        {
            var repo = memoryRepo? (ICatalogueRepository) new MemoryCatalogueRepository():CatalogueRepository;

            TableInfo parent  = null;
            TableInfo parent2 = null;

            ColumnInfo child  = null;
            ColumnInfo child2 = null;
            ColumnInfo child3 = null;

            try
            {
                parent  = new TableInfo(repo, "unit_test_CreateLookup");
                parent2 = new TableInfo(repo, "unit_test_CreateLookupOther");
                child   = new ColumnInfo(repo, "unit_test_CreateLookup", "int", parent);  //lookup desc
                child2  = new ColumnInfo(repo, "unit_test_CreateLookup", "int", parent2); //fk in data table
                child3  = new ColumnInfo(repo, "unit_test_CreateLookup", "int", parent);  //pk in lookup

                new Lookup(repo, child, child2, child3, ExtractionJoinType.Left, null);

                Assert.AreEqual(child.GetAllLookupForColumnInfoWhereItIsA(LookupType.Description).Length, 1);
                Assert.AreEqual(child2.GetAllLookupForColumnInfoWhereItIsA(LookupType.Description).Length, 0);
                Assert.AreEqual(child.GetAllLookupForColumnInfoWhereItIsA(LookupType.AnyKey).Length, 0);
                Assert.AreEqual(child2.GetAllLookupForColumnInfoWhereItIsA(LookupType.AnyKey).Length, 1);
                Assert.AreEqual(child3.GetAllLookupForColumnInfoWhereItIsA(LookupType.AnyKey).Length, 1);


                Assert.IsTrue(parent.IsLookupTable());
                Assert.IsFalse(parent2.IsLookupTable());
            }
            finally
            {
                //cleanup
                try { child.DeleteInDatabase(); }catch (Exception) { }
                try { child2.DeleteInDatabase(); }catch (Exception) { }
                try { child3.DeleteInDatabase(); }catch (Exception) { }
                try { parent.DeleteInDatabase(); }catch (Exception) { }
                try { parent2.DeleteInDatabase(); }catch (Exception) { }
            }
        }
Esempio n. 12
0
        public void GetAllColumnInfos_moreThan1_pass()
        {
            TableInfo parent = new TableInfo(CatalogueRepository, "Slalom");

            try
            {
                var ci = new ColumnInfo(CatalogueRepository, "MyAwesomeColumn", "varchar(1000)", parent);

                try
                {
                    Assert.IsTrue(CatalogueRepository.GetAllObjectsWithParent <ColumnInfo>(parent).Count() == 1);
                }
                finally
                {
                    ci.DeleteInDatabase();
                }
            }
            finally
            {
                parent.DeleteInDatabase();
            }
        }
Esempio n. 13
0
        public void CompositeLookupTest_SQL()
        {
            //this only works for MSSQL Servers
            if (CatalogueRepository.DiscoveredServer.DatabaseType != DatabaseType.MicrosoftSQLServer)
            {
                Assert.Ignore("This test only targets Microsft SQL Servers");
            }

            TableInfo  fkTable = null;
            TableInfo  pkTable = null;
            ColumnInfo desc    = null;
            ColumnInfo fk      = null;
            ColumnInfo pk      = null;

            ColumnInfo fk2 = null;
            ColumnInfo pk2 = null;

            Lookup lookup = null;
            LookupCompositeJoinInfo composite = null;

            try
            {
                //table 1 - the dataset table, it has 2 foreign keys e.g. TestCode, Healthboard
                fkTable = new TableInfo(CatalogueRepository, "UnitTest_Biochemistry");
                fk      = new ColumnInfo(CatalogueRepository, "UnitTest_BCTestCode", "int", fkTable);
                fk2     = new ColumnInfo(CatalogueRepository, "UnitTest_BCHealthBoard", "int", fkTable);

                //table 2 - the lookup table, it has 2 primary keys e.g. TestCode,Healthboard and 1 description e.g. TestDescription (the Healthboard makes it a composite JOIN which allows for the same TestCode being mapped to a different discription in Tayside vs Fife (healthboard)
                pkTable = new TableInfo(CatalogueRepository, "UnitTest_BiochemistryLookup");
                pk      = new ColumnInfo(CatalogueRepository, "UnitTest_TestCode", "int", pkTable);
                pk2     = new ColumnInfo(CatalogueRepository, "UnitTest_Healthboard", "int", pkTable);
                desc    = new ColumnInfo(CatalogueRepository, "UnitTest_TestDescription", "int", pkTable);
                lookup  = new Lookup(CatalogueRepository, desc, fk, pk, ExtractionJoinType.Left, null);

                string joinSQL = JoinHelper.GetJoinSQL(lookup);

                Assert.AreEqual(joinSQL, "UnitTest_Biochemistry Left JOIN UnitTest_BiochemistryLookup ON UnitTest_BCTestCode = UnitTest_TestCode");

                //Create the composite lookup
                composite = new LookupCompositeJoinInfo(CatalogueRepository, lookup, fk2, pk2);

                string joinSQL_AfterAddingCompositeKey = JoinHelper.GetJoinSQL(lookup);

                Assert.AreEqual(joinSQL_AfterAddingCompositeKey, "UnitTest_Biochemistry Left JOIN UnitTest_BiochemistryLookup ON UnitTest_BCTestCode = UnitTest_TestCode AND UnitTest_BCHealthBoard = UnitTest_Healthboard");
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                throw ex;
            }
            finally
            {
                //cleanup
                if (composite != null)
                {
                    composite.DeleteInDatabase();
                }

                lookup.DeleteInDatabase();

                desc.DeleteInDatabase();
                fk.DeleteInDatabase();
                pk.DeleteInDatabase();
                fk2.DeleteInDatabase();
                pk2.DeleteInDatabase();
                fkTable.DeleteInDatabase();
                pkTable.DeleteInDatabase();
            }
        }
Esempio n. 14
0
        public void CompositeLookupTest()
        {
            TableInfo  fkTable = null;
            TableInfo  pkTable = null;
            ColumnInfo desc    = null;
            ColumnInfo fk      = null;
            ColumnInfo pk      = null;

            ColumnInfo fk2 = null;
            ColumnInfo pk2 = null;

            Lookup lookup = null;
            LookupCompositeJoinInfo composite = null;

            try
            {
                //table 1 - the dataset table, it has 2 foreign keys e.g. TestCode, Healthboard
                fkTable = new TableInfo(CatalogueRepository, "UnitTest_Biochemistry");
                fk      = new ColumnInfo(CatalogueRepository, "UnitTest_BCTestCode", "int", fkTable);
                fk2     = new ColumnInfo(CatalogueRepository, "UnitTest_BCHealthBoard", "int", fkTable);

                //table 2 - the lookup table, it has 2 primary keys e.g. TestCode,Healthboard and 1 description e.g. TestDescription (the Healthboard makes it a composite JOIN which allows for the same TestCode being mapped to a different discription in Tayside vs Fife (healthboard)
                pkTable = new TableInfo(CatalogueRepository, "UnitTest_BiochemistryLookup");
                pk      = new ColumnInfo(CatalogueRepository, "UnitTest_TestCode", "int", pkTable);
                pk2     = new ColumnInfo(CatalogueRepository, "UnitTest_Healthboard", "int", pkTable);
                desc    = new ColumnInfo(CatalogueRepository, "UnitTest_TestDescription", "int", pkTable);
                lookup  = new Lookup(CatalogueRepository, desc, fk, pk, ExtractionJoinType.Left, null);

                Assert.AreEqual(lookup.PrimaryKey.Name, pk.Name);
                Assert.AreEqual(lookup.PrimaryKey.ID, pk.ID);

                Assert.AreEqual(lookup.ForeignKey.Name, fk.Name);
                Assert.AreEqual(lookup.ForeignKey.ID, fk.ID);

                Assert.AreEqual(lookup.Description.Name, desc.Name);
                Assert.AreEqual(lookup.Description.ID, desc.ID);

                //Create the composite lookup
                composite = new LookupCompositeJoinInfo(CatalogueRepository, lookup, fk2, pk2);

                Assert.AreEqual(composite.OriginalLookup_ID, lookup.ID);

                Assert.AreEqual(composite.PrimaryKey.ID, pk2.ID);
                Assert.AreEqual(composite.PrimaryKey_ID, pk2.ID);
                Assert.AreEqual(composite.PrimaryKey.Name, pk2.Name);

                Assert.AreEqual(composite.ForeignKey.ID, fk2.ID);
                Assert.AreEqual(composite.ForeignKey_ID, fk2.ID);
                Assert.AreEqual(composite.ForeignKey.Name, fk2.Name);

                //get a fresh copy out of memory now that we have created the Lookup composite key, confirm the integrity of that relationship
                Assert.AreEqual(lookup.GetSupplementalJoins().Count(), 1);
                Assert.AreEqual(lookup.GetSupplementalJoins().Cast <LookupCompositeJoinInfo>().First().ID, composite.ID);

                composite.DeleteInDatabase();
                composite = null;

                Assert.AreEqual(lookup.GetSupplementalJoins().Count(), 0);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                throw;
            }
            finally
            {
                //cleanup
                if (composite != null)
                {
                    composite.DeleteInDatabase();
                }

                lookup.DeleteInDatabase();

                desc.DeleteInDatabase();
                fk.DeleteInDatabase();
                pk.DeleteInDatabase();
                fk2.DeleteInDatabase();
                pk2.DeleteInDatabase();
                fkTable.DeleteInDatabase();
                pkTable.DeleteInDatabase();
            }
        }
Esempio n. 15
0
        public void ExtractableColumnTest()
        {
            ExtractableDataSet      dataSet       = null;
            ExtractionConfiguration configuration = null;
            Project project = null;

            Catalogue     cata     = null;
            CatalogueItem cataItem = null;
            ColumnInfo    column   = null;
            TableInfo     table    = null;

            ExtractionInformation extractionInformation = null;
            ExtractableColumn     extractableColumn     = null;

            try
            {
                //setup catalogue side of things
                cata     = new Catalogue(CatalogueRepository, "unit_test_ExtractableColumnTest_Cata");
                cataItem = new CatalogueItem(CatalogueRepository, cata, "unit_test_ExtractableColumnTest_CataItem");
                table    = new TableInfo(CatalogueRepository, "DaveTable");
                column   = new ColumnInfo(CatalogueRepository, "Name", "string", table);
                cataItem.SetColumnInfo(column);

                extractionInformation = new ExtractionInformation(CatalogueRepository, cataItem, column, "Hashme(Name)");

                //setup extractor side of things
                dataSet = new ExtractableDataSet(DataExportRepository, cata);
                project = new Project(DataExportRepository, "unit_test_ExtractableColumnTest_Proj");

                configuration = new ExtractionConfiguration(DataExportRepository, project);

                extractableColumn = new ExtractableColumn(DataExportRepository, dataSet, configuration, extractionInformation, 0, "Hashme2(Name)");
                Assert.AreEqual(configuration.GetAllExtractableColumnsFor(dataSet).Length, 1);
            }
            finally
            {
                if (extractionInformation != null)
                {
                    extractionInformation.DeleteInDatabase();
                }

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

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

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

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

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

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

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