public void GivenNoRegions_WhenCallingGetAsPlainText_ThenEmptyStringIsReturned()
        {
            //Arrange
            var target = RawAzureOcrResult.CreateFrom(_resultMock.Object);

            //Act
            var result = target.GetAsPlainText();

            //Assert
            result.Should().BeEmpty();
        }
        public void GivenNoRegions_WhenCallingTextFound_ThenFalseIsReturned()
        {
            //Arrange
            var target = RawAzureOcrResult.CreateFrom(_resultMock.Object);

            //Act
            var result = target.TextFound();

            //Assert
            result.Should().BeFalse();
        }
        public void GivenAProjectOxfordOcrResult_WhenInvokingCreateFrom_ThenPropertiesAreSetCorrectly()
        {
            //Arrange / Act
            var result = RawAzureOcrResult.CreateFrom(_resultMock.Object);

            //Assert
            Assert.AreEqual(_language, result.Language);
            Assert.AreEqual(_orientation, result.Orientation);
            Assert.AreEqual(_regions, result.Regions);
            Assert.AreEqual(_textAngle, result.TextAngle);
        }
        public void GivenRegions_WhenCallingTextFound_ThenTrueIsReturned()
        {
            //Arrange
            _resultMock.Object.Regions = new [] { new Region() };
            var target = RawAzureOcrResult.CreateFrom(_resultMock.Object);

            //Act
            var result = target.TextFound();

            //Assert
            result.Should().BeTrue();
        }
        public void GivenRegions_WhenCallingGetAsPlainText_ThenTextOfAllWordsAreReturned()
        {
            //Arrange
            _resultMock.Object.Regions = new[]
            {
                new Region
                {
                    Lines = new[]
                    {
                        new Line {
                            Words = new[] { new Word {
                                                Text = "Test A"
                                            }, new Word {
                                                Text = "Test B"
                                            } }
                        },
                        new Line {
                            Words = new[] { new Word {
                                                Text = "Test C"
                                            } }
                        }
                    }
                },
                new Region
                {
                    Lines = new[]
                    {
                        new Line {
                            Words = new[] { new Word {
                                                Text = "Test D"
                                            }, new Word {
                                                Text = "Test E"
                                            } }
                        },
                    }
                }
            };
            var target = RawAzureOcrResult.CreateFrom(_resultMock.Object);

            //Act
            var result = target.GetAsPlainText();

            //Assert
            result.Should().Be("Test A Test B Test C Test D Test E");
        }
예제 #6
0
        private async Task <AzureOcrResult> DoOcr(Stream imageAsStream, FileFormatEnum fileFormatEnum, DateTime start)
        {
            try
            {
                var preprocessedResult = _ocrPreProcessing.AjustOrientationAndSize(imageAsStream, fileFormatEnum);
                using (var stream = preprocessedResult.ImageFileStream)
                {
                    ValidateImageProportions(preprocessedResult.NewImageHeight, preprocessedResult.NewImageWidth);
                    var entries = await _azureVisionApi.Execute(stream);

                    var rawAzureOcrResult = RawAzureOcrResult.CreateFrom(entries);
                    var content           = _azureOcrParser.Execute(rawAzureOcrResult, preprocessedResult.NewImageHeight,
                                                                    preprocessedResult.NewImageWidth);
                    return(AzureOcrResult.CreateSuccesResult(DateTime.Now.Subtract(start), content, rawAzureOcrResult));
                }
            }
            catch (Exception e)
            {
                return(AzureOcrResult.CreateErrorResult(DateTime.Now.Subtract(start), e));
            }
        }