public void SimpleUpgradeWhenExistingListHasNoRenderings() { ICmPossibilityList oldKeyTermsList = Cache.LangProject.KeyTermsList; IChkTerm term = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); oldKeyTermsList.PossibilitiesOS.Add(term); term.Name.set_String(m_wsEn, "Abba"); term.Description.set_String(m_wsEn, "Daddy"); AddOccurrenceToOldStyleSense(term, 41014036, null, "abba"); term = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); oldKeyTermsList.PossibilitiesOS.Add(term); term.Name.set_String(m_wsEn, "Angel"); IChkTerm subsense = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); term.SubPossibilitiesOS.Add(subsense); subsense.Name.set_String(m_wsEn, "Heavenly being"); subsense.Description.set_String(m_wsEn, "Supernatural being sent as a messenger from God"); AddOccurrenceToOldStyleSense(subsense, 040001020, null, "aggelos"); subsense = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); term.SubPossibilitiesOS.Add(subsense); subsense.Name.set_String(m_wsEn, "Demon"); subsense.Description.set_String(m_wsEn, "A fallen angel"); AddOccurrenceToOldStyleSense(subsense, 040007022, null, "daimonion"); Assert.AreEqual(2, Cache.LangProject.KeyTermsList.PossibilitiesOS.Count); BiblicalTermsList terms = new BiblicalTermsList(); terms.Version = new Guid("00FEA689-3B63-4bd4-B640-7262A274D1A8"); terms.KeyTerms = new List<Term>(); terms.KeyTerms.Add(new Term(3, "KT", "\u03b1\u03b2\u03b2\u03b1", "Greek", "abba; father", null, null, 4101403603, 4500801516, 4800400618)); terms.KeyTerms.Add(new Term(21, "KT", "\u1F04\u03B3\u03B3\u03B5\u03BB\u03BF\u03C2-1", "Greek", "angel", null, null, 040001020)); terms.KeyTerms.Add(new Term(363, "KT", "\u03B4\u03B1\u03B9\u03BC\u1F79\u03BD\u03B9\u03BF\u03BD", "Greek", "demon", "\u1F04\u03B3\u03B3\u03B5\u03BB\u03BF\u03C2", "\u03B4\u03B1\u03B9\u03BC\u03BF\u03BD\u1F77\u03B6\u03BF\u03BC\u03B1\u03B9, \u03B4\u03B1\u03B9\u03BC\u03BF\u03BD\u03B9\u1F7D\u03B4\u03B7\u03C2, \u03B4\u03B1\u1F77\u03BC\u03C9\u03BD", 040007022)); List<BiblicalTermsLocalization> localizations = new List<BiblicalTermsLocalization>(1); BiblicalTermsLocalization loc = new BiblicalTermsLocalization(1); loc.WritingSystemHvo = m_wsEn; loc.Categories.Add(new CategoryLocalization("KT", "Key terms")); loc.Terms.Add(new TermLocalization(3, "abba; father", "title for God, literally dad")); localizations.Add(loc); // Load the terms var ktInitializer = new DummyTeKeyTermsInit(m_scr); ktInitializer.m_localizations = localizations; var mockProgressDlg = MockRepository.GenerateMock<IProgress>(); ktInitializer.CallCreateKeyTerms(mockProgressDlg, terms); ICmPossibilityList newChkTermsList = Cache.LangProject.KeyTermsList; int wsGreek = m_wsf.GetWsFromStr("grc"); // Make sure there is one category (possibility) in the new list Assert.AreEqual(1, newChkTermsList.PossibilitiesOS.Count); ICmPossibility ktCategory = newChkTermsList.PossibilitiesOS[0]; Assert.AreEqual("KT", ktCategory.Abbreviation.get_String(m_wsEn).Text); // Make sure there are three keyterms in that category Assert.AreEqual(3, ktCategory.SubPossibilitiesOS.Count); // Look at the contents of the first ChkTerm ("abba") IChkTerm keyterm = (IChkTerm)ktCategory.SubPossibilitiesOS[0]; Assert.AreEqual(3, keyterm.TermId); Assert.AreEqual("\u03b1\u03b2\u03b2\u03b1", keyterm.Name.get_String(wsGreek).Text); Assert.AreEqual("abba", keyterm.Name.get_String(m_wsEn).Text); Assert.AreEqual("title for God, literally dad", keyterm.Description.get_String(m_wsEn).Text); Assert.AreEqual("father", keyterm.SeeAlso.get_String(m_wsEn).Text); Assert.AreEqual(0, keyterm.RenderingsOC.Count); Assert.AreEqual(3, keyterm.OccurrencesOS.Count, "There should be 3 references for abba"); Assert.IsNull(keyterm.OccurrencesOS[0].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Unassigned, keyterm.OccurrencesOS[0].Status); Assert.IsNull(keyterm.OccurrencesOS[1].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Unassigned, keyterm.OccurrencesOS[1].Status); Assert.IsNull(keyterm.OccurrencesOS[2].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Unassigned, keyterm.OccurrencesOS[2].Status); // Briefly check the other two ChkTerms keyterm = (IChkTerm)ktCategory.SubPossibilitiesOS[1]; Assert.AreEqual(21, keyterm.TermId); Assert.AreEqual(0, keyterm.RenderingsOC.Count); Assert.AreEqual(1, keyterm.OccurrencesOS.Count); Assert.IsNull(keyterm.OccurrencesOS[0].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Unassigned, keyterm.OccurrencesOS[0].Status); keyterm = (IChkTerm)ktCategory.SubPossibilitiesOS[2]; Assert.AreEqual(363, keyterm.TermId); Assert.AreEqual(0, keyterm.RenderingsOC.Count); Assert.AreEqual(1, keyterm.OccurrencesOS.Count); Assert.IsNull(keyterm.OccurrencesOS[0].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Unassigned, keyterm.OccurrencesOS[0].Status); bool fFoundResource = false; foreach (ICmResource resource in m_lp.TranslatedScriptureOA.ResourcesOC) { if (resource.Name == "BiblicalTerms") { Assert.AreEqual(terms.Version, resource.Version); fFoundResource = true; } } Assert.IsTrue(fFoundResource); }
public void UpgradeWhenExistingListHasRenderings_NewStyleList() { IWfiWordform abc = Cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create(); abc.Form.SetVernacularDefaultWritingSystem("abc"); IWfiWordform def = Cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create(); def.Form.SetVernacularDefaultWritingSystem("def"); IWfiWordform ghi = Cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create(); ghi.Form.SetVernacularDefaultWritingSystem("ghi"); // Create key terms under a key term possibility list (the new style of list). ICmPossibilityList oldKeyTermsList = Cache.LangProject.KeyTermsList; ICmPossibility keyTermPoss = Cache.ServiceLocator.GetInstance<ICmPossibilityFactory>().Create(); oldKeyTermsList.PossibilitiesOS.Add(keyTermPoss); IChkTerm term = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); keyTermPoss.SubPossibilitiesOS.Add(term); term.Name.set_String(m_wsEn, "Abba"); term.Description.set_String(m_wsEn, "Daddy"); AddOccurrenceToOldStyleSense(term, 41014036, abc, "abba", KeyTermRenderingStatus.Assigned); AddOccurrenceToOldStyleSense(term, 45008015, abc, "abba", KeyTermRenderingStatus.AutoAssigned); AddOccurrenceToOldStyleSense(term, 48004006, null, "abba"); // Not rendered AddOccurrenceToOldStyleSense(term, 48004007, abc, "abba"); // This one is not in new list term = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); keyTermPoss.SubPossibilitiesOS.Add(term); term.Name.set_String(m_wsEn, "Angel"); IChkTerm subsense = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); term.SubPossibilitiesOS.Add(subsense); subsense.Name.set_String(m_wsEn, "Heavenly being"); subsense.Description.set_String(m_wsEn, "Supernatural being sent as a messenger from God"); AddOccurrenceToOldStyleSense(subsense, 040001020, def, "aggelos"); AddOccurrenceToOldStyleSense(subsense, 040001024, ghi, "aggelos"); AddOccurrenceToOldStyleSense(subsense, 040002013, null, "aggelos", KeyTermRenderingStatus.Ignored); subsense = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); term.SubPossibilitiesOS.Add(subsense); subsense.Name.set_String(m_wsEn, "Demon"); subsense.Description.set_String(m_wsEn, "A fallen angel"); AddOccurrenceToOldStyleSense(subsense, 040007022, null, "daimonion"); int iKeyTermPoss = Cache.LangProject.KeyTermsList.PossibilitiesOS.IndexOf(keyTermPoss); Assert.GreaterOrEqual(0, iKeyTermPoss, "We expect the key term list to be added as a node under the Biblical Terms list"); Assert.AreEqual(2, Cache.LangProject.KeyTermsList.PossibilitiesOS[iKeyTermPoss].SubPossibilitiesOS.Count); BiblicalTermsList terms = new BiblicalTermsList(); terms.Version = new Guid("00FEA689-3B63-4bd4-B640-7262A274D1A8"); terms.KeyTerms = new List<Term>(); terms.KeyTerms.Add(new Term(3, "KT", "\u03b1\u03b2\u03b2\u03b1", "Greek", "abba; father", null, null, 4101403603, 4500801516, 4800400618)); terms.KeyTerms.Add(new Term(21, "KT", "\u1F04\u03B3\u03B3\u03B5\u03BB\u03BF\u03C2", "Greek", "angel", null, null, 04000102006, 04000102413, 04000201305)); terms.KeyTerms.Add(new Term(363, "KT", "\u03B4\u03B1\u03B9\u03BC\u1F79\u03BD\u03B9\u03BF\u03BD-1", "Greek", "demon", "\u03B4\u03B1\u03B9\u03BC\u1F79\u03BD\u03B9\u03BF\u03BD", "\u03B4\u03B1\u03B9\u03BC\u03BF\u03BD\u1F77\u03B6\u03BF\u03BC\u03B1\u03B9, \u03B4\u03B1\u03B9\u03BC\u03BF\u03BD\u03B9\u1F7D\u03B4\u03B7\u03C2, \u03B4\u03B1\u1F77\u03BC\u03C9\u03BD", 04000702219)); List<BiblicalTermsLocalization> localizations = new List<BiblicalTermsLocalization>(1); BiblicalTermsLocalization loc = new BiblicalTermsLocalization(1); loc.WritingSystemHvo = m_wsEn; loc.Categories.Add(new CategoryLocalization("KT", "Key terms")); loc.Terms.Add(new TermLocalization(3, "abba; father", "title for God, literally dad")); localizations.Add(loc); // Load the terms var ktInitializer = new DummyTeKeyTermsInit(m_scr); ktInitializer.m_localizations = localizations; var mockProgressDlg = MockRepository.GenerateMock<IProgress>(); ktInitializer.CallCreateKeyTerms(mockProgressDlg, terms); ICmPossibilityList newChkTermsList = Cache.LangProject.KeyTermsList; int wsGreek = m_wsf.GetWsFromStr("grc"); // Make sure there is one category (possibility) in the new list ICmPossibility ktCategory = newChkTermsList.PossibilitiesOS[iKeyTermPoss]; Assert.AreEqual("KT", ktCategory.Abbreviation.get_String(m_wsEn).Text); // Make sure there are three keyterms in that category Assert.AreEqual(3, ktCategory.SubPossibilitiesOS.Count); // Check the ChkTerm and ChkRefs for "abba" IChkTerm keyterm = (IChkTerm)ktCategory.SubPossibilitiesOS[0]; Assert.AreEqual(3, keyterm.TermId); Assert.AreEqual("\u03b1\u03b2\u03b2\u03b1", keyterm.Name.get_String(wsGreek).Text); Assert.AreEqual("abba", keyterm.Name.get_String(m_wsEn).Text); Assert.AreEqual("title for God, literally dad", keyterm.Description.get_String(m_wsEn).Text); Assert.AreEqual("father", keyterm.SeeAlso.get_String(m_wsEn).Text); Assert.AreEqual(1, keyterm.RenderingsOC.Count); IChkRendering abbaRendering = keyterm.RenderingsOC.ToArray()[0]; Assert.AreEqual(abc, abbaRendering.SurfaceFormRA); Assert.AreEqual(3, keyterm.OccurrencesOS.Count, "There should be 3 references for abba"); Assert.AreEqual(KeyTermRenderingStatus.Assigned, keyterm.OccurrencesOS[0].Status); Assert.AreEqual(abc, keyterm.OccurrencesOS[0].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.AutoAssigned, keyterm.OccurrencesOS[1].Status); Assert.AreEqual(abc, keyterm.OccurrencesOS[1].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Unassigned, keyterm.OccurrencesOS[2].Status); Assert.IsNull(keyterm.OccurrencesOS[2].RenderingRA); // Check the ChkRefs for "angel" keyterm = (IChkTerm)ktCategory.SubPossibilitiesOS[1]; Assert.AreEqual(21, keyterm.TermId); Assert.AreEqual(2, keyterm.RenderingsOC.Count); bool fFoundDEF = false; bool fFoundGHI = false; foreach (IChkRendering rendering in keyterm.RenderingsOC) { fFoundDEF |= (rendering.SurfaceFormRA == def); fFoundGHI |= (rendering.SurfaceFormRA == ghi); } Assert.IsTrue(fFoundDEF); Assert.IsTrue(fFoundGHI); Assert.AreEqual(3, keyterm.OccurrencesOS.Count); Assert.AreEqual(KeyTermRenderingStatus.Assigned, keyterm.OccurrencesOS[0].Status); Assert.AreEqual(def, keyterm.OccurrencesOS[0].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Assigned, keyterm.OccurrencesOS[1].Status); Assert.AreEqual(ghi, keyterm.OccurrencesOS[1].RenderingRA); Assert.AreEqual(KeyTermRenderingStatus.Ignored, keyterm.OccurrencesOS[2].Status); Assert.IsNull(keyterm.OccurrencesOS[2].RenderingRA); // Check the ChkRefs for "demon" keyterm = (IChkTerm)ktCategory.SubPossibilitiesOS[2]; Assert.AreEqual(363, keyterm.TermId); Assert.AreEqual(0, keyterm.RenderingsOC.Count); Assert.AreEqual(1, keyterm.OccurrencesOS.Count); Assert.AreEqual(KeyTermRenderingStatus.Unassigned, keyterm.OccurrencesOS[0].Status); Assert.IsNull(keyterm.OccurrencesOS[0].RenderingRA); }