public void CountPropertyTests() { ILcmServiceLocator servLoc = Cache.ServiceLocator; ILangProject lp = Cache.LanguageProject; ILexDb lexDb = lp.LexDbOA; ILexEntry le = servLoc.GetInstance <ILexEntryFactory>().Create(); ILexSense sense = servLoc.GetInstance <ILexSenseFactory>().Create(); le.SensesOS.Add(sense); // LcmReferenceCollection int originalCount = lexDb.LexicalFormIndexRC.Count; lexDb.LexicalFormIndexRC.Add(le); Assert.AreEqual(originalCount + 1, lexDb.LexicalFormIndexRC.Count); lexDb.LexicalFormIndexRC.Remove(le); Assert.AreEqual(originalCount, lexDb.LexicalFormIndexRC.Count); // LcmReferenceSequence originalCount = le.MainEntriesOrSensesRS.Count; le.MainEntriesOrSensesRS.Add(sense); Assert.AreEqual(originalCount + 1, le.MainEntriesOrSensesRS.Count); le.MainEntriesOrSensesRS.RemoveAt(le.MainEntriesOrSensesRS.Count - 1); Assert.AreEqual(originalCount, le.MainEntriesOrSensesRS.Count); }
public void Insert_Null() { ILcmServiceLocator servLoc = Cache.ServiceLocator; servLoc.GetInstance <IScrBookFactory>().Create(1); m_scr.ScriptureBooksOS.Insert(0, null); }
/// <summary> /// Make an individual spelling dictionary conform as closely as possible to the spelling status /// recorded in Wordforms. /// </summary> /// <param name="ws"></param> /// <param name="cache"></param> public static void ConformOneSpellingDictToWordforms(int ws, LcmCache cache) { ILcmServiceLocator servloc = cache.ServiceLocator; var lgwsFactory = servloc.GetInstance <ILgWritingSystemFactory>(); var dict = SpellingHelper.GetSpellChecker(ws, lgwsFactory); if (dict == null) { return; } // we only force one to exist for the default, others might not have one. var words = new List <string>(); foreach (IWfiWordform wf in servloc.GetInstance <IWfiWordformRepository>().AllInstances()) { if (wf.SpellingStatus != (int)SpellingStatusStates.correct) { continue; // don't put it in the list of correct words } string wordform = wf.Form.get_String(ws).Text; if (!string.IsNullOrEmpty(wordform)) { words.Add(wordform); } } SpellingHelper.ResetDictionary(SpellingHelper.DictionaryId(ws, lgwsFactory), words); }
public InterestingTextsDecorator(ISilDataAccessManaged domainDataByFlid, XmlNode configurationNode, ILcmServiceLocator services) : base(domainDataByFlid) { SetOverrideMdc(new InterestingTextsMdc(base.MetaDataCache as IFwMetaDataCacheManaged)); m_services = services; }
public DiscourseTestHelper(LcmCache cache) { m_cache = cache; #region Load Factories and Repositories m_servLoc = m_cache.ServiceLocator; m_wAnalysisFact = m_servLoc.GetInstance <IWfiAnalysisFactory>(); m_wGlossFact = m_servLoc.GetInstance <IWfiGlossFactory>(); m_rowFact = m_servLoc.GetInstance <IConstChartRowFactory>(); m_wordGrpFact = m_servLoc.GetInstance <IConstChartWordGroupFactory>(); m_ccTagFact = m_servLoc.GetInstance <IConstChartTagFactory>(); m_mtmFact = m_servLoc.GetInstance <IConstChartMovedTextMarkerFactory>(); m_clauseMrkrFact = m_servLoc.GetInstance <IConstChartClauseMarkerFactory>(); m_partRepo = m_servLoc.GetInstance <IConstituentChartCellPartRepository>(); m_rowRepo = m_servLoc.GetInstance <IConstChartRowRepository>(); #endregion m_text = m_servLoc.GetInstance <ITextFactory>().Create(); m_stText = m_servLoc.GetInstance <IStTextFactory>().Create(); m_text.ContentsOA = m_stText; m_allOccurrences = new Dictionary <IStTxtPara, AnalysisOccurrence[]>(); m_firstPara = MakeParagraph(); }
public ConcDecorator(ISilDataAccessManaged domainDataByFlid, XmlNode configurationNode, ILcmServiceLocator services) : base(domainDataByFlid) { m_services = services; SetOverrideMdc(new ConcMdc(MetaDataCache as IFwMetaDataCacheManaged)); }
internal GhostParentHelper(ILcmServiceLocator services, int parentClsid, int flidOwning) { m_services = services; m_parentClsid = parentClsid; m_flidOwning = flidOwning; var mdc = m_services.GetInstance <IFwMetaDataCacheManaged>(); TargetClass = mdc.GetDstClsId(flidOwning); switch ((CellarPropertyType)mdc.GetFieldType(flidOwning)) { case CellarPropertyType.OwningAtomic: m_indexToCreate = -2; break; case CellarPropertyType.OwningCollection: m_indexToCreate = -1; break; case CellarPropertyType.OwningSequence: m_indexToCreate = 0; break; default: throw new InvalidOperationException("can only create objects in owning properties"); } }
public void AddTo_RefColToRefCol() { ILcmServiceLocator servLoc = Cache.ServiceLocator; ILangProject lp = Cache.LanguageProject; ILexDb lexDb = lp.LexDbOA; ILexAppendix app1 = servLoc.GetInstance <ILexAppendixFactory>().Create(); lexDb.AppendixesOC.Add(app1); ILexAppendix app2 = servLoc.GetInstance <ILexAppendixFactory>().Create(); lexDb.AppendixesOC.Add(app2); ILexEntry le1 = servLoc.GetInstance <ILexEntryFactory>().Create(); ILexSense sense1 = servLoc.GetInstance <ILexSenseFactory>().Create(); le1.SensesOS.Add(sense1); ILexSense sense2 = servLoc.GetInstance <ILexSenseFactory>().Create(); le1.SensesOS.Add(sense2); sense1.AppendixesRC.Add(app1); sense1.AppendixesRC.Add(app2); sense1.AppendixesRC.AddTo(sense2.AppendixesRC); Assert.AreEqual(2, sense2.AppendixesRC.Count); Assert.IsTrue(sense2.AppendixesRC.Contains(app1)); Assert.IsTrue(sense2.AppendixesRC.Contains(app2)); }
/// <summary> /// Returns GPHs for the four properties we currently know about, or null if not a known property that has ghosts. /// </summary> /// <param name="services"></param> /// <param name="classDotMethod"></param> /// <returns></returns> public static GhostParentHelper CreateIfPossible(ILcmServiceLocator services, string classDotMethod) { switch (classDotMethod) { case "LexDb.AllPossiblePronunciations": return(new GhostParentHelper(services, LexEntryTags.kClassId, LexEntryTags.kflidPronunciations)); case "LexDb.AllPossibleEtymologies": return(new GhostParentHelper(services, LexEntryTags.kClassId, LexEntryTags.kflidEtymology)); case "LexDb.AllPossibleAllomorphs": return(new GphAllPossibleAllomorphs(services, LexEntryTags.kClassId, LexEntryTags.kflidAlternateForms)); case "LexDb.AllExampleSentenceTargets": return(new GhostParentHelper(services, LexSenseTags.kClassId, LexSenseTags.kflidExamples)); case "LexDb.AllExampleTranslationTargets": return(new GhostParentHelper(services, LexExampleSentenceTags.kClassId, LexExampleSentenceTags.kflidTranslations)); case "LexDb.AllComplexEntryRefPropertyTargets": return(new GphComplexEntries(services)); case "LexDb.AllVariantEntryRefPropertyTargets": return(new GphVariants(services)); case "LexDb.AllExtendedNoteTargets": return(new GhostParentHelper(services, LexSenseTags.kClassId, LexSenseTags.kflidExtendedNote)); case "LexDb.AllPossiblePictures": return(new GhostParentHelper(services, LexSenseTags.kClassId, LexSenseTags.kflidPictures)); default: return(null); } }
public void IndexedSetter_EmptyList() { ILcmServiceLocator servLoc = Cache.ServiceLocator; Cache.LangProject.CheckListsOC.Add(servLoc.GetInstance <ICmPossibilityListFactory>().Create()); Cache.LangProject.CheckListsOC.First().PossibilitiesOS[0] = servLoc.GetInstance <ICmPossibilityFactory>().Create(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="CopyObject<TTopLevel>"/> class. /// </summary> /// <param name="cache">The cache.</param> /// <param name="topLevelOwnerFunct">The delegate used for adding the created object to /// an owner.</param> /// ------------------------------------------------------------------------------------ private CopyObject(LcmCache cache, CopiedOwner <TTopLevel> topLevelOwnerFunct) { m_cache = cache; m_servLoc = m_cache.ServiceLocator; m_sda = m_cache.DomainDataByFlid; m_mdc = m_cache.ServiceLocator.GetInstance <IFwMetaDataCacheManaged>(); m_topLevelOwnerFunct = topLevelOwnerFunct; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the test data. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_servLoc = Cache.ServiceLocator; m_wsf = Cache.WritingSystemFactory; m_ws_en = m_wsf.GetWsFromStr("en"); CreateTestText(); }
public void Insert_Null() { ILcmServiceLocator servLoc = Cache.ServiceLocator; servLoc.GetInstance <IScrBookFactory>().Create(1); Assert.That(() => m_scr.ScriptureBooksOS.Insert(0, null), Throws.TypeOf <ArgumentNullException>()); }
/// <summary> /// Create test data for ReferenceAdjusterService tests. /// </summary> protected override void CreateTestData() { base.CreateTestData(); m_servLoc = Cache.ServiceLocator; m_raService = m_servLoc.GetInstance <IReferenceAdjuster>(); m_tagFact = m_servLoc.GetInstance <ITextTagFactory>(); CreateTestText(); }
public void IndexedSetter_EmptyList() { ILcmServiceLocator servLoc = Cache.ServiceLocator; Cache.LangProject.CheckListsOC.Add(servLoc.GetInstance <ICmPossibilityListFactory>().Create()); Assert.That(() => Cache.LangProject.CheckListsOC.First().PossibilitiesOS[0] = servLoc.GetInstance <ICmPossibilityFactory>().Create(), Throws.TypeOf <ArgumentOutOfRangeException>()); }
public void CopyTo_NoItemsInEmptyItemListTest() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBook[] bookArray = new IScrBook[0]; m_scr.ScriptureBooksOS.CopyTo(bookArray, 0); // This test makes sure that an exception is not thrown when the array is empty. // This fixes creating a new List<> when giving a LcmVector as the parameter. }
public void Insert_Deleted() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBook book0 = servLoc.GetInstance <IScrBookFactory>().Create(1); m_scr.ScriptureBooksOS.Remove(book0); m_scr.ScriptureBooksOS.Insert(0, book0); }
/// <summary> /// set up member variables and test data. /// </summary> protected override void CreateTestData() { base.CreateTestData(); m_servLoc = Cache.ServiceLocator; m_servLoc.GetInstance <IVirtualOrderingFactory>(); m_voRepo = m_servLoc.GetInstance <IVirtualOrderingRepository>(); m_possFact = m_servLoc.GetInstance <ICmPossibilityFactory>(); CreateKnownPossibilityList(); }
/// <summary> /// Returns GPHs for the four properties we currently know about. /// </summary> /// <param name="services"></param> /// <param name="classDotMethod"></param> /// <returns></returns> public static GhostParentHelper Create(ILcmServiceLocator services, string classDotMethod) { var result = CreateIfPossible(services, classDotMethod); if (result == null) { throw new ArgumentException("Unexpected field request to GhostParentHelper.Create", "classDotMethod"); } return(result); }
public void Insert_Deleted() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBook book0 = servLoc.GetInstance <IScrBookFactory>().Create(1); m_scr.ScriptureBooksOS.Remove(book0); Assert.That(() => m_scr.ScriptureBooksOS.Insert(0, book0), Throws.TypeOf <LcmObjectDeletedException>().With.Message.EqualTo("Owned object has been deleted.")); }
/// <summary> /// Restore any appropriate settings which have values in the property table /// </summary> public static void RestoreSettings(ILcmServiceLocator services, PropertyTable propertyTable) { var hcSettings = propertyTable.GetStringProperty(khomographconfiguration, null); if (hcSettings != null) { var hc = services.GetInstance <HomographConfiguration>(); hc.PersistData = hcSettings; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads all the lexical entries from the specified service locator into a collection /// of PaLexEntry objects and returns the collection in a serialized list. /// </summary> /// ------------------------------------------------------------------------------------ internal static string GetAllAsXml(ILcmServiceLocator svcloc) { try { return(XmlSerializationHelper.SerializeToString(GetAll(svcloc))); } catch { return(null); } }
public void InsertIntoRefSequence_Uninitialized() { ILcmServiceLocator servLoc = Cache.ServiceLocator; ILangProject lp = Cache.LanguageProject; ILexEntry le = servLoc.GetInstance <ILexEntryFactory>().Create(); var senseUninitialized = MockRepository.GenerateStub <ILexSense>(); senseUninitialized.Stub(x => x.Hvo).Return((int)SpecialHVOValues.kHvoUninitializedObject); le.MainEntriesOrSensesRS.Insert(0, senseUninitialized); }
private IWfiWordform FindOrCreateWordform(string form) { ILcmServiceLocator servLoc = Cache.ServiceLocator; IWfiWordform wf = servLoc.GetInstance <IWfiWordformRepository>().GetMatchingWordform(m_vernacularWS.Handle, form); if (wf == null) { UndoableUnitOfWorkHelper.Do("Undo create", "Redo create", m_actionHandler, () => wf = servLoc.GetInstance <IWfiWordformFactory>().Create(TsStringUtils.MakeString(form, m_vernacularWS.Handle))); } return(wf); }
public void InsertIntoRefSequence_Uninitialized() { ILcmServiceLocator servLoc = Cache.ServiceLocator; ILangProject lp = Cache.LanguageProject; ILexEntry le = servLoc.GetInstance <ILexEntryFactory>().Create(); var senseUninitialized = MockRepository.GenerateStub <ILexSense>(); senseUninitialized.Stub(x => x.Hvo).Return((int)SpecialHVOValues.kHvoUninitializedObject); Assert.That(() => le.MainEntriesOrSensesRS.Insert(0, senseUninitialized), Throws.TypeOf <LcmObjectUninitializedException>().With.Message.EqualTo("Object has not been initialized.")); }
public void AddNullItem2ToVectorTest() { ILcmServiceLocator servLoc = Cache.ServiceLocator; ILangProject lp = Cache.LanguageProject; ILexEntry le = servLoc.GetInstance <ILexEntryFactory>().Create(); ILexSense sense = servLoc.GetInstance <ILexSenseFactory>().Create(); le.SensesOS.Add(sense); le.MainEntriesOrSensesRS.Add(sense); le.MainEntriesOrSensesRS[0] = null; // Should throw the exception. }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create test data for tests. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_servloc = Cache.ServiceLocator; m_text = AddInterlinearTextToLangProj("My Interlinear Text"); m_stTextPara = AddParaToInterlinearTextContents(m_text, "Here is a sentence I can chart."); m_stText = m_text.ContentsOA; m_rowFact = m_servloc.GetInstance <IConstChartRowFactory>(); m_wordGrpFact = m_servloc.GetInstance <IConstChartWordGroupFactory>(); m_possFact = m_servloc.GetInstance <ICmPossibilityFactory>(); m_wfiFact = m_servloc.GetInstance <IWfiWordformFactory>(); m_mtMrkrFact = m_servloc.GetInstance <IConstChartMovedTextMarkerFactory>(); m_clsMrkrFact = m_servloc.GetInstance <IConstChartClauseMarkerFactory>(); }
public void AddNullItem2ToVectorTest() { ILcmServiceLocator servLoc = Cache.ServiceLocator; ILangProject lp = Cache.LanguageProject; ILexEntry le = servLoc.GetInstance <ILexEntryFactory>().Create(); ILexSense sense = servLoc.GetInstance <ILexSenseFactory>().Create(); le.SensesOS.Add(sense); le.MainEntriesOrSensesRS.Add(sense); Assert.That(() => le.MainEntriesOrSensesRS[0] = null, Throws.TypeOf <NotSupportedException>()); }
public void ContainsMethodTests() { ILcmServiceLocator servLoc = Cache.ServiceLocator; ILangProject lp = Cache.LanguageProject; ILexDb lexDb = lp.LexDbOA; ILexEntry le = servLoc.GetInstance <ILexEntryFactory>().Create(); // LcmReferenceCollection Assert.IsFalse(lexDb.LexicalFormIndexRC.Contains(le)); lexDb.LexicalFormIndexRC.Add(le); Assert.IsTrue(lexDb.LexicalFormIndexRC.Contains(le)); lexDb.LexicalFormIndexRC.Remove(le); }
public void CopyTo_OneItemInOneItemListTest() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBookFactory bookFact = servLoc.GetInstance <IScrBookFactory>(); // Setup the source sequence using the scripture books sequence. IScrBook book0 = bookFact.Create(1); IScrBook[] bookArray = new IScrBook[1]; m_scr.ScriptureBooksOS.CopyTo(bookArray, 0); Assert.AreEqual(book0, bookArray[0]); }