Пример #1
0
        public void Create_WhenHasSourceAndTarget_ShouldAddSourceSegmentToParagraphUnit()
        {
            // Arrange
            var testee = CreateTestee();

            var sourceSegmentMock = A.Fake <ISegment>();
            var targetSegmentMock = A.Fake <ISegment>();

            A.CallTo(() => _itemFactoryMock.CreateSegment(A <ISegmentPairProperties> .Ignored)).ReturnsNextFromSequence(sourceSegmentMock, targetSegmentMock);

            var textPropertiesMock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties(TheSourceValue)).Returns(textPropertiesMock);

            var textMock = A.Fake <IText>();

            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMock)).Returns(textMock);

            // Act
            testee.Create(TheSourcePath, TheSourceValue, TheTargetPath, TheTargetValue);

            // Assert
            A.CallTo(() => sourceSegmentMock.Add(textMock)).MustHaveHappened();
            A.CallTo(() => _paragraphUnitMock.Source.Add(sourceSegmentMock)).MustHaveHappened();
        }
Пример #2
0
        public void VisitPlaceholderTag(IPlaceholderTag tag)
        {
            if (tag.Properties.MetaDataContainsKey("Anonymizer"))
            {
                var abstractMarkupData = tag.Parent.AllSubItems.FirstOrDefault(i => i.IndexInParent.Equals(tag.IndexInParent));
                if (abstractMarkupData != null)
                {
                    //if we catch an exception that means is only a taged text is not encrypted
                    try
                    {
                        var decryptedText = _factory.CreateText(
                            _propertiesFactory.CreateTextProperties(
                                DecryptText(tag.Properties.TagContent)));

                        if (!_decryptSettings.IgnoreEncrypted)
                        {
                            var elementContainer = abstractMarkupData.Parent;
                            elementContainer.Insert(tag.IndexInParent, decryptedText);
                            elementContainer.RemoveAt(tag.IndexInParent);
                        }
                    }
                    catch (Exception e)
                    {
                        // take the text from tag and insert it back as IText
                        InsertTextBack(abstractMarkupData, tag);
                    }
                }
            }
        }
Пример #3
0
        private static void MergeMarkupData(ISegment segment, IDocumentItemFactory itemFactory, IPropertiesFactory propFactory)
        {
            Location textLocation = new Location(segment, true);

            IText prevText = null;

            do
            {
                if (textLocation.ItemAtLocation != null)
                {
                    IAbstractMarkupData currData = (IAbstractMarkupData)textLocation.ItemAtLocation.Clone();
                    IText currText = currData as IText;
                    if (currText == null)
                    {
                        prevText = null;
                    }
                    else
                    if (prevText == null)
                    {
                        prevText = currText;
                    }
                    else
                    {
                        prevText = itemFactory.CreateText(propFactory.CreateTextProperties(prevText.Properties.Text +
                                                                                           currText.Properties.Text));
                        textLocation.ItemAtLocation.Parent.RemoveAt(textLocation.ItemAtLocation.IndexInParent);

                        textLocation.MovePrevious();
                        textLocation.ItemAtLocation.Parent[textLocation.ItemAtLocation.IndexInParent] = prevText;
                    }
                }
            }while (textLocation.MoveNextSibling());
        }
        public void Create_WhenTextHasSoftLineBreaks_ShouldReplaceSoftLineBreaks()
        {
            // Arrange
            var testee = CreateTestee();

            var entry = new Entry
            {
                MessageId     = "message id\\n",
                MessageString = "message string",
            };

            var textPropertiesMsgidMock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("message id\n")).Returns(textPropertiesMsgidMock);

            var textMsgidMock = A.Fake <IText>();

            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMsgidMock)).Returns(textMsgidMock);

            // Act
            testee.Create(entry, LineType.MessageId, false);

            // Assert
            A.CallTo(() => _sourceSegment0Mock.Add(textMsgidMock)).MustHaveHappened();
        }
        public void VisitText_WhenTextIsTextInlineType_ShouldAddText()
        {
            // Arrange
            var testee = CreateTestee();

            A.CallTo(() => _textProcessorMock.Process(TexBeforeProcessing)).Returns(new List <IFragment>
            {
                new Fragment(InlineType.Text, "text")
            });

            var textPropertiesMock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("text")).Returns(textPropertiesMock);

            var newTextMock = A.Fake <IText>();

            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMock)).Returns(newTextMock);

            // Act
            testee.VisitText(_textMock);

            // Assert
            A.CallTo(() => _sourceParagraphMock.Add(newTextMock)).MustHaveHappened();
        }
Пример #6
0
        public void VisitPlaceholderTag(IPlaceholderTag tag)
        {
            if (tag.Properties.MetaDataContainsKey("Anonymizer"))
            {
                var abstractMarkupData = tag.Parent.AllSubItems.FirstOrDefault(i => i.IndexInParent.Equals(tag.IndexInParent));
                if (abstractMarkupData != null)
                {
                    var decryptedText = _factory.CreateText(
                        _propertiesFactory.CreateTextProperties(AnonymizeData.DecryptData(tag.Properties.TagContent, "Andrea")));
                    var elementContainer = abstractMarkupData.Parent;

                    elementContainer.Insert(tag.IndexInParent, decryptedText);

                    elementContainer.RemoveAt(tag.IndexInParent);
                }
            }
        }
