Esempio n. 1
0
        public void CreateAndAssociateColumns()
        {
            var cata           = new Catalogue(CatalogueRepository, "MyCat");
            var cataItem       = new CatalogueItem(CatalogueRepository, cata, "MyCataItem");
            var TableInfo      = new TableInfo(CatalogueRepository, "Cata");
            var ColumnInfo     = new ColumnInfo(CatalogueRepository, "Col", "varchar(10)", TableInfo);
            var ExtractionInfo = new ExtractionInformation(CatalogueRepository, cataItem, ColumnInfo, "fish");

            var ds = new ExtractableDataSet(DataExportRepository, cata);

            var proj   = new Project(DataExportRepository, "MyProj");
            var config = new ExtractionConfiguration(DataExportRepository, proj);

            SelectedDataSets selectedDataSets;

            var extractableColumn = new ExtractableColumn(DataExportRepository, ds, config, ExtractionInfo, 1, "fish");

            try
            {
                selectedDataSets = new SelectedDataSets(DataExportRepository, config, ds, null);

                var cols = config.GetAllExtractableColumnsFor(ds);

                Assert.AreEqual(1, cols.Count());
                Assert.AreEqual(extractableColumn, cols.Single());

                cols = config.GetAllExtractableColumnsFor(ds);

                Assert.AreEqual(1, cols.Count());
                Assert.AreEqual(extractableColumn, cols.Single());
            }
            finally
            {
                extractableColumn.DeleteInDatabase();
                config.DeleteInDatabase();
                proj.DeleteInDatabase();

                ds.DeleteInDatabase();

                TableInfo.DeleteInDatabase();
                cata.DeleteInDatabase();
            }
        }
Esempio n. 2
0
        public void Extract_ProjectSpecificCatalogue_AppendedColumn()
        {
            //make the catalogue a custom catalogue for this project
            CustomExtractableDataSet.Project_ID = _project.ID;
            CustomExtractableDataSet.SaveToDatabase();

            var pipe = SetupPipeline();

            pipe.Name = "Extract_ProjectSpecificCatalogue_AppendedColumn Pipe";
            pipe.SaveToDatabase();

            var extraColumn   = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific).Single(e => e.GetRuntimeName().Equals("SuperSecretThing"));
            var asExtractable = new ExtractableColumn(DataExportRepository, _extractableDataSet, _configuration, extraColumn, 10, extraColumn.SelectSQL);

            //get rid of any lingering joins
            foreach (JoinInfo j in CatalogueRepository.GetAllObjects <JoinInfo>())
            {
                j.DeleteInDatabase();
            }

            //add the ability to join the two tables in the query
            var idCol      = _extractableDataSet.Catalogue.GetAllExtractionInformation(ExtractionCategory.Core).Single(c => c.IsExtractionIdentifier).ColumnInfo;
            var otherIdCol = CustomCatalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific).Single(e => e.GetRuntimeName().Equals("PrivateID")).ColumnInfo;

            new JoinInfo(CatalogueRepository, idCol, otherIdCol, ExtractionJoinType.Left, null);

            //generate a new request (this will include the newly created column)
            _request = new ExtractDatasetCommand(_configuration, new ExtractableDatasetBundle(_extractableDataSet));

            var tbl = Database.ExpectTable("TestTable");

            tbl.Truncate();

            using (var blk = tbl.BeginBulkInsert())
            {
                var dt = new DataTable();
                dt.Columns.Add("PrivateID");
                dt.Columns.Add("Name");
                dt.Columns.Add("DateOfBirth");

                dt.Rows.Add(new object[] { "Priv_12345", "Bob", "2001-01-01" });
                dt.Rows.Add(new object[] { "Priv_wtf11", "Frank", "2001-10-29" });
                blk.Upload(dt);
            }

            ExtractionPipelineUseCase            useCase;
            IExecuteDatasetExtractionDestination results;

            Execute(out useCase, out results);

            var mainDataTableCsv = results.DirectoryPopulated.GetFiles().Single(f => f.Name.Equals("TestTable.csv"));

            Assert.IsNotNull(mainDataTableCsv);
            Assert.AreEqual("TestTable.csv", mainDataTableCsv.Name);

            var lines = File.ReadAllLines(mainDataTableCsv.FullName);

            Assert.AreEqual("ReleaseID,Name,DateOfBirth,SuperSecretThing", lines[0]);

            var bobLine   = lines.Single(l => l.StartsWith("Pub_54321,Bob"));
            var frankLine = lines.Single(l => l.StartsWith("Pub_11ftw,Frank"));

            Assert.AreEqual("Pub_54321,Bob,2001-01-01,monkeys can all secretly fly", bobLine);
            Assert.AreEqual("Pub_11ftw,Frank,2001-10-29,the wizard of OZ was a man behind a machine", frankLine);

            asExtractable.DeleteInDatabase();
        }