public void XliffElement_AddChildElementsToList() { TestXliffElement element; List <ElementInfo> list; List <XliffElement> children; element = new TestXliffElement(); children = new List <XliffElement>(); Console.WriteLine("Test with null."); list = null; element.CallAddChildElementsToList(null, ref list); Assert.IsNull(list, "List is incorrect."); Console.WriteLine("Test with empty enumeration."); list = null; element.CallAddChildElementsToList(new XliffElement[] { }, ref list); Assert.IsNull(list, "List is incorrect."); Console.WriteLine("Test with invalid enumeration."); children.Add(new Target()); list = null; try { element.CallAddChildElementsToList(children, ref list); Assert.Fail("Expected KeyNotFoundException to be thrown."); } catch (KeyNotFoundException) { } Console.WriteLine("Test with valid enumeration."); children.Clear(); children.Add(new File()); children.Add(new File()); children.Add(new Source()); list = null; element.CallAddChildElementsToList(children, ref list); Assert.AreEqual(3, list.Count, "List count is incorrect."); Assert.AreEqual(ElementNames.File, list[0].LocalName, "LocalName[0] is incorrect."); Assert.AreEqual(ElementNames.File, list[1].LocalName, "LocalName[1] is incorrect."); Assert.AreEqual(ElementNames.Source, list[2].LocalName, "LocalName[2] is incorrect."); Assert.AreEqual(children[0], list[0].Element, "Element[0] is incorrect."); Assert.AreEqual(children[1], list[1].Element, "Element[1] is incorrect."); Assert.AreEqual(children[2], list[2].Element, "Element[2] is incorrect."); Console.WriteLine("Test with full list."); list = new List <ElementInfo>(); list.Add(new ElementInfo(new XmlNameInfo("name"), new TestXliffElement())); children.Clear(); children.Add(new File()); element.CallAddChildElementsToList(children, ref list); Assert.AreEqual(2, list.Count, "List count is incorrect."); Assert.AreEqual("name", list[0].LocalName, "LocalName[0] is incorrect."); Assert.AreEqual(ElementNames.File, list[1].LocalName, "Key[1] is incorrect."); Assert.AreEqual(children[0], list[1].Element, "Value[1] is incorrect."); }
public void XliffElement_AddChildElementsToList() { TestXliffElement element; List<ElementInfo> list; List<XliffElement> children; element = new TestXliffElement(); children = new List<XliffElement>(); Console.WriteLine("Test with null."); list = null; element.CallAddChildElementsToList(null, ref list); Assert.IsNull(list, "List is incorrect."); Console.WriteLine("Test with empty enumeration."); list = null; element.CallAddChildElementsToList(new XliffElement[] { }, ref list); Assert.IsNull(list, "List is incorrect."); Console.WriteLine("Test with invalid enumeration."); children.Add(new Target()); list = null; try { element.CallAddChildElementsToList(children, ref list); Assert.Fail("Expected KeyNotFoundException to be thrown."); } catch (KeyNotFoundException) { } Console.WriteLine("Test with valid enumeration."); children.Clear(); children.Add(new File()); children.Add(new File()); children.Add(new Source()); list = null; element.CallAddChildElementsToList(children, ref list); Assert.AreEqual(3, list.Count, "List count is incorrect."); Assert.AreEqual(ElementNames.File, list[0].LocalName, "LocalName[0] is incorrect."); Assert.AreEqual(ElementNames.File, list[1].LocalName, "LocalName[1] is incorrect."); Assert.AreEqual(ElementNames.Source, list[2].LocalName, "LocalName[2] is incorrect."); Assert.AreEqual(children[0], list[0].Element, "Element[0] is incorrect."); Assert.AreEqual(children[1], list[1].Element, "Element[1] is incorrect."); Assert.AreEqual(children[2], list[2].Element, "Element[2] is incorrect."); Console.WriteLine("Test with full list."); list = new List<ElementInfo>(); list.Add(new ElementInfo(new XmlNameInfo("name"), new TestXliffElement())); children.Clear(); children.Add(new File()); element.CallAddChildElementsToList(children, ref list); Assert.AreEqual(2, list.Count, "List count is incorrect."); Assert.AreEqual("name", list[0].LocalName, "LocalName[0] is incorrect."); Assert.AreEqual(ElementNames.File, list[1].LocalName, "Key[1] is incorrect."); Assert.AreEqual(children[0], list[1].Element, "Value[1] is incorrect."); }
public void XliffElement_Parent() { TestXliffElement element; TestXliffElement parent; Console.WriteLine("Test default value."); element = new TestXliffElement(); Assert.IsNull(element.Parent, "Parent is not null."); Console.WriteLine("Test with parent."); parent = new TestXliffElement(); element.Parent = parent; Assert.AreEqual(parent, element.Parent, "Parent was not set."); }
public void XliffElement_GetSetPropertyValue() { TestAncestorXliffElement ancestor; TestXliffElement element; TestXliffElement parent; const string propertyName = "Property"; element = new TestXliffElement(); Console.WriteLine("Test with default value."); Assert.AreEqual(100, element.CallGetPropertyValue(propertyName), "Value is incorrect."); Console.WriteLine("Test with new value."); element.CallSetPropertyValue(200, propertyName); Assert.AreEqual(200, element.CallGetPropertyValue(propertyName), "Value is incorrect."); Console.WriteLine("Test with parent inherited value."); parent = new TestXliffElement(); parent.ParentInheritedProperty = 302; element.Parent = parent; Assert.AreEqual(parent.ParentInheritedProperty, element.CallGetPropertyValue("ParentInheritedProperty"), "Value is incorrect."); Console.WriteLine("Test with ancestor inherited value."); parent = new TestXliffElement(); element.Parent = parent; ancestor = new TestAncestorXliffElement(); ancestor.AncestorInheritedProperty = 500; parent.Parent = ancestor; Assert.AreEqual(ancestor.AncestorInheritedProperty, element.CallGetPropertyValue("AncestorInheritedProperty"), "Value is incorrect."); Console.WriteLine("Test with ancestor inherited value with a different name."); parent = new TestXliffElement(); element.Parent = parent; ancestor = new TestAncestorXliffElement(); ancestor.Property = 600; parent.Parent = ancestor; Assert.AreEqual(ancestor.Property, element.CallGetPropertyValue("AncestorInheritedPropertyDifferentName"), "Value is incorrect."); Console.WriteLine("Test with callback inherited value."); Assert.AreEqual(40, element.CallGetPropertyValue("CallbackInheritedProperty"), "Value is incorrect."); }
public void XliffElement_SelectableAncestor() { TestXliffElement element; TestXliffElement parent; Console.WriteLine("Test default value."); element = new TestXliffElement(); Assert.IsNull(element.SelectableAncestor, "SelectableAncestor is not null."); Console.WriteLine("Test with parent that is not selectable."); parent = new TestXliffElement(); element.Parent = parent; Assert.IsNull(element.SelectableAncestor, "SelectableAncestor is not null."); Console.WriteLine("Test with parent that is selectable."); parent.Parent = new File(); Assert.AreEqual(parent.Parent, element.SelectableAncestor, "SelectableAncestor is incorrect."); }
public void XliffElement_SelectElement() { File file; Group group; Unit unit; Segment segment; Ignorable ignorable; TestXliffElement element; element = new TestXliffElement(); element.Document = new XliffDocument(); Console.WriteLine("Test with no items."); Assert.IsNull(element.CallSelectElement("#/file")); Console.WriteLine("Test with file items."); file = new File("file"); element.Document.Files.Add(file); Assert.AreEqual(file, element.CallSelectElement("#/f=file")); Console.WriteLine("Test with relative path to file item."); Assert.AreEqual(file, element.Document.Select("#f=file")); Console.WriteLine("Test with many items."); group = new Group("group"); file.Containers.Add(new Group()); file.Containers.Add(group); unit = new Unit("unit"); group.Containers.Add(unit); group.Containers.Add(new Group()); group.Containers.Add(new Unit()); Assert.AreEqual(unit, element.CallSelectElement("#/f=file/g=group/u=unit")); Console.WriteLine("Test with segment."); segment = new Segment("segment"); unit.Resources.Add(segment); Assert.AreEqual(segment, element.CallSelectElement("#/f=file/g=group/u=unit/segment")); Console.WriteLine("Test with relative path to segment."); Assert.AreEqual(segment, group.Select("#u=unit/segment")); Console.WriteLine("Test with invalid relative path to segment."); try { group.Select("u=unit/segment"); Assert.Fail("Expected ArgumentException to be thrown."); } catch (ArgumentException) { } Console.WriteLine("Test with ignorable."); ignorable = new Ignorable("ignorable"); unit.Resources.Add(ignorable); Assert.AreEqual(ignorable, element.CallSelectElement("#/f=file/g=group/u=unit/ignorable")); Console.WriteLine("Test with data."); unit.OriginalData = new OriginalData(); unit.OriginalData.AddData("data", "text"); Assert.AreEqual(unit.OriginalData.DataElements[0], element.CallSelectElement("#/f=file/g=group/u=unit/d=data")); Console.WriteLine("Test with note."); file.AddNote("note").Id = "note"; Assert.AreEqual(file.Notes[0], element.CallSelectElement("#/f=file/n=note")); // // This test should still work even though it's an invalid document. // Console.WriteLine("Test with duplicate names."); element.Document.Files.Add(new File("file")); Assert.AreEqual(file, element.CallSelectElement("#/f=file"), "Found wrong item."); Console.WriteLine("Test with bogus names."); Assert.IsNull(element.CallSelectElement("#/f=foo"), "Item should not have been found."); Console.WriteLine("Test with bogus path."); Assert.IsNull(element.CallSelectElement("#/blah"), "Item should not have been found."); Console.WriteLine("Test with empty string."); // This returns null because SelectElement is called directly which doesn't search for the leading '#'. Assert.IsNull(element.CallSelectElement(String.Empty)); Console.WriteLine("Test with empty path."); Assert.IsNull(element.CallSelectElement("/"), "Item should not have been found."); Console.WriteLine("Test with inline element."); segment.Source = new Source(); segment.Source.Text.Add(new MarkedSpan("ms1")); Assert.AreEqual(segment.Source.Text[0], element.CallSelectElement("#/f=file/g=group/u=unit/ms1"), "Item should have been found."); Console.WriteLine("Test with inline element."); segment.Target = new Target(); segment.Target.Text.Add(new MarkedSpan("ms2")); Assert.AreEqual(segment.Target.Text[0], element.CallSelectElement("#/f=file/g=group/u=unit/t=ms2"), "Item should have been found."); Console.WriteLine("Test with relative path to inline element from file."); Assert.AreEqual(segment.Target.Text[0], file.Select("#g=group/u=unit/t=ms2"), "Item should have been found."); Console.WriteLine("Test with relative path to inline element from unit."); Assert.AreEqual(segment.Target.Text[0], unit.Select("#t=ms2"), "Item should have been found."); }