public void CopySeveralObjects_unrelated() { // Setup test var source = new List <ICmObject>(); // IEnumerable collection to feed to CopyObject ICmPossibilityList possList = m_servLoc.GetInstance <ICmPossibilityListFactory>().Create(); Cache.LanguageProject.TimeOfDayOA = possList; possList.ListVersion = new Guid("5f145304-64cd-47ef-2001-d147ddda0492"); possList.IsSorted = true; source.Add(possList); // Make a Wordform Object var wordform = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); wordform.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("rubbish", Cache.DefaultVernWs); source.Add(wordform); // SUT var newCollection = CopyObject <ICmObject> .CloneFdoObjects(source, x => Cache.LanguageProject.ThesaurusRA = (ICmPossibilityList)x); var newList = new List <ICmObject>(newCollection); // Verify results Assert.AreEqual(2, newList.Count, "Copied the wrong number of objects!"); var newPoss = (ICmPossibilityList)newList[0]; var newWordform = (IWfiWordform)newList[1]; VerifyWordform(wordform, newWordform); Assert.AreNotEqual(possList, newPoss); Assert.AreEqual(possList.ListVersion, newPoss.ListVersion); Assert.AreEqual(possList.IsSorted, newPoss.IsSorted); }
public void CopySeveralObjects_interrelated() { // Test Setup var source = new List <ICmObject>(); // IEnumerable collection to feed to CopyObject var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); source.Add(entry); var sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense); var msa = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create(); entry.MorphoSyntaxAnalysesOC.Add(msa); sense.MorphoSyntaxAnalysisRA = msa; var statusList = Cache.LanguageProject.StatusOA; if (statusList == null) { statusList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); Cache.LanguageProject.StatusOA = statusList; } if (statusList.PossibilitiesOS.Count == 0) { var status = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); statusList.PossibilitiesOS.Add(status); } sense.StatusRA = statusList.PossibilitiesOS[0]; // SUT var copyColl = CopyObject <ICmObject> .CloneFdoObjects(source, CopyObject <ICmObject> .kAddToSourceOwner); var newList = new List <ICmObject>(); foreach (ICmObject obj in copyColl) { newList.Add(obj); } // Verify results Assert.AreEqual(1, newList.Count, "Wrong number of copied objects."); // Verify new TextSegment var newEntry = newList[0] as ILexEntry; Assert.IsNotNull(newEntry, "Root entry failed to copy."); Assert.AreNotEqual(entry, newEntry, "Copy of entry should not be the same object."); Assert.AreEqual(1, newEntry.SensesOS.Count, "We should have same number of senses on the copy."); var newSense = newEntry.SensesOS[0]; Assert.AreNotEqual(sense, newSense, "Copy of sense should not be the same object."); var newMsa = newEntry.MorphoSyntaxAnalysesOC.ToArray()[0]; Assert.AreNotEqual(msa, newMsa, "Copy of Msa should not be the same object."); Assert.AreEqual(newMsa, newSense.MorphoSyntaxAnalysisRA, "The copy of the sense should point to the copy of the msa."); Assert.AreEqual(statusList.PossibilitiesOS[0], newSense.StatusRA, "The copy of the sense should point to the uncopied status."); }