IsInterestingText() public method

public IsInterestingText ( IStText text ) : bool
text IStText
return bool
示例#1
0
        private bool BelongsToInterestingText(ISegment seg)
        {
            if (m_interestingTexts == null)
            {
                return(true);                // no filtering
            }
            IStText text = seg.Paragraph != null ? seg.Paragraph.Owner as IStText : null;

            return(text != null && m_interestingTexts.IsInterestingText(text));
        }
        public void GetCoreTexts()
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo);

            VerifyList(CurrentTexts(mockTextRep),
                       testObj.InterestingTexts, "texts from initial list of two");
            // Make sure it works if there are none.
            Assert.AreEqual(0, new InterestingTextList(m_propertyTable, new MockTextRepository(), m_mockStTextRepo).InterestingTexts.Count());
            Assert.IsTrue(testObj.IsInterestingText(mockTextRep.m_texts[0].ContentsOA));
            Assert.IsFalse(testObj.IsInterestingText(new MockStText()));
        }
        public void AddAndRemoveCoreTexts()
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo);

            Assert.AreEqual(0, testObj.ScriptureTexts.Count());
            testObj.InterestingTextsChanged += TextsChangedHandler;
            MockText newText = AddMockText(mockTextRep, testObj);

            VerifyList(CurrentTexts(mockTextRep),
                       testObj.InterestingTexts, "texts from initial list of two");
            VerifyTextsChangedArgs(2, 1, 0);
            var removed = mockTextRep.m_texts[1].ContentsOA;

            RemoveText(mockTextRep, testObj, 1);
            VerifyList(CurrentTexts(mockTextRep),
                       testObj.InterestingTexts, "texts from initial list of two");
            VerifyTextsChangedArgs(1, 0, 1);
            Assert.IsTrue(testObj.IsInterestingText(mockTextRep.m_texts[1].ContentsOA), "text not removed still interesting");
            Assert.IsFalse(testObj.IsInterestingText(removed), "removed text no longer interesting");
        }
        public void AddAndRemoveScripture()
        {
            List <IStText>      expectedScripture;
            List <IStText>      expected;
            InterestingTextList testObj = SetupTwoMockTextsAndOneScriptureSection(true, out expectedScripture, out expected);

            MakeMockScriptureSection();
            testObj.PropChanged(m_sections[1].Hvo, ScrSectionTags.kflidContent, 0, 1, 0);
            testObj.PropChanged(m_sections[1].Hvo, ScrSectionTags.kflidHeading, 0, 1, 0);
            VerifyList(expected, testObj.InterestingTexts, "new Scripture objects are not added automatically");
            VerifyScriptureList(testObj, expectedScripture, "new Scripture objects are not added automatically to ScriptureTexts");
            Assert.IsTrue(testObj.IsInterestingText(expectedScripture[0]));
            Assert.IsTrue(testObj.IsInterestingText(expectedScripture[1]));

            var remove = ((MockStText)m_sections[0].ContentOA);

            remove.IsValidObject = false;
            expected.Remove(m_sections[0].ContentOA);   // before we clear ContentsOA!
            expectedScripture.Remove(m_sections[0].ContentOA);
            m_sections[0].ContentOA = null;             // not normally valid, but makes things somewhat more consistent for test.
            testObj.PropChanged(m_sections[0].Hvo, ScrSectionTags.kflidContent, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (ContentsOA)");
            VerifyScriptureList(testObj, expectedScripture, "deleted Scripture texts are removed from ScriptureTexts (ContentsOA");
            VerifyTextsChangedArgs(2, 0, 1);
            Assert.IsFalse(testObj.IsInterestingText(remove));
            Assert.IsTrue(testObj.IsInterestingText(expectedScripture[0]));

            ((MockStText)m_sections[0].HeadingOA).IsValidObject = false;
            expected.Remove(m_sections[0].HeadingOA);   // before we clear ContentsOA!
            m_sections[0].HeadingOA = null;             // not normally valid, but makes things somewhat more consistent for test.
            testObj.PropChanged(m_sections[0].Hvo, ScrSectionTags.kflidHeading, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (HeadingOA)");

            m_sections[0].ContentOA = new MockStText();
            var newTexts = new IStText[] { expected[0], expected[1], m_sections[0].ContentOA, m_sections[1].ContentOA, m_sections[1].HeadingOA };

            testObj.SetInterestingTexts(newTexts);
            VerifyTextsChangedArgs(2, 3, 0);
            expected.AddRange(new[] { m_sections[0].ContentOA, m_sections[1].ContentOA, m_sections[1].HeadingOA });
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (HeadingOA)");
            // Unfortunately, I don't think we actually get PropChanged on the direct owning property,
            // if the owning object (Text or ScrSection) gets deleted. We need to detect deleted objects
            // if things are deleted from any of the possible owning properties.
            // This is also a chance to verify that being owned by an ScrDraft does not count as valid.
            // It's not a very realistic test, as we aren't trying to make everything about the test data consistent.
            ((MockStText)m_sections[0].ContentOA).m_mockOwnerOfClass = new MockScrDraft();              // not allowed in list.
            testObj.PropChanged(m_sections[0].Hvo, ScrBookTags.kflidSections, 0, 0, 1);
            expected.RemoveAt(2);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (ScrBook.SectionsOS)");
            VerifyTextsChangedArgs(2, 0, 1);

            ((MockStText)expected[3]).IsValidObject = false;
            expected.RemoveAt(3);
            testObj.PropChanged(m_sections[0].Hvo, ScriptureTags.kflidScriptureBooks, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (Scripture.ScriptureBooks)");
            VerifyTextsChangedArgs(3, 0, 1);

            ((MockStText)expected[2]).IsValidObject = false;
            expected.RemoveAt(2);
            testObj.PropChanged(m_sections[0].Hvo, ScrBookTags.kflidTitle, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (ScrBookTags.Title)");
            VerifyTextsChangedArgs(2, 0, 1);
            Assert.AreEqual(0, testObj.ScriptureTexts.Count(), "by now we've removed all ScriptureTexts");

            ((MockStText)expected[1]).IsValidObject = false;
            expected.RemoveAt(1);
            //testObj.PropChanged(1, LangProjectTags.kflidTexts, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted texts are removed (LangProject.Texts)");
            VerifyTextsChangedArgs(1, 0, 1);
        }