/// ------------------------------------------------------------------------------------ /// <summary> /// If a test overrides this, it should call this base implementation. /// </summary> /// ------------------------------------------------------------------------------------ public override void TestSetup() { base.TestSetup(); m_notifiee = new Notifiee(); m_sda.AddNotification(m_notifiee); }
public void SetAndAccessMultiStrings() { ITsStrFactory tsf = TsStrFactoryClass.Create(); int kflid = XMLViewsDataCache.ktagEditColumnBase; int hvoRoot = 10578; int wsEng = Cache.WritingSystemFactory.GetWsFromStr("en"); XMLViewsDataCache xmlCache = new XMLViewsDataCache(Cache.MainCacheAccessor as ISilDataAccessManaged, true, new Dictionary<int, int>()); Notifiee recorder = new Notifiee(); xmlCache.AddNotification(recorder); Assert.AreEqual(0, xmlCache.get_MultiStringAlt(hvoRoot, kflid, wsEng).Length); Assert.AreEqual(0, recorder.Changes.Count); ITsString test1 = tsf.MakeString("test1", wsEng); xmlCache.CacheMultiString(hvoRoot, kflid, wsEng, test1); Assert.AreEqual(0, recorder.Changes.Count); Assert.AreEqual(test1, xmlCache.get_MultiStringAlt(hvoRoot, kflid, wsEng)); ITsString test2 = tsf.MakeString("blah", wsEng); xmlCache.SetMultiStringAlt(hvoRoot, kflid, wsEng, test2); Assert.AreEqual(test2, xmlCache.get_MultiStringAlt(hvoRoot, kflid, wsEng)); recorder.CheckChanges(new ChangeInformationTest[] {new ChangeInformationTest(hvoRoot, kflid, wsEng, 0, 0)}, "expected PropChanged from setting string"); xmlCache.RemoveNotification(recorder); // Enhance JohnT: a better test would verify that it doesn't intefere with other multistrings, // and that it can store stuff independently for different HVOs, tags, and WSs. }
/// ------------------------------------------------------------------------------------ /// <summary> /// If a test overrides this, it should call this base implementation. /// </summary> /// ------------------------------------------------------------------------------------ public override void TestTearDown() { m_sda.RemoveNotification(m_notifiee); m_notifiee = null; while (m_actionHandler.CanUndo()) m_actionHandler.Undo(); m_actionHandler.Commit(); base.TestTearDown(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// If a test overrides this, it should call this base implementation. /// </summary> /// ------------------------------------------------------------------------------------ public override void TestTearDown() { m_sda.RemoveNotification(m_notifiee); m_notifiee = null; while (m_actionHandler.CanUndo()) { m_actionHandler.Undo(); } m_actionHandler.Commit(); base.TestTearDown(); }
public void SetAndAccessDummyList() { ILexDb lexDb = Cache.LangProject.LexDbOA; ILexEntry entry1 = null; ICmResource res1 = null; NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () => { var leFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>(); entry1 = leFactory.Create(); ILexEntry entry2 = leFactory.Create(); res1 = Cache.ServiceLocator.GetInstance<ICmResourceFactory>().Create(); lexDb.ResourcesOC.Add(res1); }); int hvoRoot = 10578; ObjectListPublisher publisher = new ObjectListPublisher(Cache.MainCacheAccessor as ISilDataAccessManaged, ObjectListFlid); var values = new int[] {23, 56, 2048}; Notifiee recorder = new Notifiee(); publisher.AddNotification(recorder); publisher.CacheVecProp(hvoRoot, values); Assert.AreEqual(values.Length, publisher.get_VecSize(hvoRoot, ObjectListFlid), "override of vec size"); //Assert.AreEqual(Cache.LangProject.Texts.Count, publisher.get_VecSize(Cache.LangProject.Hvo, LangProjectTags.kflidTexts), "base vec size"); Assert.AreEqual(23, publisher.get_VecItem(hvoRoot, ObjectListFlid, 0), "override of vec item"); Assert.AreEqual(res1.Hvo, publisher.get_VecItem(lexDb.Hvo, LexDbTags.kflidResources, 0), "base vec item"); Assert.AreEqual(56, publisher.get_VecItem(hvoRoot, ObjectListFlid, 1), "override of vec item, non-zero index"); VerifyCurrentValue(hvoRoot, publisher, values, "original value"); Assert.AreEqual(lexDb.ResourcesOC.Count(), publisher.VecProp(lexDb.Hvo, LexDbTags.kflidResources).Length, "base VecProp"); recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 0, values.Length, 0) }, "expected PropChanged from caching HVOs"); publisher.RemoveNotification(recorder); recorder = new Notifiee(); publisher.AddNotification(recorder); publisher.Replace(hvoRoot, 1, new int[] {97, 98}, 0); VerifyCurrentValue(hvoRoot, publisher, new int[] {23, 97, 98, 56, 2048}, "after inserting 97, 98" ); recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 2, 0) }, "expected PropChanged from caching HVOs"); publisher.RemoveNotification(recorder); recorder = new Notifiee(); publisher.AddNotification(recorder); publisher.Replace(hvoRoot, 1, new int[0] , 2); VerifyCurrentValue(hvoRoot, publisher, new int[] { 23, 56, 2048 }, "after deleting 97, 98"); recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 0, 2) }, "expected PropChanged from caching HVOs"); publisher.RemoveNotification(recorder); }
public void ReconcileCollectionChanges() { int entryCount = Cache.LangProject.LexDbOA.Entries.Count(); var destroy = MakeEntry("destroy", "wipe out"); var destroyId = destroy.Id; var remove = MakeEntry("remove", "get rid of"); var removeId = remove.Id; ILexEntry right = null; ICmObjectId rightId = null; ILexEntry kick = null; List<ICmObjectSurrogate> newbiesClockwise; List<ICmObjectSurrogate> dirtballsClockwise; List<ICmObjectId> gonersClockwise; GetEffectsOfChange(() => { right = MakeEntry("right", "correct"); destroy.Delete(); }, () => rightId = right.Id, out newbiesClockwise, out dirtballsClockwise, out gonersClockwise); UndoableUnitOfWorkHelper.Do("undo", "redo", m_actionHandler, () => { kick = MakeEntry("kick", "strike with foot"); remove.Delete(); }); var uowService = Cache.ServiceLocator.GetInstance<IUnitOfWorkService>(); var reconciler = ((UnitOfWorkService)uowService).CreateReconciler(newbiesClockwise, dirtballsClockwise, gonersClockwise); var notifiee = new Notifiee(); Cache.DomainDataByFlid.AddNotification(notifiee); Assert.That(reconciler.OkToReconcileChanges(), Is.True); reconciler.ReconcileForeignChanges(); // In effect the other client added 'right' and deleted 'destroy'. Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(kick)); right = (ILexEntry)Cache.ServiceLocator.GetObject(rightId); // will throw if it doesn't exist. Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right)); Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(remove)); Assert.IsFalse(Cache.ServiceLocator.ObjectRepository.IsValidObjectId(destroyId.Guid)); // One way to be sure 'destroy' really got destroyed. Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2)); // See if we got PropChanged notifications on 'Entries' int flidEntries = Cache.MetaDataCache.GetFieldId2(LexDbTags.kClassId, "Entries", false); notifiee.CheckChangesWeaker( new[] {new ChangeInformationTest(Cache.LangProject.LexDbOA.Hvo, flidEntries, 0, entryCount + 2, entryCount + 2)}, "missing Entries propcount"); // adding kick; right should still be there. Remove should come back, Destroy still be gone. m_actionHandler.Undo(); Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(kick)); Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right)); Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(remove)); Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2)); m_actionHandler.Redo(); // restore kick, re-delete Remove. Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(kick)); Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right)); Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(remove)); Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2)); }
public void NumberOfSenses() { ILexEntry entry; ILexSense sense2, sense2_2; ILexSense senseInserted; using (var helper = new NonUndoableUnitOfWorkHelper(m_actionHandler)) { entry = m_entryFactory.Create(); var sense = m_senseFactory.Create(); entry.SensesOS.Add(sense); Assert.AreEqual(1, entry.NumberOfSensesForEntry); sense2 = m_senseFactory.Create(); entry.SensesOS.Add(sense2); Assert.AreEqual(2, entry.NumberOfSensesForEntry); var sense3 = m_senseFactory.Create(); entry.SensesOS.Add(sense3); Assert.AreEqual(3, entry.NumberOfSensesForEntry); var sense2_1 = m_senseFactory.Create(); sense2.SensesOS.Add(sense2_1); Assert.AreEqual(4, entry.NumberOfSensesForEntry); sense2_2 = m_senseFactory.Create(); sense2.SensesOS.Add(sense2_2); Assert.AreEqual(5, entry.NumberOfSensesForEntry); var sense2_1_1 = m_senseFactory.Create(); sense2_1.SensesOS.Add(sense2_1_1); Assert.AreEqual(6, entry.NumberOfSensesForEntry); var sense2_2_1 = m_senseFactory.Create(); sense2_2.SensesOS.Add(sense2_2_1); Assert.AreEqual(7, entry.NumberOfSensesForEntry); helper.RollBack = false; } m_notifiee = new Notifiee(); IFwMetaDataCache mdc = m_sda.MetaDataCache; int nosFlid = mdc.GetFieldId("LexEntry", "NumberOfSensesForEntry", false); m_sda.AddNotification(m_notifiee); using (var helper = new NonUndoableUnitOfWorkHelper(m_actionHandler)) { senseInserted = m_senseFactory.Create(); entry.SensesOS.Insert(1, senseInserted); Assert.AreEqual(8, entry.NumberOfSensesForEntry); // Added one top-level sense helper.RollBack = false; } m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(entry.Hvo, LexEntryTags.kflidSenses, 1, 1, 0), new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), }, "insert second sense in entry"); m_sda.RemoveNotification(m_notifiee); m_notifiee = new Notifiee(); m_sda.AddNotification(m_notifiee); using (var helper = new NonUndoableUnitOfWorkHelper(m_actionHandler)) { entry.SensesOS.Remove(senseInserted); helper.RollBack = false; } m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(entry.Hvo, LexEntryTags.kflidSenses, 1, 0, 1), new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), }, "delete second sense in entry"); m_sda.RemoveNotification(m_notifiee); Assert.AreEqual(7, entry.NumberOfSensesForEntry); m_notifiee = new Notifiee(); m_sda.AddNotification(m_notifiee); using (var helper = new NonUndoableUnitOfWorkHelper(m_actionHandler)) { senseInserted = m_senseFactory.Create(); sense2.SensesOS.Insert(1, senseInserted); Assert.AreEqual(8, entry.NumberOfSensesForEntry); // Added a subsense. helper.RollBack = false; } m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(sense2.Hvo, LexSenseTags.kflidSenses, 1, 1, 0), new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), }, "insert subsense in sense"); m_sda.RemoveNotification(m_notifiee); Assert.AreEqual(8, entry.NumberOfSensesForEntry); m_notifiee = new Notifiee(); m_sda.AddNotification(m_notifiee); using (var helper = new NonUndoableUnitOfWorkHelper(m_actionHandler)) { sense2.SensesOS.Remove(senseInserted); helper.RollBack = false; } m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(sense2.Hvo, LexSenseTags.kflidSenses, 1, 0, 1), new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), }, "remove subsense from sense"); m_sda.RemoveNotification(m_notifiee); Assert.AreEqual(7, entry.NumberOfSensesForEntry); }
public void TestLexSenseSideEffects() { var senseFactory = Cache.ServiceLocator.GetInstance<ILexSenseFactory>(); ILexEntry entry = null; ILexSense sense, sense2 = null, sense3 = null, sense2_1 = null, sense2_2 = null, sense2_1_1 = null, sense2_2_1 = null; UndoableUnitOfWorkHelper.Do("Undo add senses", "Redo add senses", m_actionHandler, () => { entry = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(); sense = senseFactory.Create(); entry.SensesOS.Add(sense); Assert.AreEqual("1", sense.LexSenseOutline.Text); sense2 = senseFactory.Create(); entry.SensesOS.Add(sense2); Assert.AreEqual("2", sense2.LexSenseOutline.Text); sense3 = senseFactory.Create(); entry.SensesOS.Add(sense3); Assert.AreEqual("3", sense3.LexSenseOutline.Text); sense2_1 = senseFactory.Create(); sense2.SensesOS.Add(sense2_1); Assert.AreEqual("2.1", sense2_1.LexSenseOutline.Text); sense2_2 = senseFactory.Create(); sense2.SensesOS.Add(sense2_2); Assert.AreEqual("2.2", sense2_2.LexSenseOutline.Text); sense2_1_1 = senseFactory.Create(); sense2_1.SensesOS.Add(sense2_1_1); Assert.AreEqual("2.1.1", sense2_1_1.LexSenseOutline.Text); sense2_2_1 = senseFactory.Create(); sense2_2.SensesOS.Add(sense2_2_1); Assert.AreEqual("2.2.1", sense2_2_1.LexSenseOutline.Text); }); m_notifiee = new Notifiee(); var mdc = m_sda.MetaDataCache; var lsoFlid = mdc.GetFieldId("LexSense", "LexSenseOutline", false); m_sda.AddNotification(m_notifiee); ILexSense senseInserted = null; UndoableUnitOfWorkHelper.Do("Undo add another sense", "Redo add another sense", m_actionHandler, () => { senseInserted = senseFactory.Create(); entry.SensesOS.Insert(1, senseInserted); Assert.AreEqual("2", senseInserted.LexSenseOutline.Text); }); int nosFlid = mdc.GetFieldId("LexEntry", "NumberOfSensesForEntry", false); m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), new ChangeInformationTest(entry.Hvo, LexEntryTags.kflidSenses, 1, 1, 0), new ChangeInformationTest(sense2.Hvo, lsoFlid, 0, "2".Length, "3".Length), new ChangeInformationTest(sense3.Hvo, lsoFlid, 0, "3".Length, "4".Length), new ChangeInformationTest(sense2_1.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length), new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length), new ChangeInformationTest(sense2_1_1.Hvo, lsoFlid, 0, "2.1.1".Length, "3.1.1".Length), new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "3.2.1".Length), }, "insert second sense in entry"); m_sda.RemoveNotification(m_notifiee); Assert.AreEqual("3.1.1", sense2_1_1.LexSenseOutline.Text); m_notifiee = new Notifiee(); m_sda.AddNotification(m_notifiee); UndoableUnitOfWorkHelper.Do("Undo remove sense", "Redo remove sense", m_actionHandler, () => entry.SensesOS.Remove(senseInserted)); m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), new ChangeInformationTest(entry.Hvo, LexEntryTags.kflidSenses, 1, 0, 1), new ChangeInformationTest(sense2.Hvo, lsoFlid, 0, "2".Length, "3".Length), new ChangeInformationTest(sense3.Hvo, lsoFlid, 0, "3".Length, "4".Length), new ChangeInformationTest(sense2_1.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length), new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.1".Length, "3.1".Length), new ChangeInformationTest(sense2_1_1.Hvo, lsoFlid, 0, "2.1.1".Length, "3.1.1".Length), new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "3.2.1".Length), }, "delete second sense in entry"); m_sda.RemoveNotification(m_notifiee); Assert.AreEqual("2.1.1", sense2_1_1.LexSenseOutline.Text); m_notifiee = new Notifiee(); m_sda.AddNotification(m_notifiee); UndoableUnitOfWorkHelper.Do("Undo add another sense", "Redo add another sense", m_actionHandler, () => { senseInserted = senseFactory.Create(); sense2.SensesOS.Insert(1, senseInserted); Assert.AreEqual("2.2", senseInserted.LexSenseOutline.Text); }); m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), new ChangeInformationTest(sense2.Hvo, LexSenseTags.kflidSenses, 1, 1, 0), new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.2".Length, "2.3".Length), new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "2.3.1".Length), }, "insert subsense in sense"); m_sda.RemoveNotification(m_notifiee); Assert.AreEqual("2.3.1", sense2_2_1.LexSenseOutline.Text); m_notifiee = new Notifiee(); m_sda.AddNotification(m_notifiee); UndoableUnitOfWorkHelper.Do("Undo get rid of sense", "Redo get rid of sense", m_actionHandler, () => sense2.SensesOS.Remove(senseInserted)); m_notifiee.CheckChangesWeaker(new[] { new ChangeInformationTest(entry.Hvo, nosFlid, 0, 0, 0), new ChangeInformationTest(sense2.Hvo, LexSenseTags.kflidSenses, 1, 0, 1), new ChangeInformationTest(sense2_2.Hvo, lsoFlid, 0, "2.2".Length, "2.3".Length), new ChangeInformationTest(sense2_2_1.Hvo, lsoFlid, 0, "2.2.1".Length, "2.3.1".Length), }, "remove subsense from sense"); m_sda.RemoveNotification(m_notifiee); Assert.AreEqual("2.2.1", sense2_2_1.LexSenseOutline.Text); }