public void VectorPropertyTests() { var servLoc = Cache.ServiceLocator; var entryFactory = servLoc.GetInstance <ILexEntryFactory>(); var resourceFactory = servLoc.GetInstance <ICmResourceFactory>(); var lexDb = Cache.LanguageProject.LexDbOA; ILexEntry le2 = null; // The following tests assume one resource originally exists. We also need le2, to be the owner // of the senses. UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { lexDb.ResourcesOC.Add(resourceFactory.Create()); le2 = entryFactory.Create(); }); // 1 ClearChanges(); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => lexDb.ResourcesOC.Clear()); // Check the Resources vector prop. CheckChanges(1, -1, lexDb.Hvo, LexDbTags.kflidResources, 0, 1, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, -1, lexDb.Hvo, LexDbTags.kflidResources, 0, 0, 0); m_actionHandler.Redo(); ClearChanges(); // 2 // Test a collection property. ICmResource res1 = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Add one item. res1 = resourceFactory.Create(); lexDb.ResourcesOC.Add(res1); }); // Check the Entries vector prop. CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 1, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 0, 1); m_actionHandler.Redo(); ClearChanges(); // 3 ICmResource res2 = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Add another item. res2 = resourceFactory.Create(); lexDb.ResourcesOC.Add(res2); }); // Check the Resources vector prop. CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 1, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 0, 1); m_actionHandler.Redo(); SetLexeme(le2, "second"); ClearChanges(); // 4 ICmResource res3 = null; ICmResource res4 = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Add two new items. res3 = resourceFactory.Create(); lexDb.ResourcesOC.Add(res3); res4 = resourceFactory.Create(); lexDb.ResourcesOC.Add(res4); }); // Check the Entries vector prop. CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 2, 2, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 2, 0, 2); m_actionHandler.Redo(); ClearChanges(); // 5 UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Remove a couple of non-contiguous items. res1.Delete(); res3.Delete(); }); // Check the Entries vector prop. CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 1, 3); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 3, 1); m_actionHandler.Redo(); ClearChanges(); // 6 UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => res4.Delete()); // Check the Entries vector prop. CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 0, 1); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 1, 0); m_actionHandler.Redo(); ClearChanges(); // 7 // Test a sequence property. // By this point only le2 is still there, // which is fine, since we are moving to test senses, // and they can all go into le2. var senseFactory = servLoc.GetInstance <ILexSenseFactory>(); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Add one item. var se1 = senseFactory.Create(); le2.SensesOS.Add(se1); }); // Check the Senses vector prop. CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 1, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 0, 1); m_actionHandler.Redo(); ClearChanges(); // 8 UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Add another item, but before the other sense. var se2 = senseFactory.Create(); le2.SensesOS.Insert(0, se2); }); // Check the Senses vector prop. CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 1, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 0, 1); m_actionHandler.Redo(); ClearChanges(); // 9 UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Add another item, but between the other two senses. var se3 = senseFactory.Create(); le2.SensesOS.Insert(1, se3); }); // Check the Senses vector prop. CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 1, 1, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 1, 0, 1); m_actionHandler.Redo(); ClearChanges(); // 10 UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Add another item, but between two senses. var se4 = senseFactory.Create(); le2.SensesOS.Insert(2, se4); // Add yet another one at the end. var se5 = senseFactory.Create(); le2.SensesOS.Add(se5); }); // Check the Senses vector prop. CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 2, 3, 1); ClearChanges(); m_actionHandler.Undo(); CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 2, 1, 3); m_actionHandler.Redo(); ClearChanges(); // 11 // Clear Entries prop var resourcesCount = lexDb.ResourcesOC.Count(); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => lexDb.ResourcesOC.Clear()); // Check the Entries vector prop. CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 0, resourcesCount); ClearChanges(); m_actionHandler.Undo(); CheckChanges(lexDb.Hvo, LexDbTags.kflidResources, 0, resourcesCount, 0); m_actionHandler.Redo(); ClearChanges(); }