public void TestLiftImport1() { var messageCapture = new MessageCapture(); MessageBoxUtils.Manager.SetMessageBoxAdapter(messageCapture); SetWritingSystems("es"); var repoEntry = Cache.ServiceLocator.GetInstance<ILexEntryRepository>(); var repoSense = Cache.ServiceLocator.GetInstance<ILexSenseRepository>(); Assert.AreEqual(0, repoEntry.Count); Assert.AreEqual(0, repoSense.Count); var sOrigFile = CreateInputFile(s_LiftData1); CreateDummyFile("pictures", "Desert.jpg"); var myPicRelativePath = Path.Combine("subfolder","MyPic.jpg"); CreateDummyFile("pictures", myPicRelativePath); CreateDummyFile("audio", "Sleep Away.mp3"); CreateDummyFile("audio", "hombre634407358826681759.wav"); CreateDummyFile("audio", "male adult634407358826681760.wav"); CreateDummyFile("others", "SomeFile.txt"); var logFile = TryImport(sOrigFile, 4); File.Delete(sOrigFile); Assert.IsNotNull(logFile); File.Delete(logFile); Assert.AreEqual(4, repoEntry.Count); Assert.AreEqual(4, repoSense.Count); Assert.That(messageCapture.Messages, Has.Count.EqualTo(0), "we should not message about an empty-string ref in <relation>"); ILexEntry entry; Assert.IsTrue(repoEntry.TryGetObject(new Guid("ecfbe958-36a1-4b82-bb69-ca5210355400"), out entry)); Assert.AreEqual(1, entry.SensesOS.Count); var sense0 = entry.SensesOS[0]; Assert.AreEqual(sense0.Guid, new Guid("f63f1ccf-3d50-417e-8024-035d999d48bc")); Assert.IsNotNull(entry.LexemeFormOA); Assert.IsNotNull(entry.LexemeFormOA.MorphTypeRA); Assert.AreEqual("root", entry.LexemeFormOA.MorphTypeRA.Name.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("hombre", entry.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text); Assert.AreEqual("hombre634407358826681759.wav", entry.LexemeFormOA.Form.get_String(m_audioWsCode).Text); Assert.IsNotNull(sense0.MorphoSyntaxAnalysisRA as IMoStemMsa); // ReSharper disable PossibleNullReferenceException Assert.IsNotNull((sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA); Assert.AreEqual("Noun", (sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Name.AnalysisDefaultWritingSystem.Text); // ReSharper restore PossibleNullReferenceException Assert.AreEqual("man", sense0.Gloss.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("male adult human link", sense0.Definition.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("male adult634407358826681760.wav", sense0.Definition.get_String(m_audioWsCode).Text); Assert.AreEqual(2, sense0.SemanticDomainsRC.Count); foreach (var sem in sense0.SemanticDomainsRC) { if (sem.Abbreviation.AnalysisDefaultWritingSystem.Text == "2.6.4.4 Adult") { Assert.AreEqual("2.6.4.4 Adult", sem.Name.AnalysisDefaultWritingSystem.Text); } else { Assert.AreEqual("2.6.5.1 Man", sem.Abbreviation.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("2.6.5.1 Man", sem.Name.AnalysisDefaultWritingSystem.Text); } } Assert.That(sense0.PicturesOS.Count, Is.EqualTo(2)); Assert.That(sense0.PicturesOS[0].PictureFileRA.InternalPath, Is.EqualTo(Path.Combine(FdoFileHelper.ksPicturesDir, "Desert.jpg"))); Assert.That(sense0.PicturesOS[1].PictureFileRA.InternalPath, Is.EqualTo(Path.Combine(FdoFileHelper.ksPicturesDir, myPicRelativePath))); VerifyLinkedFileExists(FdoFileHelper.ksPicturesDir, "Desert.jpg"); VerifyLinkedFileExists(FdoFileHelper.ksPicturesDir, myPicRelativePath); Assert.That(entry.PronunciationsOS.Count, Is.EqualTo(1)); Assert.That(entry.PronunciationsOS[0].MediaFilesOS[0].MediaFileRA.InternalPath, Is.EqualTo(Path.Combine(FdoFileHelper.ksMediaDir, "Sleep Away.mp3"))); VerifyLinkedFileExists(FdoFileHelper.ksMediaDir, "Sleep Away.mp3"); VerifyLinkedFileExists(FdoFileHelper.ksMediaDir, "hombre634407358826681759.wav"); VerifyLinkedFileExists(FdoFileHelper.ksMediaDir, "male adult634407358826681760.wav"); VerifyLinkedFileExists(FdoFileHelper.ksOtherLinkedFilesDir, "SomeFile.txt"); Assert.IsTrue(repoEntry.TryGetObject(new Guid("766aaee2-34b6-4e28-a883-5c2186125a2f"), out entry)); Assert.AreEqual(1, entry.SensesOS.Count); sense0 = entry.SensesOS[0]; Assert.AreEqual(sense0.Guid, new Guid("cf6680cc-faeb-4bd2-90ec-0be5dcdcc6af")); Assert.IsNotNull(entry.LexemeFormOA); Assert.IsNotNull(entry.LexemeFormOA.MorphTypeRA); Assert.AreEqual("root", entry.LexemeFormOA.MorphTypeRA.Name.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("mujer", entry.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text); Assert.IsNotNull(sense0.MorphoSyntaxAnalysisRA as IMoStemMsa); // ReSharper disable PossibleNullReferenceException Assert.IsNotNull((sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA); Assert.AreEqual("Noun", (sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Name.AnalysisDefaultWritingSystem.Text); // ReSharper restore PossibleNullReferenceException Assert.AreEqual("woman", sense0.Gloss.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("female adult human", sense0.Definition.AnalysisDefaultWritingSystem.Text); Assert.AreEqual(2, sense0.SemanticDomainsRC.Count); foreach (var sem in sense0.SemanticDomainsRC) { if (sem.Abbreviation.AnalysisDefaultWritingSystem.Text == "2.6.4.4 Adult") { Assert.AreEqual("2.6.4.4 Adult", sem.Name.AnalysisDefaultWritingSystem.Text); } else { Assert.AreEqual("2.6.5.2 Woman", sem.Abbreviation.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("2.6.5.2 Woman", sem.Name.AnalysisDefaultWritingSystem.Text); } } Assert.IsTrue(repoEntry.TryGetObject(new Guid("1767c76d-e35f-495a-9203-6b31fd82ad72"), out entry)); Assert.AreEqual(1, entry.SensesOS.Count); sense0 = entry.SensesOS[0]; Assert.AreEqual(sense0.Guid, new Guid("04545fa2-e24c-446e-928c-2a13710359b3")); Assert.IsNotNull(entry.LexemeFormOA); Assert.IsNotNull(entry.LexemeFormOA.MorphTypeRA); Assert.AreEqual("stem", entry.LexemeFormOA.MorphTypeRA.Name.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("niño".Normalize(NormalizationForm.FormD), entry.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text); Assert.IsNotNull(sense0.MorphoSyntaxAnalysisRA as IMoStemMsa); // ReSharper disable PossibleNullReferenceException Assert.IsNotNull((sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA); Assert.AreEqual("Noun", (sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Name.AnalysisDefaultWritingSystem.Text); // ReSharper restore PossibleNullReferenceException Assert.AreEqual("boy", sense0.Gloss.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("male human child", sense0.Definition.AnalysisDefaultWritingSystem.Text); Assert.AreEqual(2, sense0.SemanticDomainsRC.Count); foreach (var sem in sense0.SemanticDomainsRC) { if (sem.Abbreviation.AnalysisDefaultWritingSystem.Text == "2.6.4.2 Child") { Assert.AreEqual("2.6.4.2 Child", sem.Name.AnalysisDefaultWritingSystem.Text); } else { Assert.AreEqual("2.6.5.1 Man", sem.Abbreviation.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("2.6.5.1 Man", sem.Name.AnalysisDefaultWritingSystem.Text); } } Assert.IsTrue(repoEntry.TryGetObject(new Guid("185c528d-aeb1-4e32-8aac-2420322020d2"), out entry)); Assert.AreEqual(1, entry.SensesOS.Count); sense0 = entry.SensesOS[0]; Assert.AreEqual(sense0.Guid, new Guid("db9d3790-2f5c-4d99-b9fc-3b21b47fa505")); Assert.IsNotNull(entry.LexemeFormOA); Assert.IsNotNull(entry.LexemeFormOA.MorphTypeRA); Assert.AreEqual("stem", entry.LexemeFormOA.MorphTypeRA.Name.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("niña".Normalize(NormalizationForm.FormD), entry.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text); Assert.IsNotNull(sense0.MorphoSyntaxAnalysisRA as IMoStemMsa); // ReSharper disable PossibleNullReferenceException Assert.IsNotNull((sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA); Assert.AreEqual("Noun", (sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Name.AnalysisDefaultWritingSystem.Text); // ReSharper restore PossibleNullReferenceException Assert.AreEqual("girl", sense0.Gloss.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("female human child", sense0.Definition.AnalysisDefaultWritingSystem.Text); Assert.AreEqual(2, sense0.SemanticDomainsRC.Count); foreach (var sem in sense0.SemanticDomainsRC) { if (sem.Abbreviation.AnalysisDefaultWritingSystem.Text == "2.6.4.2 Child") { Assert.AreEqual("2.6.4.2 Child", sem.Name.AnalysisDefaultWritingSystem.Text); } else { Assert.AreEqual("2.6.5.2 Woman", sem.Abbreviation.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("2.6.5.2 Woman", sem.Name.AnalysisDefaultWritingSystem.Text); } } }
public void TestLiftImport4() { // Setup var messageCapture = new MessageCapture(); MessageBoxUtils.Manager.SetMessageBoxAdapter(messageCapture); // ReSharper disable InconsistentNaming const string LINE_SEPARATOR = "\u2028"; var s_newLine = Environment.NewLine; var ccharsNL = s_newLine.Length; const string s_cr = "\r"; const string s_lf = "\n"; // ReSharper restore InconsistentNaming SetWritingSystems("es"); var repoEntry = Cache.ServiceLocator.GetInstance<ILexEntryRepository>(); var repoSense = Cache.ServiceLocator.GetInstance<ILexSenseRepository>(); Assert.AreEqual(0, repoEntry.Count); Assert.AreEqual(0, repoSense.Count); // Put data in LIFT string const int idxModifiedLine = 19; // "<form lang=\"en\"><text>male{0}adult{1}human</text></form>", var fmtString = s_LiftData4[idxModifiedLine]; s_LiftData4[idxModifiedLine] = String.Format(fmtString, s_newLine, s_cr, s_lf); var sOrigFile = CreateInputFile(s_LiftData4); var logFile = TryImport(sOrigFile, 1); File.Delete(sOrigFile); Assert.IsNotNull(logFile); File.Delete(logFile); Assert.AreEqual(1, repoEntry.Count); Assert.AreEqual(1, repoSense.Count); Assert.That(messageCapture.Messages[0], Is.StringContaining("nonsence_object_ID"), "inability to link up bad ref should be reported in message box"); ILexEntry entry; Assert.IsTrue(repoEntry.TryGetObject(new Guid("ecfbe958-36a1-4b82-bb69-ca5210355400"), out entry)); Assert.AreEqual(1, entry.SensesOS.Count); Assert.AreEqual(entry.SensesOS[0].Guid, new Guid("f63f1ccf-3d50-417e-8024-035d999d48bc")); Assert.IsNotNull(entry.LexemeFormOA); Assert.IsNotNull(entry.LexemeFormOA.MorphTypeRA); Assert.AreEqual("root", entry.LexemeFormOA.MorphTypeRA.Name.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("hombre", entry.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text); var actualDefn = entry.SensesOS[0].Definition.AnalysisDefaultWritingSystem.Text; var expectedXmlDefn = String.Format(fmtString, LINE_SEPARATOR, LINE_SEPARATOR, LINE_SEPARATOR); var doc = new XmlDocument(); doc.LoadXml(expectedXmlDefn); var expectedDefn = doc.SelectSingleNode("form/text"); Assert.IsNotNull(expectedDefn); Assert.AreEqual(expectedDefn.InnerText, actualDefn, "Mismatched definition."); }