示例#1
0
        public void VisitSegmentUpdatesMetaDataOfFormattingTag()
        {
            // Arrange
            var settings = utility.CreateSettings();
            var list     = utility.CreateConversionItemLists(searchText: "<cf bold=\"True\">(.+?)</cf>",
                                                             tagPair: true,
                                                             replacementText: "<cf bold=\"False\">$1</cf>",
                                                             toUpper: true);
            var segment = utility.CreateSegment(isLocked: false);
            var text    = utility.CreateText("some text", segment);
            var tagPair = utility.CreateTag("<cf bold=\"True\">", "</cf>", text);

            tagPair.Parent = utility.CreateSegment();
            tagPair.StartTagProperties.TagContent = "<cf bold=\"True\">";
            tagPair.TagProperties.Returns(Substitute.For <IAbstractTagProperties>());
            var pair = new KeyValuePair <string, string>("bold", $@"<w:rPr> { Environment.NewLine }< w:bold w:val = ""True"" /></ w:rPr > ");

            tagPair.TagProperties.MetaData.Returns(new List <KeyValuePair <string, string> >()
            {
                pair
            });

            var itemFactory     = Substitute.For <IDocumentItemFactory>();
            var reporter        = Substitute.For <ICleanUpMessageReporter>();
            var reportGenerator = Substitute.For <IXmlReportGenerator>();
            var sourceHandler   = new ConversionCleanupHandler(settings, list, itemFactory, reporter, reportGenerator, BatchTaskMode.Source);

            // Act
            sourceHandler.VisitTagPair(tagPair);
            sourceHandler.VisitSegment(segment);

            // Assert
            tagPair.StartTagProperties.Formatting.Received().Add(Arg.Any <IFormattingItem>());
            tagPair.TagProperties.Received().SetMetaData(Arg.Any <string>(), Arg.Any <string>());
        }
示例#2
0
        public void VisitSegmentMatchesTagPairAndUpdatesFormatting()
        {
            // Arrange
            var settings = utility.CreateSettings();
            var list     = utility.CreateConversionItemLists(searchText: "<cf bold=\"True\">(.+?)</cf>",
                                                             tagPair: true,
                                                             replacementText: "<cf bold=\"False\">$1</cf>");
            var segment = utility.CreateSegment(isLocked: false);
            var text    = utility.CreateText("some text", segment);
            var tagPair = utility.CreateTag("<cf bold=\"True\">", "</cf>", text);

            tagPair.Parent = utility.CreateSegment();

            var itemFactory     = Substitute.For <IDocumentItemFactory>();
            var reporter        = Substitute.For <ICleanUpMessageReporter>();
            var reportGenerator = Substitute.For <IXmlReportGenerator>();
            var sourceHandler   = new ConversionCleanupHandler(settings, list, itemFactory, reporter, reportGenerator, BatchTaskMode.Source);

            // Act
            sourceHandler.VisitTagPair(tagPair);
            sourceHandler.VisitSegment(segment);

            // Assert
            tagPair.StartTagProperties.Formatting.Received().Add(Arg.Any <IFormattingItem>());
            tagPair.DidNotReceive().RemoveFromParent();
        }
示例#3
0
        public void VisitSegmentUpdatesITextComplexSegmentTagSensitive()
        {
            // Arrange
            var settings = utility.CreateSettings();
            var list     = utility.CreateConversionItemLists(searchText: "Delete me",
                                                             replacementText: "");
            var segment = utility.CreateSegment(isLocked: false);
            var text1   = utility.CreateText("Delete me", segment);
            var text2   = utility.CreateText("I will remain", segment);
            var tag     = utility.CreateTag(new Bold(true));

            var itemFactory     = Substitute.For <IDocumentItemFactory>();
            var reporter        = Substitute.For <ICleanUpMessageReporter>();
            var reportGenerator = Substitute.For <IXmlReportGenerator>();
            var sourceHandler   = new ConversionCleanupHandler(settings, list, itemFactory, reporter, reportGenerator, BatchTaskMode.Source);

            // Act
            sourceHandler.VisitText(text1);
            sourceHandler.VisitTagPair(tag);
            sourceHandler.VisitText(text2);
            sourceHandler.VisitSegment(segment);

            // Assert
            text1.Received().RemoveFromParent();
            Assert.Equal("I will remain", text2.Properties.Text);
        }
示例#4
0
        public void VisitSegmentMatchesTagPairAndCreatesPlaceholder()
        {
            // Arrange
            var settings = utility.CreateSettings();
            var list     = utility.CreateConversionItemLists(searchText: "<tag>(.+?)</tag>",
                                                             tagPair: true,
                                                             replacementText: @"<tag trans=""$1""/>",
                                                             placeHolder: true);
            var segment = utility.CreateSegment(isLocked: false);
            var text    = utility.CreateText("some text", segment);
            var tagPair = utility.CreateTag("<tag>", "</tag>", text);

            tagPair.Parent = utility.CreateSegment();
            var itemFactory     = Substitute.For <IDocumentItemFactory>();
            var reporter        = Substitute.For <ICleanUpMessageReporter>();
            var reportGenerator = Substitute.For <IXmlReportGenerator>();
            var sourceHandler   = new ConversionCleanupHandler(settings, list, itemFactory, reporter, reportGenerator, BatchTaskMode.Source);

            // Act
            sourceHandler.VisitTagPair(tagPair);
            sourceHandler.VisitSegment(segment);

            // Assert
            tagPair.Parent.Received().Insert(Arg.Any <int>(), Arg.Any <IAbstractMarkupData>());
            tagPair.Received().RemoveFromParent();
        }