public void XNameWithNamespaceConstructor() { XNamespace ns = @"http:\\www.contacts.com\"; XElement contact = new XElement(ns + "contact"); XStreamingElement streamElement = new XStreamingElement(ns + "contact"); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
//[Variation(Priority = 0, Desc = "XStreamingElement in XDocument")] public void XStreamingElementInXDocument() { _xDoc = new XDocument(); XStreamingElement streamElement = new XStreamingElement("contacts", "SomeValue"); _xDoc.Add(streamElement); getFreshStream(); streamElement.Save(_sourceStream); _xDoc.Save(_targetStream); resetStreamPos(); if (!_diff.Compare(_sourceStream, _targetStream)) throw new TestFailedException(""); }
public void XNameAndXElementObjectConstructor() { XElement contact = new XElement("contact", new XElement("phone", "925-555-0134")); XStreamingElement streamElement = new XStreamingElement("contact", contact.Element("phone")); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XStreamingElementInXDocument() { _xDoc = new XDocument(); XStreamingElement streamElement = new XStreamingElement("contacts", "SomeValue"); _xDoc.Add(streamElement); GetFreshStream(); streamElement.Save(_sourceStream); _xDoc.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void IEnumerableLazinessTest2() { XElement name = new XElement("name", "jane"); XElement phone = new XElement("phone", new XAttribute("type", "home"), "925-555-0134"); XElement contact = new XElement("contact", name, phone); // During debug this test will not work correctly since ToString() of // streamElement gets called for displaying the value in debugger local window. XStreamingElement streamElement = new XStreamingElement("contact", GetElements(contact)); GetFreshStream(); contact.Save(_targetStream); _invokeStatus = true; streamElement.Save(_sourceStream); Assert.False(_invokeError, "IEnumerable walked before expected"); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void NestedXStreamingElementPlusIEnumerable() { InputSpace.Contacts(ref _xDoc, ref _xmlDoc); XElement element = new XElement("contacts", new XElement("Element", "Value"), _xDoc.Root.DescendantNodes()); XStreamingElement streamElement = new XStreamingElement("contacts"); streamElement.Add(new XStreamingElement("Element", "Value"), _xDoc.Root.DescendantNodes()); GetFreshStream(); streamElement.Save(_sourceStream); element.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void ModifyOriginalElement() { XElement contact = new XElement( "contact", new XElement("name", "jane"), new XElement("phone", new XAttribute("type", "home"), "925-555-0134")); XStreamingElement streamElement = new XStreamingElement("contact", new object[] { contact.Elements() }); foreach (XElement x in contact.Elements()) { x.Remove(); } GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void SaveWithXmlTextWriter() { XElement contact = new XElement( "contacts", new XElement("contact", "jane"), new XElement("contact", "john")); XStreamingElement streamElement = new XStreamingElement("contacts", contact.Elements()); GetFreshStream(); TextWriter w = new StreamWriter(_sourceStream); streamElement.Save(w); w.Flush(); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XDocInXStreamingElement() { InputSpace.Contacts(ref _xDoc, ref _xmlDoc); XStreamingElement streamElement = new XStreamingElement("Root", _xDoc); Assert.Throws<InvalidOperationException>(() => streamElement.Save(new MemoryStream())); }
public void XCommentInXStreamingElement() { XComment node = new XComment("This is a comment"); XElement element = new XElement("Root", node); XStreamingElement streamElement = new XStreamingElement("Root", node); GetFreshStream(); streamElement.Save(_sourceStream); element.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XCDataInXStreamingElement() { XCData node = new XCData("CDATA Text '%^$#@!&*()'"); XElement element = new XElement("Root", node); XStreamingElement streamElement = new XStreamingElement("Root", node); GetFreshStream(); streamElement.Save(_sourceStream); element.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XmlDeclInXStreamingElement() { XDeclaration node = new XDeclaration("1.0", "utf-8", "yes"); XElement element = new XElement("Root", node); XStreamingElement streamElement = new XStreamingElement("Root", node); GetFreshStream(); streamElement.Save(_sourceStream); element.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XDocTypeInXStreamingElement() { XDocumentType node = new XDocumentType( "DOCTYPE", "note", "SYSTEM", "<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>"); XStreamingElement streamElement = new XStreamingElement("Root", node); Assert.Throws<InvalidOperationException>(() => streamElement.Save(new MemoryStream())); }
public void XNameAndEmptyStringConstructor() { XElement contact = new XElement("contact", ""); XStreamingElement streamElement = new XStreamingElement("contact", ""); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
//[Variation(Priority = 0, Desc = "Constructor - XStreamingElement(XName with Namespace)")] public void XNameWithNamespaceConstructor() { XNamespace ns = @"http:\\www.contacts.com\"; XElement contact = new XElement(ns + "contact"); XStreamingElement streamElement = new XStreamingElement(ns + "contact"); getFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); resetStreamPos(); if (!_diff.Compare(_sourceStream, _targetStream)) throw new TestFailedException(""); }
public void AddIEnumerableOfXNodesPlusAttribute() { InputSpace.Contacts(ref _xDoc, ref _xmlDoc); XAttribute xAttrib = new XAttribute("Attribute", "Value"); XElement element = new XElement("contacts", xAttrib, _xDoc.Root.DescendantNodes()); XStreamingElement streamElement = new XStreamingElement("contacts"); streamElement.Add(xAttrib, _xDoc.Root.DescendantNodes()); GetFreshStream(); streamElement.Save(_sourceStream); element.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void SaveWithNull() { XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134"); Assert.Throws<ArgumentNullException>(() => streamElement.Save((XmlWriter)null)); }
public void XNameAndCollectionObjectConstructor() { XElement contact = new XElement( "contacts", new XElement("contact1", "jane"), new XElement("contact2", "john")); List<Object> list = new List<Object>(); list.Add(contact.Element("contact1")); list.Add(contact.Element("contact2")); XStreamingElement streamElement = new XStreamingElement("contacts", list); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void SaveTwice() { XElement contact = new XElement( "contacts", new XElement("contact", "jane"), new XElement("contact", "john")); XStreamingElement streamElement = new XStreamingElement("contacts", contact.Elements()); GetFreshStream(); streamElement.Save(_sourceStream); _sourceStream.Position = 0; streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XNameAndObjectArrayConstructor() { XElement contact = new XElement( "contact", new XElement("name", "jane"), new XElement("phone", new XAttribute("type", "home"), "925-555-0134")); XStreamingElement streamElement = new XStreamingElement( "contact", new object[] { contact.Element("name"), contact.Element("phone") }); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void NestedXStreamingElement() { XElement name = new XElement("name", "jane"); XElement phone = new XElement("phone", new XAttribute("type", "home"), "925-555-0134"); XElement contact = new XElement("contact", name, new XElement("phones", phone)); XStreamingElement streamElement = new XStreamingElement( "contact", name, new XStreamingElement("phones", phone)); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void AddObject(object content) { XElement contact = new XElement("phone", content); XStreamingElement streamElement = new XStreamingElement("phone"); streamElement.Add(content); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void IEnumerableLazinessTest1() { XElement name = new XElement("name", "jane"); XElement phone = new XElement("phone", new XAttribute("type", "home"), "925-555-0134"); XElement contact = new XElement("contact", name, phone); IEnumerable<XElement> elements = contact.Elements(); name.Remove(); phone.Remove(); XStreamingElement streamElement = new XStreamingElement("contact", new object[] { elements }); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void AddTimeSpanObject() { XElement contact = new XElement("Time", TimeSpan.FromMinutes(12)); XStreamingElement streamElement = new XStreamingElement("Time"); streamElement.Add(TimeSpan.FromMinutes(12)); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XStreamingElementInXElement() { XElement element = new XElement("contacts"); XStreamingElement streamElement = new XStreamingElement("contact", "SomeValue"); element.Add(streamElement); XElement x = element.Element("contact"); GetFreshStream(); streamElement.Save(_sourceStream); x.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void AddAttribute() { XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134"); XStreamingElement streamElement = new XStreamingElement("phone"); streamElement.Add(contact.Attribute("type")); streamElement.Add("925-555-0134"); GetFreshStream(); streamElement.Save(_sourceStream); contact.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void AddIEnumerableOfXNodes() { XElement x = InputSpace.GetElement(100, 3); XElement element = new XElement("root", x.Nodes()); XStreamingElement streamElement = new XStreamingElement("root"); streamElement.Add(x.Nodes()); GetFreshStream(); streamElement.Save(_sourceStream); element.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void AddIEnumerableOfMixedNodes() { XElement element = new XElement("root", GetMixedNodes()); XStreamingElement streamElement = new XStreamingElement("root"); streamElement.Add(GetMixedNodes()); GetFreshStream(); streamElement.Save(_sourceStream); element.Save(_targetStream); ResetStreamPos(); Assert.True(Diff.Compare(_sourceStream, _targetStream)); }
public void XStreamingElementSave_SaveOptions() { string markup = "<e a=\"value\"> <!--comment--> <e2> <![CDATA[cdata]]> </e2> <?pi target?> </e>"; try { XElement e = XElement.Parse(markup, LoadOptions.PreserveWhitespace); XStreamingElement e2 = new XStreamingElement(e.Name, e.Attributes(), e.Nodes()); e2.Save(_fileName, SaveOptions.DisableFormatting); } finally { Assert.True(File.Exists(_fileName)); Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + markup, File.ReadAllText(_fileName)); File.Delete(_fileName); } }
//[Variation(Priority = 0, Desc = "XStreamingElement in XElement")] public void XStreamingElementInXElement() { XElement element = new XElement("contacts"); XStreamingElement streamElement = new XStreamingElement("contact", "SomeValue"); element.Add(streamElement); XElement x = element.Element("contact"); getFreshStream(); streamElement.Save(_sourceStream); x.Save(_targetStream); resetStreamPos(); if (!_diff.Compare(_sourceStream, _targetStream)) throw new TestFailedException(""); }