public override void TestTearDown() { base.TestTearDown(); m_reversalSlice.DummyControl.Dispose(); m_reversalSlice.Dispose(); m_reversalSlice = null; NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => m_lexEntry?.Delete()); m_lexEntry = null; }
public void VectorCount() { ILexEntryFactory factory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>(); factory.Create(); ILexEntry entry = factory.Create(); Assert.AreEqual(0, entry.AlternateFormsOS.Count); entry.Delete(); Assert.IsTrue(0 < Cache.LanguageProject.LexDbOA.Entries.Count()); }
public void ResetIndex() { using (var searchEngine = new LexEntrySearchEngine(Cache)) { var entryFactory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>(); IMoMorphType stem = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphStem); ILexEntry form1 = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form1", Cache.DefaultVernWs), "gloss1", new SandboxGenericMSA()); ILexEntry form2 = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form2", Cache.DefaultVernWs), "gloss2", new SandboxGenericMSA()); ILexEntry form3 = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form3", Cache.DefaultVernWs), "gloss3", new SandboxGenericMSA()); m_actionHandler.EndUndoTask(); Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }), Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo })); Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }), Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo })); m_actionHandler.BeginUndoTask("Undo doing stuff", "Redo doing stuff"); ILexEntry form4 = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form4", Cache.DefaultVernWs), "gloss4", new SandboxGenericMSA()); m_actionHandler.EndUndoTask(); Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }), Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo, form4.Hvo })); Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }), Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo, form4.Hvo })); m_actionHandler.BeginUndoTask("Undo doing stuff", "Redo doing stuff"); form1.Delete(); m_actionHandler.EndUndoTask(); Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }), Is.EquivalentTo(new[] { form2.Hvo, form3.Hvo, form4.Hvo })); Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }), Is.EquivalentTo(new[] { form2.Hvo, form3.Hvo, form4.Hvo })); m_actionHandler.BeginUndoTask("Undo doing stuff", "Redo doing stuff"); form2.LexemeFormOA.Form.SetVernacularDefaultWritingSystem("other"); form2.SensesOS[0].Gloss.SetAnalysisDefaultWritingSystem("other"); m_actionHandler.EndUndoTask(); Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }), Is.EquivalentTo(new[] { form3.Hvo, form4.Hvo })); Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }), Is.EquivalentTo(new[] { form3.Hvo, form4.Hvo })); } }
public void ReconcilingDeletingObjects() { var kick = MakeEntry("kick", "punish severely"); var kick1 = AddSense(kick, "strike with foot"); var text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create(); if (Cache.LangProject.PartsOfSpeechOA == null) { Cache.LangProject.PartsOfSpeechOA = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); } VerifyReconcilingAChange(() => kick.SensesOS.RemoveAt(0), "deleting first sense"); ILexEntry punch = null; UndoableUnitOfWorkHelper.Do("undo make notebook record", "redo make notebook record", m_actionHandler, () => punch = MakeEntry("punch", "strike with foot")); VerifyReconcilingAChange(() => punch.Delete(), "deleting from collection"); VerifyReconcilingAChange(() => Cache.LangProject.PartsOfSpeechOA = null, "deleting from owning atomic"); }
public void InnerViewRefreshesWhenRefreshIsPending() { ILexEntry entry = null; int flid = 5035001; // MoForm flid NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => { entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); IMoStemAllomorph morph = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create(); entry.LexemeFormOA = morph; }); Form dummyForm = new Form(); LabeledMultiStringView view = new LabeledMultiStringView(entry.LexemeFormOA.Hvo, flid, WritingSystemServices.kwsVern, false, true); dummyForm.Controls.Add(view); InnerLabeledMultiStringView innerView = view.InnerView; view.FinishInit(); innerView.Cache = Cache; // Access the Handle of the innerView to construct the RootBox. var handle = innerView.Handle; Assert.IsFalse(innerView.Visible); Assert.IsFalse(innerView.RefreshPending); view.WritingSystemsToDisplay = WritingSystemServices.GetWritingSystemList(Cache, WritingSystemServices.kwsVern, false); view.RefreshDisplay(); // The flag gets set because the view is not yet visible, so the display cannot refresh. Assert.IsTrue(innerView.RefreshPending); // Trigger the display to refresh by making the form visible. dummyForm.Visible = true; Assert.IsFalse(innerView.RefreshPending); view.Dispose(); NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => entry.Delete()); }
public void UndoRedoIncomingRefs() { var servLoc = Cache.ServiceLocator; var leFact = servLoc.GetInstance <ILexEntryFactory>(); var le1 = leFact.Create(); var lsFact = servLoc.GetInstance <ILexSenseFactory>(); var ls1 = lsFact.Create(); le1.SensesOS.Add(ls1); if (Cache.LangProject.StatusOA == null) { Cache.LangProject.StatusOA = servLoc.GetInstance <ICmPossibilityListFactory>().Create(); } var possFact = servLoc.GetInstance <ICmPossibilityFactory>(); var status1 = possFact.Create(); Cache.LangProject.StatusOA.PossibilitiesOS.Add(status1); Cache.ActionHandlerAccessor.EndUndoTask(); // so we can have our own units of work to test Undo // Atomic UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => ls1.StatusRA = status1); Assert.AreEqual(1, status1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(0, status1.ReferringObjects.Count); m_actionHandler.Redo(); Assert.AreEqual(1, status1.ReferringObjects.Count); m_actionHandler.Undo(); // leave it Undone so it doesn't affect the ref collection test below. Assert.AreEqual(0, status1.ReferringObjects.Count); // Ref sequence UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => le1.MainEntriesOrSensesRS.Add(ls1)); Assert.AreEqual(1, ls1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(0, ls1.ReferringObjects.Count); m_actionHandler.Redo(); Assert.AreEqual(1, ls1.ReferringObjects.Count); m_actionHandler.Undo(); // cleanup Assert.AreEqual(0, ls1.ReferringObjects.Count); // Ref collection UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => ls1.DomainTypesRC.Add(status1)); Assert.AreEqual(1, status1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(0, status1.ReferringObjects.Count); m_actionHandler.Redo(); Assert.AreEqual(1, status1.ReferringObjects.Count); m_actionHandler.Undo(); // cleanup Assert.AreEqual(0, status1.ReferringObjects.Count); ILexSense ls2 = null; // Now see if it happens properly when we Undo and Redo object creation and deletion. // Atomic UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { ls2 = lsFact.Create(); le1.SensesOS.Add(ls2); ls2.StatusRA = status1; }); Assert.AreEqual(1, status1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(0, status1.ReferringObjects.Count); m_actionHandler.Redo(); Assert.AreEqual(1, status1.ReferringObjects.Count); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => le1.SensesOS.Remove(ls2)); Assert.AreEqual(0, status1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(1, status1.ReferringObjects.Count, "incoming ref should come back on undoing delete"); m_actionHandler.Redo(); Assert.AreEqual(0, status1.ReferringObjects.Count, "incoming ref should go away on redoing delete"); // collection UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { ls2 = lsFact.Create(); le1.SensesOS.Add(ls2); ls2.DomainTypesRC.Add(status1); }); Assert.AreEqual(1, status1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(0, status1.ReferringObjects.Count); m_actionHandler.Redo(); Assert.AreEqual(1, status1.ReferringObjects.Count); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => le1.SensesOS.Remove(ls2)); Assert.AreEqual(0, status1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(1, status1.ReferringObjects.Count, "incoming ref should come back on undoing delete"); m_actionHandler.Redo(); Assert.AreEqual(0, status1.ReferringObjects.Count, "incoming ref should go away on redoing delete"); // sequence ILexEntry le2 = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { le2 = leFact.Create(); le2.MainEntriesOrSensesRS.Add(ls1); }); Assert.AreEqual(1, ls1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(0, ls1.ReferringObjects.Count); m_actionHandler.Redo(); Assert.AreEqual(1, ls1.ReferringObjects.Count); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => le2.Delete()); Assert.AreEqual(0, ls1.ReferringObjects.Count); m_actionHandler.Undo(); Assert.AreEqual(1, ls1.ReferringObjects.Count, "incoming ref should come back on undoing delete"); m_actionHandler.Redo(); Assert.AreEqual(0, ls1.ReferringObjects.Count, "incoming ref should go away on redoing delete"); // The base class for this group of tests expects to end an Undo task after the test is over. Cache.ActionHandlerAccessor.BeginUndoTask("undo something", "redo something"); }