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(); }
public void Extract_ProjectSpecificCatalogue_FilterReference() { //make the catalogue a custom catalogue for this project CustomExtractableDataSet.Project_ID = _project.ID; CustomExtractableDataSet.SaveToDatabase(); var pipe = SetupPipeline(); pipe.Name = "Extract_ProjectSpecificCatalogue_FilterReference Pipe"; pipe.SaveToDatabase(); var rootContainer = new FilterContainer(DataExportRepository); _selectedDataSet.RootFilterContainer_ID = rootContainer.ID; _selectedDataSet.SaveToDatabase(); var filter = new DeployedExtractionFilter(DataExportRepository, "monkeys only", rootContainer); filter.WhereSQL = "SuperSecretThing = 'monkeys can all secretly fly'"; filter.SaveToDatabase(); rootContainer.AddChild(filter); //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); new SelectedDataSetsForcedJoin(DataExportRepository, _selectedDataSet, CustomTableInfo); //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); var lines = File.ReadAllLines(mainDataTableCsv.FullName); Assert.AreEqual("ReleaseID,Name,DateOfBirth", lines[0]); Assert.AreEqual("Pub_54321,Bob,2001-01-01", lines[1]); Assert.AreEqual(2, lines.Length); }