Exemplo n.º 1
0
        // Test Parser Mapping
        // ######################################################################
        public static TheoryData TestParsingData()
        {
            // test 1 data
            var inputDocument = File.OpenRead(@"TestData\Parser\MSRead\test1 - inputDocument.pdf");  // read input document
            var parser        = new MSReadParserService(Secrets.MSReadCognitiveServicesEndPoint, Secrets.MSReadCongnitiveServicesKey);

            return(new TheoryData <Stream, MSReadParserService, CliException>
            {
                {
                    inputDocument,
                    parser,
                    null
                }
            });
        }
Exemplo n.º 2
0
 public IParserService GetParser(string fileType, string fileName = "")
 {
     if (Constants.MsReadValidFileTypes.Contains(fileType))
     {
         if (_msreadParser == null)
         {
             _msreadParser = new MSReadParserService(_allParsersConfigs.MsRead.CognitiveServiceEndPoint, _allParsersConfigs.MsRead.CongnitiveServiceKey);
         }
         return(_msreadParser);
     }
     else if (Constants.DocxValidFileTypes.Contains(fileType))
     {
         if (_docxParser == null)
         {
             _docxParser = new DocxParserService();
         }
         return(_docxParser);
     }
     throw new UnsupportedFileTypeException(fileName, fileType, _validDocTypes);
 }
Exemplo n.º 3
0
 public void TestParsing(Stream inputDocument, MSReadParserService parser, CliException expectedException)
 {
     /* TEST NOTES
      * *************
      * we only care about parsing result
      * i.e. parser results maps to our object correctly
      *
      * we don't care about the actual values in the object
      * because the service provider (in this case msread team)
      * may optimize their engine
      * rendering the values in our "ExpectedResult" object in correct
      * */
     if (expectedException == null)
     {
         var actualResult = parser.ParseFileInternal(inputDocument).ConfigureAwait(false).GetAwaiter().GetResult();
         // validate object values aren't null
         actualResult.AnalyzeResult.ReadResults.ToList().ForEach(page =>
         {
             // check all properties
             Assert.NotNull(page.Lines);
             // check line objects
             page.Lines.ToList().ForEach(line =>
             {
                 Assert.NotNull(line.BoundingBox);
                 Assert.NotNull(line.Text);
                 Assert.NotNull(line.Words);
             });
         });
     }
     else
     {
         Assert.Throws(expectedException.GetType(), () =>
         {
             parser.ParseFile(inputDocument).ConfigureAwait(false).GetAwaiter().GetResult();
         });
     }
 }
 public MsReadParserServiceUnitTest()
 {
     _parser = new MSReadParserService(Secrets.MSReadCognitiveServicesEndPoint, Secrets.MSReadCongnitiveServicesKey);
 }