public void Extensibility_SerializeWithRegisteredExtensions() { GenericElement child1; GenericElement child2; XliffDocument document; IExtensible extensible; IExtension extension; Segment segment; Source source; Unit unit; // Document extensions. document = new XliffDocument("en-us"); extensible = document; extension = new GenericExtension("extension"); extensible.Extensions.Add(extension); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 1")); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 2")); extension = new GenericExtension("extension"); extensible.Extensions.Add(extension); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 3")); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 4")); // File extensions. document.Files.Add(new File("f1")); extensible = document.Files[0]; extension = new GenericExtension("extension"); extensible.Extensions.Add(extension); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 5")); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 6")); extension = new GenericExtension("extension"); extensible.Extensions.Add(extension); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 7")); extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 8")); // Child 0. child1 = new GenericElement(); child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 9"); child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 10"); extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1"), child1)); child2 = new GenericElement(); child2.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute3", "attribute 11"); child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element2"), child2)); source = new Source(); source.Language = "de-de"; source.Space = Preservation.Preserve; child2.AddChild(new ElementInfo(new XmlNameInfo("source"), source)); // Child 1. child1 = new GenericElement(); child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 12"); child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 13"); extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1"), child1)); child2 = new GenericElement(); child2.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute3", "attribute 14"); child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace1, "element2"), child2)); child2.AddChild(new ElementInfo(new XmlNameInfo((string)null), new PlainText("text 1"))); // Child 2. child1 = new GenericElement(); child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 15"); child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 16"); child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 17"); extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1"), child1)); child2 = new GenericElement(); child2.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 18"); child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace2, "element1"), child2)); child2.AddChild(new ElementInfo(new XmlNameInfo((string)null), new PlainText("text 3"))); // Child 3. child1 = new GenericElement(); child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 19"); child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 20"); extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element1"), child1)); child2 = new GenericElement(); child2.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute3", "attribute 21"); child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace2, "element2"), child2)); child2.AddChild(new ElementInfo(new XmlNameInfo("target"), new Target())); // Child 4. child1 = new GenericElement(); child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 22"); child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 23"); extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element1"), child1)); child2 = new GenericElement(); child2.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute3", "attribute 24"); child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace2, "element2"), child2)); child2.AddChild(new ElementInfo(new XmlNameInfo((string)null), new PlainText("text 2"))); // Unit information. unit = new Unit("u1"); document.Files[0].Containers.Add(unit); extensible = unit; extension = new GenericExtension("extension"); extensible.Extensions.Add(extension); // Segment information. segment = new Segment("s1"); segment.Source = new Source(); segment.State = TranslationState.Initial; unit.Resources.Add(segment); Assert.AreEqual( TestUtilities.GetFileContents(TestData.DocumentWithExtensions), TestUtilities.GetDocumentContents(document, " "), "Document contents are incorrect."); }
public void XliffWriter_Source() { Source source; Unit unit; string actualValue; this._document.Files.Add(new File()); unit = new Unit(); this._document.Files[0].Containers.Add(unit); unit.Resources.Add(new Segment()); source = new Source(); unit.Resources[0].Source = source; Console.WriteLine("Test with default values."); actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.SourceWithDefaultValues), actualValue); Console.WriteLine("Test with empty values."); source.Language = String.Empty; actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.SourceWithEmptyValues), actualValue); Console.WriteLine("Test with valid values."); source.Language = "en-us"; source.Space = Preservation.Preserve; source.Text.Add(new CodePoint(1)); actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.SourceWithValidValues), actualValue); }
/// <summary> /// Creates a source with every element and attribute. /// </summary> /// <param name="noteId">The Id of a note to reference.</param> /// <returns>The created source.</returns> private Source CreateSource(string noteId) { IIdentifiable identifiable1; IIdentifiable identifiable2; Source result; result = new Source(); result.Text.Add(new CodePoint(24)); identifiable1 = this.CreatePh(null); result.Text.Add((ResourceStringContent)identifiable1); result.Text.Add(this.CreatePh(identifiable1.Id)); identifiable1 = this.CreatePc(null); result.Text.Add((ResourceStringContent)identifiable1); result.Text.Add(this.CreatePc(identifiable1.Id)); identifiable1 = this.CreateSc(null); result.Text.Add((ResourceStringContent)identifiable1); identifiable2 = this.CreateEc(null, identifiable1.Id); result.Text.Add((ResourceStringContent)identifiable2); result.Text.Add(this.CreateEc(null, null)); identifiable1 = this.CreateSc(identifiable1.Id); result.Text.Add((ResourceStringContent)identifiable1); result.Text.Add(this.CreateEc(identifiable2.Id, identifiable1.Id)); result.Text.Add(new PlainText("text")); result.Text.Add(new CDataTag("cdata text")); result.Text.Add(new CommentTag("comment text")); result.Text.Add(new ProcessingInstructionTag("instruction", "instruction text")); result.Text.Add(this.CreateMrk(noteId)); identifiable1 = this.CreateSm(noteId); result.Text.Add((ResourceStringContent)identifiable1); result.Text.Add(this.CreateEm(identifiable1.Id)); return result; }