The class for OCR word.
Example #1
0
        public void Setup()
        {
            _relativeCoords = new Mock <IAzureCreateRelativeCoordinate>();
            _createWord     = new Mock <ICreateWordFromAzureWord>();

            _imgWidth  = 100;
            _imgHeight = 200;
            _word1     = new Word();
            _word2     = new Word();
            _word3     = new Word();
            _line      = new Line {
                Words = new[] { _word1, _word2, _word3 }
            };

            var metaWord1Mock = new Mock <IWord>();
            var metaWord2Mock = new Mock <IWord>();
            var metaWord3Mock = new Mock <IWord>();

            _metaWord1 = metaWord1Mock.Object;
            _metaWord2 = metaWord2Mock.Object;
            _metaWord3 = metaWord3Mock.Object;

            metaWord1Mock.Setup(x => x.Value).Returns("This is");
            metaWord2Mock.Setup(x => x.Value).Returns("a");
            metaWord3Mock.Setup(x => x.Value).Returns("very important test");

            _createWord.Setup(x => x.Execute(_word1, _imgWidth, _imgHeight)).Returns(metaWord1Mock.Object);
            _createWord.Setup(x => x.Execute(_word2, _imgWidth, _imgHeight)).Returns(metaWord2Mock.Object);
            _createWord.Setup(x => x.Execute(_word3, _imgWidth, _imgHeight)).Returns(metaWord3Mock.Object);

            _target = new TransformAzureLineIntoSentence(_relativeCoords.Object, _createWord.Object);
        }
        public void GivenWord_WhenInvokingExecute_ThenWordIsReturned()
        {
            //Arrange
            var left        = 10;
            var top         = 20;
            var width       = 40;
            var height      = 15;
            var returnCoord = new Coordinate(0, 0, 0, 0);

            _relativeCoords.Setup(z => z.Execute(
                                      It.Is <Rectangle>(x => x.Height == height && x.Width == width && x.Top == top && x.Left == left),
                                      100, 200)).Returns(returnCoord);

            var wordValue = "MyTestWord";

            var word = new Word
            {
                BoundingBox = $"{left},{top},{width},{height}",
                Text        = wordValue
            };

            //Act
            var result = _target.Execute(word, _imgWidth, _imgHeight);

            //Assert
            result.Value.Should().Be(wordValue);
            result.Coordinate.Should().Be(returnCoord);
        }
Example #3
0
        public void GivenLineWithWords_WhenInvokingExecute_ThenSentenceValueIsConcatOfWordValues()
        {
            //Arrange
            var imgWidth  = 100;
            var imgHeight = 200;
            var word1     = new Word();
            var word2     = new Word();
            var word3     = new Word();
            var line      = new Line {
                Words = new[] { word1, word2, word3 }
            };

            var metaWord1 = new Mock <IWord>();
            var metaWord2 = new Mock <IWord>();
            var metaWord3 = new Mock <IWord>();

            metaWord1.Setup(x => x.Value).Returns("This is");
            metaWord2.Setup(x => x.Value).Returns("a");
            metaWord3.Setup(x => x.Value).Returns("very important test");

            _createWord.Setup(x => x.Execute(word1, imgWidth, imgHeight)).Returns(metaWord1.Object);
            _createWord.Setup(x => x.Execute(word2, imgWidth, imgHeight)).Returns(metaWord2.Object);
            _createWord.Setup(x => x.Execute(word3, imgWidth, imgHeight)).Returns(metaWord3.Object);

            //Act
            var result = _target.Execute(line, 0, imgWidth, imgHeight, 0);

            //Assert
            result.Value = "This is a very important test";
        }