예제 #1
0
 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));
 }
예제 #2
0
 //[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("");
 }
예제 #3
0
 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));
 }
예제 #4
0
 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));
 }
예제 #5
0
 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));
 }
예제 #6
0
 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));
 }
예제 #7
0
 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));
 }
예제 #8
0
 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));
 }
예제 #9
0
 public void XDocInXStreamingElement()
 {
     InputSpace.Contacts(ref _xDoc, ref _xmlDoc);
     XStreamingElement streamElement = new XStreamingElement("Root", _xDoc);
     Assert.Throws<InvalidOperationException>(() => streamElement.Save(new MemoryStream()));
 }
예제 #10
0
 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));
 }
예제 #11
0
 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));
 }
예제 #12
0
 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));
 }
예제 #13
0
        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()));
        }
예제 #14
0
 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));
 }
예제 #15
0
 //[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("");
 }
예제 #16
0
 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));
 }
예제 #17
0
 public void SaveWithNull()
 {
     XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
     Assert.Throws<ArgumentNullException>(() => streamElement.Save((XmlWriter)null));
 }
예제 #18
0
 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));
 }
예제 #19
0
 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));
 }
예제 #20
0
 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));
 }
예제 #21
0
 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));
 }
예제 #22
0
 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));
 }
예제 #23
0
 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));
 }
예제 #24
0
 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));
 }
예제 #25
0
 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));
 }
예제 #26
0
 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));
 }
예제 #27
0
 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));
 }
예제 #28
0
 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));
 }
예제 #29
0
 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);
     }
 }
예제 #30
0
 //[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("");
 }