public void TestCustomMetadataReport_ColumnInfoDatatype() { var ei1 = WhenIHaveA <ExtractionInformation>(); var ei2 = WhenIHaveA <ExtractionInformation>(); ei1.CatalogueItem.Catalogue.Name = "Cata1"; ei2.CatalogueItem.Catalogue.Name = "Cata2"; ei1.CatalogueItem.ColumnInfo.Data_type = "varchar(10)"; ei2.CatalogueItem.ColumnInfo.Data_type = "datetime2"; var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"# Welcome We love data here, see our datasets: $foreach Catalogue ## Catalogue '$Name' $Description Price: $30 | Column | Description | Datatype | $foreach CatalogueItem | $Name | $Description | $Data_type | $end $end"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { ei1.CatalogueItem.Catalogue, ei2.CatalogueItem.Catalogue }, outDir, template, "Datasets.md", true, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "Datasets.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"# Welcome We love data here, see our datasets: ## Catalogue 'Cata1' Price: $30 | Column | Description | Datatype | | MyCataItem | | varchar(10) | ## Catalogue 'Cata2' Price: $30 | Column | Description | Datatype | | MyCataItem | | datetime2 |", resultText.TrimEnd()); }
public void TestCustomMetadataReport_LoopCataloguesPrefixAndSuffix() { Setup2Catalogues(out Catalogue c1, out Catalogue c2); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"# Welcome We love data here, see our datasets: $foreach Catalogue ## Catalogue '$Name' $Description Price: $30 | Column | Description | $foreach CatalogueItem | $Name | $Description | $end $end Get in touch with us at [email protected]"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { c1, c2 }, outDir, template, "Datasets.md", true, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "Datasets.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"# Welcome We love data here, see our datasets: ## Catalogue 'Demog' This is expensive dataset: $30 to use Price: $30 | Column | Description | | Name | Name of the patient | | Address | Where they live | | Postcode | Patients postcode | ## Catalogue 'ffff' A cool dataset with interesting stuff Price: $30 | Column | Description | | Col1 | some info about column 1 | | Col2 | some info about column 2 | Get in touch with us at [email protected]", resultText.TrimEnd()); }
public void TestCustomMetadataReport_SingleCatalogue(bool oneFile) { var cata = WhenIHaveA <Catalogue>(); cata.Name = "ffff"; cata.Description = null; cata.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"| Name | Desc| | $Name | $Description |"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { cata }, outDir, template, "$Name.md", oneFile, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "ffff.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"| Name | Desc| | ffff | |", resultText.TrimEnd()); }
public void Test_CustomMetadataElementSeperator_ThrowsWhenNotInForEach() { var templateCode = @" $Name $Comma"; Setup2Catalogues(out Catalogue c1, out Catalogue c2); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, templateCode); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { c1, c2 }, outDir, template, "Datasets.md", true, null); var ex = Assert.Throws <CustomMetadataReportException>(() => cmd.Execute()); Assert.AreEqual("Unexpected use of $Comma outside of an iteration ($foreach) block", ex.Message); }
public void TestCustomMetadataReport_CatalogueItems_TooManyForeachBlocks() { var cata = WhenIHaveA <Catalogue>(); cata.Name = "ffff"; cata.Description = "A cool dataset with interesting stuff"; cata.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"## $Name $Description | Column | Description | $foreach CatalogueItem | $Name | $Description | $foreach CatalogueItem | $Name | $Description | $end $end"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { cata }, outDir, template, "$Name.md", false, null); var ex = Assert.Throws <CustomMetadataReportException>(cmd.Execute); Assert.AreEqual(6, ex.LineNumber); StringAssert.StartsWith("Error, encountered '$foreach CatalogueItem' on line 6", ex.Message); }
public void TestCustomMetadataReport_ErrorCondition_MixingTopLevelBlocks() { Setup2Catalogues(out Catalogue c1, out Catalogue c2); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"# Welcome - Datasets $foreach CatalogueItem $end $foreach Catalogue $end some more text "); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { c1, c2 }, outDir, template, "Datasets.md", true, null); var ex = Assert.Throws <CustomMetadataReportException>(() => cmd.Execute()); Assert.AreEqual("Error, Unexpected '$foreach CatalogueItem' on line 3. Current section is plain text, '$foreach CatalogueItem' can only appear within a '$foreach Catalogue' block (you cannot mix and match top level loop elements)", ex.Message); Assert.AreEqual(3, ex.LineNumber); }
public void TestCustomMetadataReport_ErrorCondition_TooManyEndBlocks() { Setup2Catalogues(out Catalogue c1, out Catalogue c2); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"# Welcome - Datasets $foreach Catalogue $end $end some more text "); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { c1, c2 }, outDir, template, "Datasets.md", true, null); var ex = Assert.Throws <CustomMetadataReportException>(() => cmd.Execute()); Assert.AreEqual("Error, encountered '$end' on line 5 while not in a $foreach Catalogue block", ex.Message); Assert.AreEqual(5, ex.LineNumber); }
public void TestCustomMetadataReport_SingleCatalogueWithNoDQEResults() { var cata = WhenIHaveA <Catalogue>(); cata.Name = "ffff"; cata.Description = null; cata.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"| Name | Desc| Range | | $Name | $Description | $StartDate$EndDate$DateRange |"); var cmd = new ExecuteCommandExtractMetadata(null, new[] { cata }, outDir, template, "$Name.md", false, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "ffff.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"| Name | Desc| Range | | ffff | | Unknown |", resultText.TrimEnd()); }
public void TestCustomMetadataReport_CatalogueItems_NoEndBlock() { var cata = WhenIHaveA <Catalogue>(); cata.Name = "ffff"; cata.Description = "A cool dataset with interesting stuff"; cata.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"## $Name $Description | Column | Description | $foreach CatalogueItem | $Name | $Description |"); var cmd = new ExecuteCommandExtractMetadata(null, new[] { cata }, outDir, template, "$Name.md", false, null); var ex = Assert.Throws <CustomMetadataReportException>(cmd.Execute); Assert.AreEqual(4, ex.LineNumber); Assert.AreEqual("Expected $end to match $foreach which started on line 4", ex.Message); }
public void TestNewlineSubstitution_FullTemplate() { var cata = WhenIHaveA <Catalogue>(); cata.Name = "ffff"; cata.Description = @"A cool dataset with interesting stuff"; cata.SaveToDatabase(); var cataItem1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "Col1"); cataItem1.Description = "some info about column 1"; cataItem1.SaveToDatabase(); var cataItem2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "Col2"); cataItem2.Description = @"some info about column 2"; cataItem2.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"## $Name $Description | Column | Description | $foreach CatalogueItem | $Name | $Description | $end"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { cata }, outDir, template, "$Name.md", false, "<br/>"); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "ffff.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"## ffff A cool<br/>dataset with interesting stuff | Column | Description | | Col1 | some info about column 1 | | Col2 | some info <br/>about column 2 |", resultText.TrimEnd()); }
public void TestTableInfoProperties_OneTableInfo() { var ei = WhenIHaveA <ExtractionInformation>(); var cata = ei.CatalogueItem.Catalogue; cata.Name = "ffff"; cata.Description = "A cool dataset with interesting stuff"; cata.SaveToDatabase(); ei.ColumnInfo.TableInfo.Server = "myserver"; ei.ColumnInfo.TableInfo.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"## $Name Server: $Server Description: $Description"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { cata }, outDir, template, "$Name.md", false, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "ffff.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"## ffff Server: myserver Description: A cool dataset with interesting stuff", resultText); }
public void TestCustomMetadataReport_Nullability_NoDQERun() { var ei1 = WhenIHaveA <ExtractionInformation>(); var ei2 = WhenIHaveA <ExtractionInformation>(); ei1.CatalogueItem.Catalogue.Name = "Cata1"; ei2.CatalogueItem.Catalogue.Name = "Cata2"; ei1.CatalogueItem.Name = "Cata1Col1"; ei2.CatalogueItem.Name = "Cata2Col1"; var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"# Welcome We love data here, see our datasets: $foreach Catalogue ## Catalogue '$Name' $Description Price: $30 Number of Records: $DQE_CountTotal | Column | Description | Nullability | $foreach CatalogueItem | $Name | $Description | $DQE_PercentNull | $end $end"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { ei1.CatalogueItem.Catalogue, ei2.CatalogueItem.Catalogue }, outDir, template, "Datasets.md", true, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "Datasets.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"# Welcome We love data here, see our datasets: ## Catalogue 'Cata1' Price: $30 Number of Records: | Column | Description | Nullability | | Cata1Col1 | | | ## Catalogue 'Cata2' Price: $30 Number of Records: | Column | Description | Nullability | | Cata2Col1 | | |", resultText.TrimEnd()); }
public void TestCustomMetadataReport_TwoCatalogues(bool oneFile) { var cata = WhenIHaveA <Catalogue>(); cata.Name = "Forest"; cata.Administrative_contact_email = "*****@*****.**"; cata.SaveToDatabase(); var cata2 = WhenIHaveA <Catalogue>(); cata2.Name = "Trees"; cata2.Description = "trollolol"; cata2.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.xml")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"<DataSet> <Name>$Name</Name> <Desc>$Description</Desc> <Email>$Administrative_contact_email</Email> </DataSet>"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { cata, cata2 }, outDir, template, oneFile ? "results.xml" : "$Name.xml", oneFile, null); cmd.Execute(); if (oneFile) { var outFile = Path.Combine(outDir.FullName, "results.xml"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase( @"<DataSet> <Name>Forest</Name> <Desc></Desc> <Email>[email protected]</Email> </DataSet> <DataSet> <Name>Trees</Name> <Desc>trollolol</Desc> <Email></Email> </DataSet>", resultText.TrimEnd()); } else { var outFile1 = Path.Combine(outDir.FullName, "Forest.xml"); var outFile2 = Path.Combine(outDir.FullName, "Trees.xml"); FileAssert.Exists(outFile1); FileAssert.Exists(outFile2); var resultText1 = File.ReadAllText(outFile1); StringAssert.AreEqualIgnoringCase( @"<DataSet> <Name>Forest</Name> <Desc></Desc> <Email>[email protected]</Email> </DataSet>".Trim(), resultText1.Trim()); var resultText2 = File.ReadAllText(outFile2); StringAssert.AreEqualIgnoringCase( @"<DataSet> <Name>Trees</Name> <Desc>trollolol</Desc> <Email></Email> </DataSet>".Trim(), resultText2.Trim()); } }
public void Test_CustomMetadataElementSeperator_JsonExample_SemicolonSub() { var templateCode = @"[ $foreach Catalogue { ""Name"": ""$Name"", ""Columns"": [ $foreach CatalogueItem { ""Name"": ""$Name"" }$Comma $end ] }$Comma $end ]"; Setup2Catalogues(out Catalogue c1, out Catalogue c2); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, templateCode); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { c1, c2 }, outDir, template, "Datasets.md", true, null, ";"); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "Datasets.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"[ { ""Name"": ""Demog"", ""Columns"": [ { ""Name"": ""Name"" }; { ""Name"": ""Address"" }; { ""Name"": ""Postcode"" } ] }; { ""Name"": ""ffff"", ""Columns"": [ { ""Name"": ""Col1"" }; { ""Name"": ""Col2"" } ] } ]", resultText.TrimEnd()); }
public void TestCustomMetadataReport_TwoCataloguesWithItems() { var c1 = WhenIHaveA <Catalogue>(); c1.Name = "ffff"; c1.Description = "A cool dataset with interesting stuff"; c1.SaveToDatabase(); var c1ci1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c1, "Col1"); c1ci1.Description = "some info about column 1"; c1ci1.SaveToDatabase(); var c1ci2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c1, "Col2"); c1ci2.Description = "some info about column 2"; c1ci2.SaveToDatabase(); var c2 = WhenIHaveA <Catalogue>(); c2.Name = "Demog"; c2.Description = "This is expensive dataset: $30 to use"; c2.SaveToDatabase(); var c2ci1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Name"); c2ci1.Description = "Name of the patient"; c2ci1.SaveToDatabase(); var c2ci2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Address"); c2ci2.Description = "Where they live"; c2ci2.SaveToDatabase(); var c2ci3 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Postcode"); c2ci3.Description = "Patients postcode"; c2ci3.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"## $Name $Description Price: $30 | Column | Description | $foreach CatalogueItem | $Name | $Description | $end"); var cmd = new ExecuteCommandExtractMetadata(null, new[] { c1, c2 }, outDir, template, "Datasets.md", true, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "Datasets.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"## ffff A cool dataset with interesting stuff Price: $30 | Column | Description | | Col1 | some info about column 1 | | Col2 | some info about column 2 | ## Demog This is expensive dataset: $30 to use Price: $30 | Column | Description | | Name | Name of the patient | | Address | Where they live | | Postcode | Patients postcode |", resultText.TrimEnd()); }