Пример #7
0
            protected override void Execute()
            {
                //get the active segment pair from the current active document in the editor
                var activeSegmentPair = Controller.ActiveDocument.ActiveSegmentPair;

                if (activeSegmentPair == null)
                {
                    return;
                }

                //Create an instance of the document item factory that is needed to create segment elements
                IDocumentItemFactory documentItemFactory = DefaultDocumentItemFactory.CreateInstance();

                ITextProperties firstTextProp = documentItemFactory
                                                .PropertiesFactory
                                                .CreateTextProperties(OpusCatProviderLanguageDirection.CurrentTranslation.ToPlain());
                IText firstText = documentItemFactory.CreateText(firstTextProp);

                activeSegmentPair.Target.Add(firstText);
                Controller.ActiveDocument.UpdateSegmentPair(activeSegmentPair);
            }
Пример #8
0
        public IAbstractMarkupData Text(string text)
        {
            var textProperties = _propertiesFactory.CreateTextProperties(text);

            return(_factory.CreateText(textProperties));
        }
        private IAbstractMarkupData CreateIText(string chunk)
        {
            var textProps = itemFactory.PropertiesFactory.CreateTextProperties(chunk);

            return(itemFactory.CreateText(textProps));
        }
Пример #10
0
        private IText CreateText(string textContent)
        {
            ITextProperties textProps = _itemFactory.PropertiesFactory.CreateTextProperties(textContent);

            return(_itemFactory.CreateText(textProps));
        }
        public void SetUp()
        {
            _itemFactoryMock       = A.Fake <IDocumentItemFactory>();
            _propertiesFactoryMock = A.Fake <IPropertiesFactory>();

            _paragraphUnitMock = A.Fake <IParagraphUnit>();
            A.CallTo(() => _itemFactoryMock.CreateParagraphUnit(A <LockTypeFlags> .Ignored)).Returns(_paragraphUnitMock);

            _paragraphSourceMock = A.Fake <IParagraph>();
            A.CallTo(() => _paragraphUnitMock.Source).Returns(_paragraphSourceMock);

            _paragraphTargetMock = A.Fake <IParagraph>();
            A.CallTo(() => _paragraphUnitMock.Target).Returns(_paragraphTargetMock);

            _segmentPairPropertiesMock = A.Fake <ISegmentPairProperties>();
            A.CallTo(() => _itemFactoryMock.CreateSegmentPairProperties()).Returns(_segmentPairPropertiesMock);

            _translationOriginMmock = A.Fake <ITranslationOrigin>();
            A.CallTo(() => _itemFactoryMock.CreateTranslationOrigin()).Returns(_translationOriginMmock);

            _sourceSegment0Mock = A.Fake <ISegment>();
            _targetSegment0Mock = A.Fake <ISegment>();
            _sourceSegment1Mock = A.Fake <ISegment>();
            _targetSegment1Mock = A.Fake <ISegment>();
            _sourceSegment2Mock = A.Fake <ISegment>();
            _targetSegment2Mock = A.Fake <ISegment>();
            _sourceSegment3Mock = A.Fake <ISegment>();
            _targetSegment3Mock = A.Fake <ISegment>();
            A.CallTo(() => _itemFactoryMock.CreateSegment(A <ISegmentPairProperties> .Ignored))
            .ReturnsNextFromSequence(
                _sourceSegment0Mock, _targetSegment0Mock,
                _sourceSegment1Mock, _targetSegment1Mock,
                _sourceSegment2Mock, _targetSegment2Mock,
                _sourceSegment3Mock, _targetSegment3Mock
                );

            var textPropertiesMsgidMock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("message id")).Returns(textPropertiesMsgidMock);

            var textPropertiesMsgidPluralMock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("message id plural"))
            .Returns(textPropertiesMsgidPluralMock);

            var textPropertiesMsgstrMock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("message string"))
            .Returns(textPropertiesMsgstrMock);

            var textPropertiesMsgstr0Mock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("message string 0"))
            .Returns(textPropertiesMsgstr0Mock);

            var textPropertiesMsgstr1Mock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("message string 1"))
            .Returns(textPropertiesMsgstr1Mock);

            var textPropertiesMsgstr2Mock = A.Fake <ITextProperties>();

            A.CallTo(() => _propertiesFactoryMock.CreateTextProperties("message string 2"))
            .Returns(textPropertiesMsgstr2Mock);

            _textMsgidMock = A.Fake <IText>();
            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMsgidMock)).Returns(_textMsgidMock);

            _textMsgidPluralMock = A.Fake <IText>();
            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMsgidPluralMock)).Returns(_textMsgidPluralMock);

            _textMsgstrMock = A.Fake <IText>();
            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMsgstrMock)).Returns(_textMsgstrMock);

            _textMsgstr0Mock = A.Fake <IText>();
            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMsgstr0Mock)).Returns(_textMsgstr0Mock);

            _textMsgstr1Mock = A.Fake <IText>();
            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMsgstr1Mock)).Returns(_textMsgstr1Mock);

            _textMsgstr2Mock = A.Fake <IText>();
            A.CallTo(() => _itemFactoryMock.CreateText(textPropertiesMsgstr2Mock)).Returns(_textMsgstr2Mock);
        }
        private IText CreateText(string value)
        {
            var textProperties = _propertiesFactory.CreateTextProperties(value);

            return(_itemFactory.CreateText(textProperties));
        }