private SandboxBase SetupSandbox(Func <AnalysisOccurrence> createDataForSandbox) { var occurrence = createDataForSandbox(); var lineChoices = InterlinLineChoices.DefaultChoices(Cache.LangProject, Cache.DefaultVernWs, Cache.DefaultAnalWs); var sandbox = new SandboxBase(Cache, null, null, lineChoices, occurrence.Analysis.Hvo); sandbox.MakeRoot(); return(sandbox); }
public void ComboHandler_CreateCoreMorphItemBasedOnSandboxCurrentState_DeletedSense_DoesNotThrow() { // Make an entry with a morph and a sense with no MSA. var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); var morph = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create(); entry.LexemeFormOA = morph; morph.Form.SetVernacularDefaultWritingSystem("kick"); morph.MorphTypeRA = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphRoot); // Set up first sense var sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense); sense.Gloss.SetAnalysisDefaultWritingSystem("silly"); // Make an analysis from that MSA. var wf = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); wf.Form.SetVernacularDefaultWritingSystem("kick"); var wa = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create(); wf.AnalysesOC.Add(wa); var mb = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create(); wa.MorphBundlesOS.Add(mb); mb.SenseRA = sense; mb.MorphRA = morph; // Set up second sense var sense2 = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense2); sense2.Gloss.SetAnalysisDefaultWritingSystem("problem"); // Make a sandbox and sut InterlinLineChoices lineChoices = InterlinLineChoices.DefaultChoices(Cache.LangProject, Cache.DefaultVernWs, Cache.DefaultAnalWs, InterlinLineChoices.InterlinMode.Analyze); using (var sandbox = new SandboxBase(Cache, null, null, lineChoices, wa.Hvo)) { var mockList = new MockComboHandler(); sandbox.m_ComboHandler = mockList; // Merge the first sense into the second (invalidating analysis and sandbox cache) using (var handler = GetComboHandler(sandbox, InterlinLineChoices.kflidLexEntries, 0)) { // wipe out the sense that the morph bundle was based on. sense2.MergeObject(sense, true); Assert.AreEqual(entry.SensesOS[0], sense2); Assert.DoesNotThrow(() => { // ReSharper disable once UnusedVariable - Assignment is SUT var i = handler.IndexOfCurrentItem; }); } } }
public void EntryHandler_NeedSelectSame_SelectSenseWhenAnalysisHasNoPos_ReturnsTrue() { // Make an entry with a morph and a sense with no MSA. var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); var morph = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create(); entry.LexemeFormOA = morph; morph.Form.SetVernacularDefaultWritingSystem("kick"); morph.MorphTypeRA = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphRoot); var sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense); sense.Gloss.SetAnalysisDefaultWritingSystem("strike with foot"); // Make an analysis from that MSA. var wf = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); wf.Form.SetVernacularDefaultWritingSystem("kick"); var wa = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create(); wf.AnalysesOC.Add(wa); var mb = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create(); wa.MorphBundlesOS.Add(mb); mb.SenseRA = sense; mb.MorphRA = morph; // Make a sandbox and sut InterlinLineChoices lineChoices = InterlinLineChoices.DefaultChoices(Cache.LangProject, Cache.DefaultVernWs, Cache.DefaultAnalWs, InterlinLineChoices.InterlinMode.Analyze); using (var sut = new SandboxBase.IhMissingEntry(null)) { using (var sandbox = new SandboxBase(Cache, m_mediator, m_propertyTable, null, lineChoices, wa.Hvo)) { sut.SetSandboxForTesting(sandbox); var mockList = MockRepository.GenerateMock <IComboList>(); sut.SetComboListForTesting(mockList); sut.SetMorphForTesting(0); sut.LoadMorphItems(); Assert.That(sut.NeedSelectSame(), Is.True); } // But if it already has an MSA it is not true. var msa = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create(); entry.MorphoSyntaxAnalysesOC.Add(msa); sense.MorphoSyntaxAnalysisRA = msa; mb.MsaRA = msa; using (var sandbox = new SandboxBase(Cache, m_mediator, m_propertyTable, null, lineChoices, wa.Hvo)) { sut.SetSandboxForTesting(sandbox); Assert.That(sut.NeedSelectSame(), Is.False); } } }
public override void TestSetup() { base.TestSetup(); InterlinLineChoices lineChoices = InterlinLineChoices.DefaultChoices(Cache.LangProject, Cache.DefaultVernWs, Cache.DefaultAnalWs, InterlinLineChoices.InterlinMode.Gloss); m_sandbox = new AddWordsToLexiconTests.SandboxForTests(Cache, lineChoices); }
public override void TestSetup() { base.TestSetup(); InterlinLineChoices lineChoices = InterlinLineChoices.DefaultChoices(Cache.LangProject, Cache.DefaultVernWs, Cache.DefaultAnalWs, InterlinLineChoices.InterlinMode. GlossAddWordsToLexicon); m_mediator = new Mediator(); m_propertyTable = new PropertyTable(m_mediator); m_sandbox = new SandboxForTests(Cache, m_mediator, m_propertyTable, lineChoices); }
public override void Initialize() { CheckDisposed(); base.Initialize(); m_text1 = Cache.LangProject.TextsOC.Add(new Text()); m_text1.ContentsOA = new StText(); m_text1.ContentsOA.ParagraphsOS.Append(new StTxtPara()); (m_text1.ContentsOA.ParagraphsOS[0] as StTxtPara).Contents.UnderlyingTsString = StringUtils.MakeTss("xxxa xxxb xxxc xxxd xxxe, xxxa xxxb.", Cache.DefaultVernWs); bool fDidParse; ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse); InterlinLineChoices lineChoices = InterlinLineChoices.DefaultChoices(0, Cache.DefaultAnalWs, Cache.LangProject, InterlinLineChoices.InterlinMode.GlossAddWordsToLexicon); m_sandbox = new SandboxForTests(Cache, lineChoices); }
/// <summary> /// </summary> /// <param name="lineConfigPropName">the key used to store/restore line configuration settings.</param> /// <param name="mode"></param> /// <returns></returns> public InterlinLineChoices SetupLineChoices(string lineConfigPropName, InterlinLineChoices.InterlinMode mode) { ConfigPropName = lineConfigPropName; InterlinLineChoices lineChoices; if (!TryRestoreLineChoices(out lineChoices)) { if (ForEditing) { lineChoices = EditableInterlinLineChoices.DefaultChoices(m_cache.LangProject, WritingSystemServices.kwsVernInParagraph, WritingSystemServices.kwsAnal); lineChoices.Mode = mode; if (mode == InterlinLineChoices.InterlinMode.Gloss || mode == InterlinLineChoices.InterlinMode.GlossAddWordsToLexicon) { lineChoices.SetStandardGlossState(); } else { lineChoices.SetStandardState(); } } else { lineChoices = InterlinLineChoices.DefaultChoices(m_cache.LangProject, WritingSystemServices.kwsVernInParagraph, WritingSystemServices.kwsAnal, mode); } } else if (ForEditing) { // just in case this hasn't been set for restored lines lineChoices.Mode = mode; } LineChoices = lineChoices; return(LineChoices); }
public void EstablishDefaultEntry_Empty_Basic() { using (var mediator = new Mediator()) using (var propertyTable = new PropertyTable(mediator)) using (var testSandbox = new AddWordsToLexiconTests.SandboxForTests(Cache, mediator, propertyTable, InterlinLineChoices.DefaultChoices(Cache.LangProject, Cache.DefaultVernWs, Cache.DefaultAnalWs))) { var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); var morph = Cache.ServiceLocator.GetInstance <IMoAffixAllomorphFactory>().Create(); entry.LexemeFormOA = morph; morph.Form.set_String(Cache.DefaultVernWs, "here"); morph.MorphTypeRA = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphSuffix); testSandbox.RawWordform = TsStringUtils.MakeString("here", Cache.DefaultVernWs); Assert.DoesNotThrow(() => testSandbox.EstablishDefaultEntry(morph.Hvo, "here", morph.MorphTypeRA, false)); Assert.DoesNotThrow(() => testSandbox.EstablishDefaultEntry(morph.Hvo, "notHere", morph.MorphTypeRA, false)); } }