public override bool ParseNext() { while (_reader.Read()) { OnProgress((byte)(_reader.LineNumber * 100 / _totalNumberOfLines)); var path = _reader.Path; var value = _reader.Value?.ToString() ?? string.Empty; if (_reader.TokenType != JsonToken.String) { continue; } _segmentDataCollector.Add(path, value); var completeSegmentData = _segmentDataCollector.CompleteSegmentData; if (completeSegmentData == null) { continue; } var paragraphUnit = _paragraphUnitFactory.Create( completeSegmentData.SourcePath, completeSegmentData.SourceValue, completeSegmentData.TargetPath, completeSegmentData.TargetValue); Output.ProcessParagraphUnit(paragraphUnit); return(true); } return(false); }
private JsonFileParser CreateTestee() { var jsonFactoryMock = A.Fake <IJsonFactory>(); A.CallTo(() => jsonFactoryMock.CreateJsonTextReader(A <string> .Ignored)).Returns(_jsonTextReaderMock); A.CallTo(() => _jsonTextReaderMock.TokenType).Returns(JsonToken.String); A.CallTo(() => _jsonTextReaderMock.Read()).ReturnsNextFromSequence(true, true, true, true, false); var lineCounter = 0; var texts = new[] { "A", "B", "C", "D" }; A.CallTo(() => _jsonTextReaderMock.LineNumber).ReturnsLazily(() => ++ lineCounter); A.CallTo(() => _jsonTextReaderMock.Value).ReturnsLazily(() => texts[lineCounter - 1 % 4]); A.CallTo(() => _jsonTextReaderMock.Path).Returns(SourcePath); var fileHelperMock = A.Fake <IFileHelper>(); A.CallTo(() => fileHelperMock.GetNumberOfLines(A <string> .Ignored)).Returns(4); var filePropertiesMock = A.Fake <IFileProperties>(); var testee = new JsonFileParser( jsonFactoryMock, fileHelperMock, _embeddedContentRegexSettingsMock, _parsingSettingsMock, _paragraphUnitFactoryMock, _segmendDataCollectorMock) { ItemFactory = _itemFactoryMock, Output = _bilingualContentHandlerMock }; testee.SetFileProperties(filePropertiesMock); return(testee); }