private MockText AddMockText(MockTextRepository mockTextRep, InterestingTextList testObj)
        {
            var newText = new MockText();

            mockTextRep.m_texts.Add(newText);
            testObj.PropChanged(newText.Hvo, TextTags.kflidContents, 0, 1, 0);
            return(newText);
        }
        private void RemoveText(MockTextRepository mockTextRep, InterestingTextList testObj, int index)
        {
            var oldTextHvo = mockTextRep.m_texts[index].Hvo;

            ((MockText)mockTextRep.m_texts[index]).IsValidObject = false;
            ((MockStText)mockTextRep.m_texts[index].ContentsOA).IsValidObject = false;
            mockTextRep.m_texts.RemoveAt(index);
            testObj.PropChanged(oldTextHvo, TextTags.kflidContents, 0, 0, 1);
        }
        private MockTextRepository MakeMockTextRepoWithTwoMockTexts()
        {
            var mockTextRep = new MockTextRepository();
            var mockText1   = new MockText();
            var mockText2   = new MockText();

            mockTextRep.m_texts.Add(mockText1);
            mockTextRep.m_texts.Add(mockText2);
            return(mockTextRep);
        }
        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 PropertyTableHasInvalidObjects()
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();

            MakeMockScriptureSection();
            m_propertyTable.SetProperty(InterestingTextList.PersistPropertyName, InterestingTextList.MakeIdList(
                                            new ICmObject[] { m_sections[0].ContentOA, m_sections[0].HeadingOA }) + "," + Convert.ToBase64String(Guid.NewGuid().ToByteArray()) + ",$%^#@+");
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo, true);

            testObj.InterestingTextsChanged += TextsChangedHandler;
            var expectedScripture = new List <IStText>();

            expectedScripture.Add(m_sections[0].ContentOA);
            expectedScripture.Add(m_sections[0].HeadingOA);
            VerifyList(expectedScripture, testObj.ScriptureTexts, "Just two valid Guids");
        }
        public void ReplaceCoreText()
        {
            MockTextRepository mockTextRepo = MakeMockTextRepoWithTwoMockTexts();
            var      testObj     = new InterestingTextList(m_propertyTable, mockTextRepo, m_mockStTextRepo);
            var      firstStText = testObj.InterestingTexts.First();
            MockText firstText   = firstStText.Owner as MockText;
            var      replacement = new MockStText();

            testObj.InterestingTextsChanged += TextsChangedHandler;
            firstText.ContentsOA             = replacement;
            testObj.PropChanged(firstText.Hvo, TextTags.kflidContents, 0, 1, 1);

            VerifyList(CurrentTexts(mockTextRepo),
                       testObj.InterestingTexts, "texts after replace");
            // Various possibilities could be valid for the arguments...for now just verify we got something.
            Assert.That(m_lastTextsChangedArgs, Is.Not.Null);
        }
        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");
        }
        private InterestingTextList SetupTwoMockTextsAndOneScriptureSection(bool fIncludeScripture, out List <IStText> expectedScripture,
                                                                            out List <IStText> expected)
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();

            MakeMockScriptureSection();
            m_propertyTable.SetProperty(InterestingTextList.PersistPropertyName, InterestingTextList.MakeIdList(
                                            new ICmObject[] { m_sections[0].ContentOA, m_sections[0].HeadingOA }));
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo, fIncludeScripture);

            testObj.InterestingTextsChanged += TextsChangedHandler;
            expectedScripture = new List <IStText>();
            expectedScripture.Add(m_sections[0].ContentOA);
            expectedScripture.Add(m_sections[0].HeadingOA);
            VerifyScriptureList(testObj, expectedScripture, "Initially two Scripture texts");

            expected = new List <IStText>(CurrentTexts(mockTextRep));
            if (fIncludeScripture)
            {
                expected.AddRange(expectedScripture);
            }
            VerifyList(expected, testObj.InterestingTexts, "two ordinary and two Scripture texts");
            return(testObj);
        }
 private List <IStText> CurrentTexts(MockTextRepository mockTextRep)
 {
     return((from text in mockTextRep.m_texts select text.ContentsOA).ToList());
 }