Example #1
0
		public void Entry_EntryHasIdWithInvalidXMLCharacters_CharactersEscaped()
		{
			const string expected = "id=\"<>&"'\"";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var entry = session.CreateItem();
				// technically the only invalid characters in an attribute are & < and " (when surrounded by ")
				entry.Id = "<>&\"\'";
				//_lexEntryRepository.SaveItem(entry);
				session.LiftWriter.Add(entry);
				string result = session.OutputString();
				Assert.IsTrue(result.Contains(expected));
			}
		}
Example #2
0
		public void ExampleSentenceWithTranslation()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var example = new LexExampleSentence();
				example.Sentence["blue"] = "ocean's eleven";
				example.Sentence["red"] = "red sunset tonight";
				example.Translation["green"] = "blah blah";
				session.LiftWriter.Add(example);
				var outPut = session.OutputString();
				AssertEqualsCanonicalString(
					"<example><form lang=\"blue\"><text>ocean's eleven</text></form><form lang=\"red\"><text>red sunset tonight</text></form><translation><form lang=\"green\"><text>blah blah</text></form></translation></example>", outPut);
			}
		}
Example #3
0
		public void BlankExample()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				session.LiftWriter.Add(new LexExampleSentence());
				AssertEqualsCanonicalString("<example />", session.OutputString());
			}
		}
Example #4
0
		public void BlankSense()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var sense = new LexSense();
				session.LiftWriter.Add(sense);
				AssertEqualsCanonicalString(
					String.Format("<sense id=\"{0}\" />", sense.GetOrCreateId()),
					session.OutputString()
				);
			}
		}
Example #5
0
		public void Add_MultiTextWithMalFormedXML_IsExportedText()
		{
			const string expected =
				"<form\r\n\tlang=\"de\">\r\n\t<text>This &lt;span href=\"reference\"&gt;is not well formed&lt;span&gt; XML!</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is not well formed<span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Example #6
0
		public void Add_TextWithSpanAndMeaningfulWhiteSpace_FormattingAndWhitespaceIsUntouched()
		{
			const string formattedText = "\rThis's <span href=\"reference\">\n is a\t\t\n\r\t span</span> with annoying whitespace!\r\n";
			const string expected = "<form\r\n\tlang=\"de\">\r\n\t<text>" + formattedText + "</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", formattedText);
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Example #7
0
		public void Add_MalformedXmlWithWithScaryUnicodeChar_IsExportedAsText()
		{
			const string expected = "<form\r\n\tlang=\"de\">\r\n\t<text>This &lt;span href=\"reference\"&gt;is not well &#x1F; formed&lt;span&gt; XML!</text>\r\n</form>";
			//  1F is the character for "Segment Separator" and you can insert it by right-clicking in windows
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is not well \u001F formed<span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Example #8
0
		public void AttributesWithProblematicCharacters()
		{
			const string expected = "lang=\"x&quot;y\">";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var sense = new LexSense();
				sense.Gloss["x\"y"] = "test";
				session.LiftWriter.Add(sense);
				session.LiftWriter.End();
				string result = session.OutputString();
				Assert.IsTrue(result.Contains(expected));
			}
		}
Example #9
0
		public void Add_MultiTextWithWellFormedXMLAndScaryCharacter_IsExportedAsXML()
		{
			const string expected =
			"<form\r\n\tlang=\"de\">\r\n\t<text>This <span href=\"reference\">is well &#x1F; formed</span> XML!</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is well \u001F formed</span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Example #10
0
		public void Add_MultiTextWithScaryUnicodeChar_IsExported()
		{
			const string expected =
				"<form\r\n\tlang=\"de\">\r\n\t<text>This has a segment separator character at the end&#x1F;</text>\r\n</form>";
			//  1F is the character for "Segment Separator" and you can insert it by right-clicking in windows
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This has a segment separator character at the end\u001F");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Example #11
0
		public void AddRelationTarget_SenseWithSynonymRelations()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var sense = new LexSense();
				sense.AddRelationTarget("synonym", "one");
				sense.AddRelationTarget("synonym", "two");
				sense.AddRelationTarget("antonym", "bee");

				session.LiftWriter.Add(sense);
				string result = session.OutputString();
				AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath(
					"/sense/relation[@type='synonym' and @ref='one']"
				);
				AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath(
					"/sense/relation[@type='synonym' and @ref='two']"
				);
				AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath(
					"/sense/relation[@type='antonym' and @ref='bee']"
				);
			}
		}
Example #12
0
		public void SenseWithSynonymRelations()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var sense = new LexSense();

				var synonymRelationType = new LexRelationType(
					"synonym",
					LexRelationType.Multiplicities.Many,
					LexRelationType.TargetTypes.Sense
				);

				var antonymRelationType = new LexRelationType(
					"antonym",
					LexRelationType.Multiplicities.Many,
					LexRelationType.TargetTypes.Sense
				);

				var relations = new LexRelationCollection();
				sense.Properties.Add(new KeyValuePair<string, IPalasoDataObjectProperty>("relations", relations));

				relations.Relations.Add(new LexRelation(synonymRelationType.ID, "one", sense));
				relations.Relations.Add(new LexRelation(synonymRelationType.ID, "two", sense));
				relations.Relations.Add(new LexRelation(antonymRelationType.ID, "bee", sense));

				session.LiftWriter.Add(sense);
				string result = session.OutputString();
				AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath(
					"/sense/relation[@type='synonym' and @ref='one']"
				);
				AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath(
					"/sense/relation[@type='synonym' and @ref='two']"
				);
				AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath(
					"/sense/relation[@type='antonym' and @ref='bee']"
				);
			}
		}
Example #13
0
		public void SenseWithExample()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var sense = new LexSense();
				var example = new LexExampleSentence();
				example.Sentence["red"] = "red sunset tonight";
				sense.ExampleSentences.Add(example);
				session.LiftWriter.Add(sense);
				string result = session.OutputString();
				AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath(
					"/sense/example/form[@lang='red']/text[text()='red sunset tonight']"
				);
			}
		}
Example #14
0
		public void MultiText()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var text = new MultiText();
				text["blue"] = "ocean";
				text["red"] = "sunset";
				session.LiftWriter.AddMultitextForms(null, text);
				AssertEqualsCanonicalString(
					"<form lang=\"blue\"><text>ocean</text></form><form lang=\"red\"><text>sunset</text></form>",
					session.OutputString()
				);
			}
		}
Example #15
0
		public void GlossWithProblematicCharacters()
		{
			const string expected = "<text>LessThan&lt;GreaterThan&gt;Ampersan&amp;</text>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var sense = new LexSense();
				sense.Gloss["blue"] = "LessThan<GreaterThan>Ampersan&";
				session.LiftWriter.Add(sense);
				string result = session.OutputString();
				Assert.IsTrue(result.Contains(expected));
			}
		}