public void TestReconstructionFromCsv() { var opts = new IsIdentifiableRelationalDatabaseOptions(); var dir = new DirectoryInfo(TestContext.CurrentContext.WorkDirectory); foreach (var f in dir.GetFiles("*HappyOzz*.csv")) { f.Delete(); } opts.DestinationCsvFolder = dir.FullName; opts.TableName = "HappyOzz"; opts.StoreReport = true; FailureStoreReport report = new FailureStoreReport("HappyOzz", 1000); report.AddDestinations(opts); var failure = new Failure( new FailurePart[] { new FailurePart("Kansas", FailureClassification.Location, 12), new FailurePart("Toto", FailureClassification.Location, 28) }) { ProblemValue = "We aren't in Kansas anymore Toto", ProblemField = "Narrative", ResourcePrimaryKey = "1.2.3", Resource = "FunBooks.HappyOzz" }; report.Add(failure); report.CloseReport(); var created = dir.GetFiles("*HappyOzz*.csv").SingleOrDefault(); Assert.IsNotNull(created); var report2 = new FailureStoreReport("", 0); var failures2 = report2.Deserialize(created).ToArray(); //read failure ok Assert.AreEqual(1, failures2.Length); Assert.AreEqual(failure.ProblemValue, failures2[0].ProblemValue); Assert.AreEqual(failure.ProblemField, failures2[0].ProblemField); Assert.AreEqual(failure.ResourcePrimaryKey, failures2[0].ResourcePrimaryKey); Assert.AreEqual(failure.Resource, failures2[0].Resource); //read parts ok Assert.AreEqual(2, failures2[0].Parts.Count); Assert.AreEqual(failure.Parts[0].Classification, failures2[0].Parts[0].Classification); Assert.AreEqual(failure.Parts[0].Offset, failures2[0].Parts[0].Offset); Assert.AreEqual(failure.Parts[0].Word, failures2[0].Parts[0].Word); Assert.AreEqual(failure.Parts[1].Classification, failures2[0].Parts[1].Classification); Assert.AreEqual(failure.Parts[1].Offset, failures2[0].Parts[1].Offset); Assert.AreEqual(failure.Parts[1].Word, failures2[0].Parts[1].Word); }
public void TestCsvDestination_Tabs() { var outDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); var opts = new IsIdentifiableRelationalDatabaseOptions { // This is slash t, not an tab DestinationCsvSeparator = "\\t", DestinationNoWhitespace = true, DestinationCsvFolder = outDir.FullName }; var dest = new CsvDestination(opts, "test", false); var report = new TestFailureReport(dest); report.WriteToDestinations(); report.CloseReport(); string fileCreatedContents = File.ReadAllText(Path.Combine(outDir.FullName, "test.csv")); fileCreatedContents = fileCreatedContents.Replace("\r\n", Environment.NewLine); TestHelpers.AreEqualIgnoringLineEndings(@"col1 col2 cell1 with some new lines and tabs cell2 ", fileCreatedContents); }
private static int OnParse(GlobalOptions globals, object parsedOpts) { var opts = SmiCliInit.Verify <IsIdentifiableAbstractOptions>(parsedOpts); return(opts switch { IsIdentifiableRelationalDatabaseOptions o => Run(o), IsIdentifiableDicomFileOptions o => Run(o), IsIdentifiableMongoOptions o => Run(o), IsIdentifiableServiceOptions o => Run(o), IsIdentifiableFileOptions o => Run(o), _ => throw new NotImplementedException($"No case for '{opts.GetType()}'") });
public DatabaseRunner(IsIdentifiableRelationalDatabaseOptions opts) : base(opts) { _opts = opts; }