public void SetUp() { var dependencies = ComTestHelper.ModifyAndBuildComDependencies(); LoggingHelper.InitConsoleLogger("PDFCreatorTest", LoggingLevel.Off); _queue = new Queue(); _queue.Initialize(); var assembly = GetType().Assembly; var assemblyHelper = new AssemblyHelper(assembly); var translationHelper = new TranslationHelper(new DefaultSettingsProvider(), assemblyHelper, new TranslationFactory(), null); translationHelper.InitTranslator("None"); var folderProvider = new FolderProvider(new PrinterPortReader(new RegistryWrap()), new PathWrap()); var testPageCreator = new TestPageCreator(new ApplicationNameProvider("FREE"), new VersionHelper(new Version(1, 0, 0, 0)), new OsHelper()); _testPageHelper = new TestPageHelper(folderProvider, dependencies.QueueAdapter.JobInfoQueue, new JobInfoManager(new LocalTitleReplacerProvider(new List <TitleReplacement>()), null), testPageCreator); CreateTestPages(1); _printJob = _queue.NextJob; _printJobInfo = _printJob.PrintJobInfo; }
public void Using_Any_On_All_Text_Takes_All_Text() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Text", "234.3"); pageCreator.SetValue(4, 6, "Text", "5%"); pageCreator.SetValue(4, 7, "Text", "Correct"); pageCreator.SetValue(6, 4, "Text", "Hello"); pageCreator.SetValue(6, 5, "Text", "234.3"); pageCreator.SetValue(6, 6, "Text", "5%"); pageCreator.SetValue(6, 7, "Text", "Also correct"); string query = "Any [Text];"; var result = Visit(query, pageCreator.Page); Assert.IsTrue(result.Results["0"].Result.Count == 8); Assert.AreEqual("Hello", result.Results["0"].GetResultAt(0)); Assert.AreEqual("234.3", result.Results["0"].GetResultAt(1)); Assert.AreEqual("5%", result.Results["0"].GetResultAt(2)); Assert.AreEqual("Correct", result.Results["0"].GetResultAt(3)); Assert.AreEqual("Hello", result.Results["0"].GetResultAt(4)); Assert.AreEqual("234.3", result.Results["0"].GetResultAt(5)); Assert.AreEqual("5%", result.Results["0"].GetResultAt(6)); Assert.AreEqual("Also correct", result.Results["0"].GetResultAt(7)); }
public void Does_Ignore_Comments() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Amount", "234.3"); pageCreator.SetValue(4, 6, "Percentage", "5%"); pageCreator.SetValue(4, 7, "Text", "Correct"); string query = @" /* Block comment at top */ // This is a comment TestLabel: // Comment on a label /* Block comment below label */ [StreetAddress]; // Comment on a text type [Text]; // Comment above text type [Email]; //Comment at bottom /* Block comment at eof */ "; var result = Visit(query, pageCreator.Page); Assert.AreEqual("TestLabel", result.Results.First().Key); }
public void Can_Trim_To_Straight_Row() { TestPageCreator testPageCreator = new TestPageCreator(3, 2); testPageCreator.SetValue(0, 0, "Text", "Text 1", new PageUnitBoundingBox(0, 0, 1, 1)); testPageCreator.SetValue(1, 1, "Text", "Text 2", new PageUnitBoundingBox(20, 5, 1, 1)); testPageCreator.SetValue(2, 0, "Text", "Text 2", new PageUnitBoundingBox(40, 0, 1, 1)); var test = pageTrimmer.TrimPage(testPageCreator.Page); Assert.IsNotNull(test.Contents[1, 0].First()); Assert.AreEqual(test.Contents[0, 0].First().Coordinate.Y, test.Contents[1, 0].First().Coordinate.Y); }
public void Can_Trim_To_Straight_Column() { TestPageCreator testPageCreator = new TestPageCreator(2, 3); testPageCreator.SetValue(0, 0, "Text", "Text 1", new PageUnitBoundingBox(0, 0, 1, 1)); testPageCreator.SetValue(1, 1, "Text", "Text 2", new PageUnitBoundingBox(5, 20, 1, 1)); testPageCreator.SetValue(0, 2, "Text", "Text 2", new PageUnitBoundingBox(0, 40, 1, 1)); var test = pageTrimmer.TrimPage(testPageCreator.Page); Assert.IsNotNull(test.Contents[0, 1].First()); Assert.AreEqual(test.Contents[0, 0].First().Coordinate.X, test.Contents[0, 1].First().Coordinate.X); }
public void Stops_When_Pattern_Missing_Page_Units() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 7, "Date", "2019-06-05"); string query = "Text Down Amount Down Percentage Down 'CaptureThis': [Date];"; var result = Visit(query, pageCreator.Page); Assert.IsTrue(result.Results.Count == 0); }
public void Can_Move_PageUnit() { TestPageCreator testPageCreator = new TestPageCreator(2, 3); testPageCreator.SetValue(0, 0, "Text", "Text 1", new PageUnitBoundingBox(0, 0, 1, 1)); testPageCreator.SetValue(1, 1, "Text", "Text 2", new PageUnitBoundingBox(5, 5, 1, 1)); testPageCreator.SetValue(0, 2, "Text", "Text 2", new PageUnitBoundingBox(0, 10, 1, 1)); var test = pageTrimmer.MovePageUnit(testPageCreator.Page, new Coordinate(1, 1), new Coordinate(0, 1)); Assert.IsNotNull(test); Assert.IsNotNull(testPageCreator.Page.Contents[0, 1].FirstOrDefault()); Assert.IsNull(testPageCreator.Page.Contents?[1, 1]?.FirstOrDefault()); }
public void Can_Do_RightDown_Down_Search() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(0, 0, "Text", "Find"); pageCreator.SetValue(0, 5, "Text", "Hello"); pageCreator.SetValue(6, 0, "Text", "World"); string query = "Text(Find) RD 6 [Text];"; var result = Visit(query, pageCreator.Page); Assert.AreEqual("Hello", result.Results["0"].Result["0"]); }
public void Can_Do_RightDown_Search_Middle_Of_Page() { var pageCreator = new TestPageCreator(30, 30); pageCreator.SetValue(15, 15, "Text", "Find"); pageCreator.SetValue(18, 15, "Text", "Hello"); pageCreator.SetValue(15, 19, "Text", "World"); string query = "Text(Find) RD 6 [Text];"; var result = Visit(query, pageCreator.Page); Assert.AreEqual("Hello", result.Results["0"].Result["0"]); }
public void Fails_With_ParseCancelledException_On_Mismatch() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 6, "Amount", "234.3"); pageCreator.SetValue(4, 7, "Percentage", "5%"); string query = "Text Down Amount Down Percentage Down 'CaptureThis': [Date];"; var result = Visit(query, pageCreator.Page); Assert.IsTrue(result.Results.Count == 0); }
public void Can_Subset_Left_Half() { var pageCreator = new TestPageCreator(2, 2); pageCreator.SetValue(0, 0, "Text", "Hello"); pageCreator.SetValue(0, 1, "Number", "5"); pageCreator.SetValue(1, 0, "Text", "Hello"); pageCreator.SetValue(1, 1, "Number", "3"); string query = "Subset(Left 50) Text(Hello) Down [Number];"; var result = Visit(query, pageCreator.Page); Assert.AreEqual("5", result.Results.First().Value.Result.First().Value); }
public void Stops_When_Cant_Match_Content() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Text", "Bad match"); pageCreator.SetValue(4, 6, "Percentage", "5%"); pageCreator.SetValue(4, 7, "Date", "2019-06-05"); string query = "Text Down Text(Test string) Down Percentage Down 'CaptureThis': [Date];"; var result = Visit(query, pageCreator.Page); Assert.IsTrue(result.Results.Count == 0); }
public void Can_Subset_Bottom_Half() { var pageCreator = new TestPageCreator(2, 2); pageCreator.SetValue(0, 0, "Text", "Hello"); pageCreator.SetValue(0, 1, "Number", "5"); pageCreator.SetValue(1, 0, "Text", "Hello world!"); pageCreator.SetValue(1, 1, "Number", "3"); string query = "Subset(Bottom 50) Number Right [Number];"; var result = Visit(query, pageCreator.Page); Assert.AreEqual("3", result.Results.First().Value.Result.First().Value); }
public void Can_Assign_Query_Label() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Amount", "234.3"); pageCreator.SetValue(4, 6, "Percentage", "5%"); pageCreator.SetValue(4, 7, "Text", "Correct"); string query = "TestLabel: [Text];"; var result = Visit(query, pageCreator.Page); Assert.AreEqual("TestLabel", result.Results.First().Key); }
public void Can_Do_RightDown_Search_And_Continue_From_It() { var pageCreator = new TestPageCreator(30, 30); pageCreator.SetValue(15, 15, "Text", "Find"); pageCreator.SetValue(18, 15, "Text", "Hello"); pageCreator.SetValue(15, 19, "Text", "World"); pageCreator.SetValue(18, 21, "Amount", "3.0"); string query = "Text(Find) RD 6 Text Down 'CoolStuff': [Amount];"; var result = Visit(query, pageCreator.Page); Assert.AreEqual("3.0", result.Results["0"].Result["CoolStuff"]); }
public void Can_Analyze_Table_Script() { var fakePage = new TestPageCreator(5, 10); fakePage.SetValue(0, 0, "Number", "ItemNo"); fakePage.SetValue(1, 0, "Text", "Description"); fakePage.SetValue(2, 0, "Number", "Quantity"); fakePage.SetValue(3, 0, "Amount", "Unit price"); fakePage.SetValue(4, 0, "Amount", "Amount"); fakePage.SetValue(0, 1, "Number", "22"); fakePage.SetValue(0, 2, "Number", "33"); fakePage.SetValue(0, 3, "Number", "44"); fakePage.SetValue(1, 1, "Text", "A"); fakePage.SetValue(1, 2, "Text", "B"); fakePage.SetValue(1, 3, "Text", "C"); fakePage.SetValue(2, 1, "Number", "3"); fakePage.SetValue(2, 2, "Number", "2"); fakePage.SetValue(2, 3, "Number", "5"); fakePage.SetValue(3, 1, "Amount", "500.0"); fakePage.SetValue(3, 2, "Amount", "245.5"); fakePage.SetValue(3, 3, "Amount", "899.99"); fakePage.SetValue(4, 1, "Amount", "1250.5"); fakePage.SetValue(4, 2, "Amount", "1500.2"); fakePage.SetValue(4, 3, "Amount", "1345.3"); var script = @" AnalyzedTable: Table 'ItemNumber': [Number(ItemNo)] 'ItemDescription': [Text(Description)] 'Quantity': [Number(Quantity)] 'ItemPrice': [Amount(Unit price)] 'TotalAmount': [Amount(Amount)]; "; var result = Visit(script, fakePage.Page).ConvertToJson(script); // Just looking at result via breakpoint atm Assert.IsNotNull(result); }
public void Can_Match_Multiple_Captures() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Amount", "234.3"); pageCreator.SetValue(4, 6, "Percentage", "5%"); pageCreator.SetValue(4, 7, "Text", "Correct"); string query = "Text Down [Amount] Down Percentage Down [Text];"; var result = Visit(query, pageCreator.Page); Assert.IsTrue(result.Results.Count == 1); Assert.AreEqual("0", result.Results["0"].Result.First().Key); Assert.AreEqual("234.3", result.Results["0"].GetResultAt(0)); Assert.AreEqual("Correct", result.Results["0"].GetResultAt(1)); }
public void Can_Interpret_Continuous_Page_Pattern() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Amount", "234.3"); pageCreator.SetValue(4, 6, "Percentage", "5%"); pageCreator.SetValue(4, 7, "Date", "2019-06-05"); string query = "Text Down Amount Down Percentage Down 'CaptureThis': [Date];"; var result = Visit(query, pageCreator.Page); Assert.IsTrue(result.Results.Count == 1); Assert.IsTrue(result.Results["0"].Result.Count == 1); Assert.AreEqual("CaptureThis", result.Results["0"].Result.ToArray()[0].Key); Assert.AreEqual("2019-06-05", result.Results["0"].GetResultAt(0)); }
public void SetUp() { var dependencies = ComTestHelper.ModifyAndBuildComDependencies(); LoggingHelper.InitConsoleLogger("PDFCreatorTest", LoggingLevel.Off); var installationPathProvider = new InstallationPathProvider(@"Software\pdfforge\PDFCreator\Settings", @"Software\pdfforge\PDFCreator", "{00000000-0000-0000-0000-000000000000}", RegistryHive.CurrentUser); var settingsProvider = new DefaultSettingsProvider(); var translationHelper = new TranslationHelper(settingsProvider, new AssemblyHelper(GetType().Assembly), new TranslationFactory(), null); translationHelper.InitTranslator("None"); var defaultSettingsBuilder = Substitute.For <IDefaultSettingsBuilder>(); defaultSettingsBuilder. CreateEmptySettings(). Returns(new PdfCreatorSettings()); defaultSettingsBuilder. CreateDefaultSettings(Arg.Any <string>(), Arg.Any <string>()). Returns(new PdfCreatorSettings()); defaultSettingsBuilder. CreateDefaultProfile(). Returns(new ConversionProfile()); var migrationStorageFactory = Substitute.For <IMigrationStorageFactory>(); var settingsLoader = new SettingsLoader(translationHelper, Substitute.For <ISettingsMover>(), installationPathProvider, Substitute.For <IPrinterHelper>(), new EditionHelper(false, false), defaultSettingsBuilder, migrationStorageFactory); var settingsManager = new SettingsManager(settingsProvider, settingsLoader, installationPathProvider, new VersionHelper(Assembly.GetExecutingAssembly()), new List <IFirstTimeCommand>()); settingsManager.LoadAllSettings(); var folderProvider = new FolderProvider(new PrinterPortReader(new RegistryWrap()), new PathWrap()); _queue = new Queue(); _queue.Initialize(); var testPageCreator = new TestPageCreator(new ApplicationNameProvider("FREE"), new VersionHelper(new Version(1, 0, 0, 0)), new OsHelper()); _testPageHelper = new TestPageHelper(folderProvider, dependencies.QueueAdapter.JobInfoQueue, new JobInfoManager(new LocalTitleReplacerProvider(new List <TitleReplacement>()), null), testPageCreator); }
public void Does_Prioritize_Patterns() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Amount", "234.3"); pageCreator.SetValue(4, 6, "Percentage", "5%"); pageCreator.SetValue(4, 7, "Text", "Correct"); string query = @" TestLabel: Text(Wrong) Up Left [Text]; Text Down Amount Down [Percentage] Down [Text]; Percentage Down [Text]; "; var result = Visit(query, pageCreator.Page); Assert.AreEqual("5%", result.Results["TestLabel"].GetResultAt(0)); Assert.AreEqual("Correct", result.Results["TestLabel"].GetResultAt(1)); }
public void Can_Assign_Query_Multiple_Result_Labels() { var pageCreator = new TestPageCreator(20, 20); pageCreator.SetValue(4, 4, "Text", "First"); pageCreator.SetValue(8, 4, "Text", "Value1"); pageCreator.SetValue(4, 5, "Text", "Second"); pageCreator.SetValue(8, 5, "Text", "Value2"); string query = @" Label1: Text(First) Right [Text]; Label2: Text(Second) Right [Text]; "; var result = Visit(query, pageCreator.Page); Assert.AreEqual("Value1", result.Results["Label1"].GetResultAt(0)); Assert.AreEqual("Value2", result.Results["Label2"].GetResultAt(0)); }
public void Takes_First_Matching_Pattern() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 5, "Amount", "234.3"); pageCreator.SetValue(4, 6, "Percentage", "5%"); pageCreator.SetValue(4, 7, "Text", "Correct"); pageCreator.SetValue(6, 4, "Text", "Hello"); pageCreator.SetValue(6, 5, "Amount", "234.3"); pageCreator.SetValue(6, 6, "Percentage", "5%"); pageCreator.SetValue(6, 7, "Text", "Incorrect"); string query = "Text Down Amount Down Percentage Down [Text];"; var result = Visit(query, pageCreator.Page); Assert.IsTrue(result.Results.Count == 1); Assert.IsTrue(result.Results["0"].Result.Count == 1); Assert.AreEqual("0", result.Results["0"].Result.ToArray()[0].Key); Assert.AreEqual("Correct", result.Results["0"].GetResultAt(0)); }
public void Can_Match_TextType_With_Or() { var pageCreator = new TestPageCreator(10, 10); pageCreator.SetValue(4, 4, "Text", "Hello"); pageCreator.SetValue(4, 7, "Date", "2019-06-05"); pageCreator.SetValue(4, 9, "Number", "5"); string firstQuery = "Date || Text(Hello) Down [Number || Date];"; var firstResult = Visit(firstQuery, pageCreator.Page); Assert.IsTrue(firstResult.Results.Count == 1); Assert.IsTrue(firstResult.Results["0"].Result.Count == 1); Assert.AreEqual("2019-06-05", firstResult.Results["0"].GetResultAt(0)); string secondQuery = "Date || Text(John) || Number Down [Number || Date];"; var secondResult = Visit(secondQuery, pageCreator.Page); Assert.IsTrue(secondResult.Results.Count == 1); Assert.IsTrue(secondResult.Results["0"].Result.Count == 1); Assert.AreEqual("5", secondResult.Results["0"].GetResultAt(0)); }
public void Can_Analyze_Basic_Table() { var fakePage = new TestPageCreator(5, 10); fakePage.SetValue(0, 0, "Number", "ItemNo"); fakePage.SetValue(1, 0, "Text", "Description"); fakePage.SetValue(2, 0, "Number", "Quantity"); fakePage.SetValue(3, 0, "Amount", "Unit price"); fakePage.SetValue(4, 0, "Amount", "Amount"); fakePage.SetValue(0, 1, "Number", "22"); fakePage.SetValue(0, 2, "Number", "33"); fakePage.SetValue(0, 3, "Number", "44"); fakePage.SetValue(1, 1, "Text", "A"); fakePage.SetValue(1, 2, "Text", "B"); fakePage.SetValue(1, 3, "Text", "C"); fakePage.SetValue(2, 1, "Number", "3"); fakePage.SetValue(2, 2, "Number", "2"); fakePage.SetValue(2, 3, "Number", "5"); fakePage.SetValue(3, 1, "Amount", "500.0"); fakePage.SetValue(3, 2, "Amount", "245.5"); fakePage.SetValue(3, 3, "Amount", "899.99"); fakePage.SetValue(4, 1, "Amount", "1250.5"); fakePage.SetValue(4, 2, "Amount", "1500.2"); fakePage.SetValue(4, 3, "Amount", "1345.3"); // var script = @" //AnalyzedTable: //Table //'ItemNumber': [Number(ItemNo)] //'ItemDescription': [Text(Description)] //'Quantity': [Number(Quantity)] //'ItemPrice': [Amount(Unit price)] //'TotalAmount': [Amount(Amount)]; //"; // var result = Visit(script, fakePage.Page); var tableAnalyzer = new TableAnalyzer(); var analysis = tableAnalyzer.AnalyzeTable(fakePage.Page, "Test", new PageInterpreter.DataModel.TableColumn[] { new PageInterpreter.DataModel.TableColumn() { ColumnName = "ItemNumber", LabelParameters = new string[] { "ItemNo" }, TextType = "Number" }, new PageInterpreter.DataModel.TableColumn() { ColumnName = "Description", LabelParameters = new string[] { "Description" }, TextType = "Text" }, new PageInterpreter.DataModel.TableColumn() { ColumnName = "Quantity", LabelParameters = new string[] { "Quantity" }, TextType = "Number" }, new PageInterpreter.DataModel.TableColumn() { ColumnName = "UnitPrice", LabelParameters = new string[] { "Unit price" }, TextType = "Amount" }, new PageInterpreter.DataModel.TableColumn() { ColumnName = "Total", LabelParameters = new string[] { "Amount" }, TextType = "Amount" } }); Assert.IsNotNull(analysis); }