/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
C# | 1580 lines | 1417 code | 111 blank | 52 comment | 1 complexity | 1f2c876a8a1d8577ac0440734d251460 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- //
- // Authors:
- // Atsushi Enomoto
- //
- // Copyright 2007 Novell (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Xml;
- using System.Xml.Linq;
- using NUnit.Framework;
- namespace MonoTests.System.Xml.Linq
- {
- [TestFixture]
- public class XElementTest
- {
- [Test] // xml declaration is skipped.
- public void LoadWithXmldecl ()
- {
- string xml = "<?xml version='1.0'?><root />";
- XElement.Load (new StringReader (xml));
- }
- [Test]
- public void Load1 ()
- {
- string xml = "<root><foo/></root>";
- XElement el = XElement.Load (new StringReader (xml));
- XElement first = el.FirstNode as XElement;
- Assert.IsNotNull (first, "#1");
- Assert.IsTrue (el.LastNode is XElement, "#2");
- Assert.IsNull (el.NextNode, "#3");
- Assert.IsNull (el.PreviousNode, "#4");
- Assert.AreEqual (1, new List<XNode> (el.Nodes ()).Count, "#5");
- Assert.AreEqual (el, first.Parent, "#6");
- Assert.AreEqual (first, el.LastNode, "#7");
- Assert.AreEqual ("root", el.Name.ToString (), "#8");
- Assert.AreEqual ("foo", first.Name.ToString (), "#9");
- Assert.IsFalse (el.Attributes ().GetEnumerator ().MoveNext (), "#10");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void LoadInvalid ()
- {
- string xml = "text";
- XmlReaderSettings s = new XmlReaderSettings ();
- s.ConformanceLevel = ConformanceLevel.Fragment;
- XElement.Load (XmlReader.Create (new StringReader (xml), s));
- }
- [Test]
- public void PrecedingWhitespaces ()
- {
- string xml = " <root/>";
- XmlReaderSettings s = new XmlReaderSettings ();
- s.ConformanceLevel = ConformanceLevel.Fragment;
- XElement.Load (XmlReader.Create (new StringReader (xml), s));
- }
- [Test]
- public void PrecedingWhitespaces2 ()
- {
- string xml = " <root/>";
- XmlReaderSettings s = new XmlReaderSettings ();
- s.ConformanceLevel = ConformanceLevel.Fragment;
- XmlReader r = XmlReader.Create (new StringReader (xml), s);
- r.Read (); // at whitespace
- XElement.Load (r);
- }
- [Test]
- public void Load2 ()
- {
- string xml = "<root>foo</root>";
- XElement el = XElement.Load (new StringReader (xml));
- XText first = el.FirstNode as XText;
- Assert.IsNotNull (first, "#1");
- Assert.IsTrue (el.LastNode is XText, "#2");
- Assert.AreEqual (1, new List<XNode> (el.Nodes ()).Count, "#3");
- Assert.AreEqual (el, first.Parent, "#4");
- Assert.AreEqual (first, el.LastNode, "#5");
- Assert.AreEqual ("foo", first.Value, "#6");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddDocumentTypeToElement ()
- {
- XElement el = new XElement (XName.Get ("foo"));
- el.Add (new XDocumentType ("foo", null, null, null));
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- [Category ("NotDotNet")]
- public void AddXDeclarationToElement ()
- {
- XElement el = new XElement (XName.Get ("foo"));
- // LAMESPEC: in .NET, XDeclaration is not treated as
- // invalid, and converted to a string without error.
- el.Add (new XDeclaration ("1.0", null, null));
- }
- [Test]
- public void SetAttribute ()
- {
- XElement el = new XElement (XName.Get ("foo"));
- el.SetAttributeValue (XName.Get ("a1"), "v1");
- XAttribute a = el.FirstAttribute;
- Assert.IsNotNull (a, "#1-1");
- Assert.AreEqual (el, a.Parent, "#1-2");
- Assert.IsNotNull (el.LastAttribute, "#1-3");
- Assert.AreEqual (a, el.LastAttribute, "#1-4");
- Assert.AreEqual ("a1", a.Name.LocalName, "#1-5");
- Assert.AreEqual ("v1", a.Value, "#1-6");
- Assert.IsNull (a.PreviousAttribute, "#1-7");
- Assert.IsNull (a.NextAttribute, "#1-8");
- el.SetAttributeValue (XName.Get ("a2"), "v2");
- Assert.IsFalse (el.FirstAttribute == el.LastAttribute, "#2-1");
- Assert.AreEqual ("a2", el.LastAttribute.Name.LocalName, "#2-2");
- el.SetAttributeValue (XName.Get ("a1"), "v3");
- XAttribute b = el.FirstAttribute;
- Assert.IsNotNull (b, "#2-3");
- Assert.IsNotNull (el.LastAttribute, "#2-4");
- Assert.AreEqual ("a1", b.Name.LocalName, "#2-5");
- Assert.AreEqual ("v3", b.Value, "#2-6");
- Assert.AreEqual (a, b, "#2-7");
- XAttribute c = el.LastAttribute;
- Assert.AreEqual (a, c.PreviousAttribute, "#2-8");
- a.Remove ();
- Assert.IsNull (a.Parent, "#3-1");
- Assert.IsNull (a.PreviousAttribute, "#3-2");
- Assert.IsNull (a.NextAttribute, "#3-3");
- Assert.IsNull (c.PreviousAttribute, "#3-4");
- Assert.IsNull (c.NextAttribute, "#3-5");
- el.RemoveAttributes ();
- Assert.IsFalse (el.HasAttributes, "#4-1");
- Assert.IsNull (b.Parent, "#4-2");
- Assert.IsNull (c.Parent, "#4-3");
- Assert.IsNull (el.FirstAttribute, "#4-4");
- Assert.IsNull (el.LastAttribute, "#4-5");
- }
- [Test]
- public void AddAfterSelf ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- el.FirstNode.AddAfterSelf ("text");
- XText t = el.FirstNode.NextNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("text", t.Value, "#2");
- XElement bar = t.NextNode as XElement;
- Assert.IsNotNull (bar, "#3");
- Assert.AreEqual ("bar", bar.Name.LocalName, "#4");
- }
- [Test]
- public void AddAfterSelfList ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- el.FirstNode.AddAfterSelf (new XText [] {
- new XText ("t1"),
- new XText ("t2"),
- new XText ("t3")});
- XText t = el.FirstNode.NextNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("t1", t.Value, "#2");
- Assert.AreEqual ("t2", ((XText) t.NextNode).Value, "#3");
- Assert.AreEqual ("t3", ((XText) t.NextNode.NextNode).Value, "#4");
- XElement bar = t.NextNode.NextNode.NextNode as XElement;
- Assert.IsNotNull (bar, "#5");
- Assert.AreEqual ("bar", bar.Name.LocalName, "#6");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddAfterSelfAttribute ()
- {
- var el = new XElement ("root", new XElement ("child"));
- var el2 = el.FirstNode as XElement;
- el2.AddAfterSelf (new XAttribute ("foo", "bar"));
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddAfterSelfXDocument ()
- {
- var el = new XElement ("root", new XElement ("child"));
- var el2 = el.FirstNode as XElement;
- el2.AddAfterSelf (new XDocument ());
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- [Category ("NotDotNet")]
- [Category ("NotWorking")]
- // LAMESPEC: there is no reason to not reject XDeclaration while it rejects XDocument.
- public void AddAfterSelfXDeclaration ()
- {
- var el = new XElement ("root", new XElement ("child"));
- var el2 = el.FirstNode as XElement;
- el2.AddAfterSelf (new XDeclaration ("1.0", null, null));
- }
- [Test]
- public void AddAfterSelfCollection ()
- {
- var el = new XElement ("root", new XElement ("child"));
- el.FirstNode.AddAfterSelf (new List<XElement> (new XElement [] {new XElement ("foo"), new XElement ("bar")}));
- Assert.AreEqual ("<root><child /><foo /><bar /></root>", el.ToString (SaveOptions.DisableFormatting), "#1");
- Assert.AreEqual ("bar", (el.LastNode as XElement).Name.LocalName, "#2");
- }
- [Test]
- public void AddAfterSelfJoinsStringAfterText ()
- {
- var el = XElement.Parse ("<foo>text1</foo>");
- el.LastNode.AddAfterSelf ("text2");
- el.LastNode.AddAfterSelf (new XText ("text3"));
- IEnumerator<XNode> e = el.Nodes ().GetEnumerator ();
- Assert.IsTrue (e.MoveNext (), "#1");
- Assert.AreEqual ("text1text2", e.Current.ToString (), "#2");
- Assert.IsTrue (e.MoveNext (), "#3");
- Assert.AreEqual ("text3", e.Current.ToString (), "#4");
- Assert.IsFalse (e.MoveNext (), "#5");
- }
- [Test]
- public void AddBeforeSelf ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- el.FirstNode.AddBeforeSelf ("text");
- XText t = el.FirstNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("text", t.Value, "#2");
- XElement foo = t.NextNode as XElement;
- Assert.IsNotNull (foo, "#3");
- Assert.AreEqual ("foo", foo.Name.LocalName, "#4");
- }
- [Test]
- public void AddBeforeSelfList ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- el.FirstNode.AddBeforeSelf (new XText [] {
- new XText ("t1"),
- new XText ("t2"),
- new XText ("t3")});
- XText t = el.FirstNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("t1", t.Value, "#2");
- Assert.AreEqual ("t2", ((XText) t.NextNode).Value, "#3");
- Assert.AreEqual ("t3", ((XText) t.NextNode.NextNode).Value, "#4");
- XElement foo = t.NextNode.NextNode.NextNode as XElement;
- Assert.IsNotNull (foo, "#5");
- Assert.AreEqual ("foo", foo.Name.LocalName, "#6");
- }
- [Test]
- public void AddBeforeSelfList2 ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- el.FirstNode.AddBeforeSelf ("t1", "t2", "t3");
- XText t = el.FirstNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("t1t2t3", t.Value, "#2");
- XElement foo = t.NextNode as XElement;
- Assert.IsNotNull (foo, "#3");
- Assert.AreEqual ("foo", foo.Name.LocalName, "#4");
- }
- [Test]
- public void AddJoinsStringAfterText ()
- {
- var el = XElement.Parse ("<foo>text1</foo>");
- el.Add ("text2");
- el.Add (new XText ("text3"));
- IEnumerator<XNode> e = el.Nodes ().GetEnumerator ();
- Assert.IsTrue (e.MoveNext (), "#1");
- Assert.AreEqual ("text1text2", e.Current.ToString (), "#2");
- Assert.IsTrue (e.MoveNext (), "#3");
- Assert.AreEqual ("text3", e.Current.ToString (), "#4");
- Assert.IsFalse (e.MoveNext (), "#5");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void AddDuplicateAttribute ()
- {
- var el = new XElement ("foo",
- new XAttribute ("bar", "baz"));
- el.Add (new XAttribute ("bar", "baz"));
- }
- [Test]
- public void ReplaceWith ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- XNode fc = el.FirstNode;
- fc.ReplaceWith ("test");
- XText t = el.FirstNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("test", t.Value, "#2");
- }
- [Test]
- public void ReplaceAll ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- el.ReplaceAll ("test");
- XText t = el.FirstNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("test", t.Value, "#2");
- Assert.AreEqual (1, new List<XNode> (el.Nodes ()).Count, "#3");
- }
- [Test]
- public void ReplaceAllList ()
- {
- XElement el = XElement.Parse ("<root><foo/><bar/></root>");
- el.ReplaceAll (
- new XText ("test1"),
- new XText ("test2"),
- new XText ("test3"));
- XText t = el.FirstNode as XText;
- Assert.IsNotNull (t, "#1");
- Assert.AreEqual ("test1", t.Value, "#2");
- t = el.LastNode as XText;
- Assert.IsNotNull (t, "#3");
- Assert.AreEqual ("test3", t.Value, "#4");
- Assert.AreEqual (3, new List<XNode> (el.Nodes ()).Count, "#5");
- }
- [Test]
- public void ReplaceAttributes ()
- {
- XElement el = XElement.Parse ("<root x='y'><foo a='b'/></root>");
- Assert.IsTrue (el.Attributes ().GetEnumerator ().MoveNext (), "#0");
- el.ReplaceAttributes ("test");
- Assert.IsTrue (el.FirstNode is XElement, "#1");
- Assert.IsTrue (el.LastNode is XText, "#2");
- Assert.IsFalse (el.Attributes ().GetEnumerator ().MoveNext (), "#3");
- }
- [Test]
- public void GetDefaultNamespace ()
- {
- XElement el = XElement.Parse ("<root xmlns='urn:foo'><foo><xxx/></foo><x:bar xmlns:x='urn:bar'><yyy/></x:bar><baz xmlns=''><zzz /></baz></root>");
- XNamespace ns1 = XNamespace.Get ("urn:foo");
- Assert.AreEqual (ns1, el.GetDefaultNamespace (), "#1");
- XElement foo = (XElement) el.FirstNode;
- Assert.AreEqual (ns1, foo.GetDefaultNamespace (), "#2");
- Assert.AreEqual (ns1, ((XElement) foo.FirstNode).GetDefaultNamespace (), "#3");
- XElement bar = (XElement) foo.NextNode;
- Assert.AreEqual (ns1, bar.GetDefaultNamespace (), "#4");
- Assert.AreEqual (ns1, ((XElement) bar.FirstNode).GetDefaultNamespace (), "#5");
- XElement baz = (XElement) bar.NextNode;
- Assert.AreEqual (XNamespace.Get (String.Empty), baz.GetDefaultNamespace (), "#6");
- Assert.AreEqual (XNamespace.Get (String.Empty), ((XElement) baz.FirstNode).GetDefaultNamespace (), "#7");
- }
- [Test]
- public void GetPrefixNamespace ()
- {
- XElement el = XElement.Parse ("<x:root xmlns:x='urn:foo'><foo><xxx/></foo><x:bar xmlns:x='urn:bar'><yyy/></x:bar><baz xmlns=''><zzz /></baz></x:root>");
- XNamespace ns1 = XNamespace.Get ("urn:foo");
- XNamespace ns2 = XNamespace.Get ("urn:bar");
- Assert.AreEqual (ns1, el.GetNamespaceOfPrefix ("x"), "#1-1");
- Assert.AreEqual ("x", el.GetPrefixOfNamespace (ns1), "#1-2");
- XElement foo = (XElement) el.FirstNode;
- Assert.AreEqual (ns1, foo.GetNamespaceOfPrefix ("x"), "#2-1");
- Assert.AreEqual ("x", foo.GetPrefixOfNamespace (ns1), "#2-2");
- Assert.AreEqual (ns1, ((XElement) foo.FirstNode).GetNamespaceOfPrefix ("x"), "#3-1");
- Assert.AreEqual ("x", ((XElement) foo.FirstNode).GetPrefixOfNamespace (ns1), "#3-2");
- XElement bar = (XElement) foo.NextNode;
- Assert.AreEqual (ns2, bar.GetNamespaceOfPrefix ("x"), "#4-1");
- Assert.AreEqual ("x", bar.GetPrefixOfNamespace (ns2), "#4-2");
- Assert.AreEqual (null, bar.GetPrefixOfNamespace (ns1), "#4-3");
- Assert.AreEqual (ns2, ((XElement) bar.FirstNode).GetNamespaceOfPrefix ("x"), "#5-1");
- Assert.AreEqual ("x", ((XElement) bar.FirstNode).GetPrefixOfNamespace (ns2), "#5-2");
- Assert.AreEqual (null, ((XElement) bar.FirstNode).GetPrefixOfNamespace (ns1), "#5-3");
- }
- #pragma warning disable 219
- [Test]
- public void CastNulls ()
- {
- const XElement a = null;
- Assert.AreEqual (null, (bool?) a, "bool?");
- Assert.AreEqual (null, (DateTime?) a, "DateTime?");
- Assert.AreEqual (null, (DateTimeOffset?) a, "DateTimeOffset?");
- Assert.AreEqual (null, (decimal?) a, "decimal?");
- Assert.AreEqual (null, (double?) a, "double?");
- Assert.AreEqual (null, (float?) a, "float?");
- Assert.AreEqual (null, (Guid?) a, "Guid?");
- Assert.AreEqual (null, (int?) a, "int?");
- Assert.AreEqual (null, (long?) a, "long?");
- Assert.AreEqual (null, (uint?) a, "uint?");
- Assert.AreEqual (null, (ulong?) a, "ulong?");
- Assert.AreEqual (null, (TimeSpan?) a, "TimeSpan?");
- Assert.AreEqual (null, (string) a, "string");
- AssertThrows<ArgumentNullException> (() => { bool z = (bool) a; }, "bool");
- AssertThrows<ArgumentNullException> (() => { DateTime z = (DateTime) a; }, "DateTime");
- AssertThrows<ArgumentNullException> (() => { DateTimeOffset z = (DateTimeOffset) a; }, "DateTimeOffset");
- AssertThrows<ArgumentNullException> (() => { decimal z = (decimal) a; }, "decimal");
- AssertThrows<ArgumentNullException> (() => { double z = (double) a; }, "double");
- AssertThrows<ArgumentNullException> (() => { float z = (float) a; }, "float");
- AssertThrows<ArgumentNullException> (() => { Guid z = (Guid) a; }, "Guid");
- AssertThrows<ArgumentNullException> (() => { int z = (int) a; }, "int");
- AssertThrows<ArgumentNullException> (() => { long z = (long) a; }, "long");
- AssertThrows<ArgumentNullException> (() => { uint z = (uint) a; }, "uint");
- AssertThrows<ArgumentNullException> (() => { ulong z = (ulong) a; }, "ulong");
- AssertThrows<ArgumentNullException> (() => { TimeSpan z = (TimeSpan) a; }, "TimeSpan");
- }
- /// <remarks>
- /// Provides functionality similar to Assert.Throws that is available on newer versions of NUnit.
- /// </remarks>
- private static T AssertThrows<T> (Action code, string message, params object[] args) where T : Exception
- {
- Exception actual = null;
- try {
- code ();
- } catch (Exception exception) {
- actual = exception;
- }
- Assert.That (actual, new NUnit.Framework.Constraints.ExactTypeConstraint (typeof (T)), message, args);
- return (T) actual;
- }
- [Test]
- public void CastEmpties ()
- {
- XElement a = new XElement ("a");
- // Verify expected "cloning" and "empty" behaviour as prerequisites
- Assert.IsTrue (a.IsEmpty, "#1-1");
- Assert.IsTrue (new XElement (a).IsEmpty, "#1-2");
- Assert.AreEqual (String.Empty, a.Value, "#2-1");
- Assert.AreEqual (String.Empty, new XElement (a).Value, "#2-2");
- Assert.AreNotSame (a, new XElement (a), "#3-1");
- Assert.AreEqual (a.ToString (), new XElement (a).ToString (), "#3-2");
- Assert.AreEqual ("<a />", a.ToString (), "#3-3");
- Assert.AreEqual (a.ToString (), new XElement ("a", null).ToString (), "#3-4");
- // Execute the primary assertions of this test
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (a); }, "bool?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (a); }, "DateTime?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (a); }, "DateTimeOffset?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (a); }, "decimal?");
- AssertThrows<FormatException> (() => { double? z = (double?) new XElement (a); }, "double?");
- AssertThrows<FormatException> (() => { float? z = (float?) new XElement (a); }, "float?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (a); }, "Guid?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (a); }, "int?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (a); }, "long?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (a); }, "uint?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (a); }, "ulong?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (a); }, "TimeSpan?");
- Assert.AreEqual (String.Empty, (string) new XElement (a), "string");
- AssertThrows<FormatException> (() => { bool z = (bool) new XElement (a); }, "bool");
- AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XElement (a); }, "DateTime");
- AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XElement (a); }, "DateTimeOffset");
- AssertThrows<FormatException> (() => { decimal z = (decimal) new XElement (a); }, "decimal");
- AssertThrows<FormatException> (() => { double z = (double) new XElement (a); }, "double");
- AssertThrows<FormatException> (() => { float z = (float) new XElement (a); }, "float");
- AssertThrows<FormatException> (() => { Guid z = (Guid) new XElement (a); }, "Guid");
- AssertThrows<FormatException> (() => { int z = (int) new XElement (a); }, "int");
- AssertThrows<FormatException> (() => { long z = (long) new XElement (a); }, "long");
- AssertThrows<FormatException> (() => { uint z = (uint) new XElement (a); }, "uint");
- AssertThrows<FormatException> (() => { ulong z = (ulong) new XElement (a); }, "ulong");
- AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XElement (a); }, "TimeSpan");
- }
- [Test]
- public void CastBlanks ()
- {
- XElement a = new XElement ("a", String.Empty);
- XElement b = new XElement ("b", new XCData (string.Empty));
- // Verify expected "cloning" and "blank" behaviour as prerequisites
- Assert.IsFalse (a.IsEmpty, "#1-1a");
- Assert.IsFalse (b.IsEmpty, "#1-1b");
- Assert.IsFalse (new XElement (a).IsEmpty, "#1-2a");
- Assert.IsFalse (new XElement (b).IsEmpty, "#1-2b");
- Assert.AreEqual (String.Empty, a.Value, "#2-1a");
- Assert.AreEqual (String.Empty, b.Value, "#2-1b");
- Assert.AreEqual (String.Empty, new XElement (a).Value, "#2-2a");
- Assert.AreEqual (String.Empty, new XElement (b).Value, "#2-2b");
- Assert.AreNotSame (a, new XElement (a), "#3-1a");
- Assert.AreNotSame (b, new XElement (b), "#3-1b");
- Assert.AreEqual (a.ToString (), new XElement (a).ToString (), "#3-2a");
- Assert.AreEqual (b.ToString (), new XElement (b).ToString (), "#3-2b");
- Assert.AreEqual ("<a></a>", a.ToString (), "#3-3a");
- Assert.AreEqual ("<b><![CDATA[]]></b>", b.ToString (), "#3-3b");
- Assert.AreEqual (a.ToString (), new XElement ("a", "").ToString (), "#3-4a");
- Assert.AreEqual (b.ToString (), new XElement ("b", new XCData ("")).ToString (), "#3-4b");
- // Execute the primary assertions of this test
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (a); }, "a:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (b); }, "b:bool?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (a); }, "a:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (b); }, "b:DateTime?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (a); }, "a:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (b); }, "b:DateTimeOffset?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (a); }, "a:decimal?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (b); }, "b:decimal?");
- AssertThrows<FormatException> (() => { double? z = (double?) new XElement (a); }, "a:double?");
- AssertThrows<FormatException> (() => { double? z = (double?) new XElement (b); }, "b:double?");
- AssertThrows<FormatException> (() => { float? z = (float?) new XElement (a); }, "a:float?");
- AssertThrows<FormatException> (() => { float? z = (float?) new XElement (b); }, "b:float?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (a); }, "a:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (b); }, "b:Guid?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (a); }, "a:int?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (b); }, "b:int?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (a); }, "a:long?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (b); }, "b:long?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (a); }, "a:uint?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (b); }, "b:uint?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (a); }, "a:ulong?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (b); }, "b:ulong?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (a); }, "a:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (b); }, "b:TimeSpan?");
- Assert.AreEqual (String.Empty, (string) new XElement (a), "a:string");
- Assert.AreEqual (String.Empty, (string) new XElement (b), "b:string");
- AssertThrows<FormatException> (() => { bool z = (bool) new XElement (a); }, "a:bool");
- AssertThrows<FormatException> (() => { bool z = (bool) new XElement (b); }, "b:bool");
- AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XElement (a); }, "a:DateTime");
- AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XElement (b); }, "b:DateTime");
- AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XElement (a); }, "a:DateTimeOffset");
- AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XElement (b); }, "b:DateTimeOffset");
- AssertThrows<FormatException> (() => { decimal z = (decimal) new XElement (a); }, "a:decimal");
- AssertThrows<FormatException> (() => { decimal z = (decimal) new XElement (b); }, "b:decimal");
- AssertThrows<FormatException> (() => { double z = (double) new XElement (a); }, "a:double");
- AssertThrows<FormatException> (() => { double z = (double) new XElement (b); }, "b:double");
- AssertThrows<FormatException> (() => { float z = (float) new XElement (a); }, "a:float");
- AssertThrows<FormatException> (() => { float z = (float) new XElement (b); }, "b:float");
- AssertThrows<FormatException> (() => { Guid z = (Guid) new XElement (a); }, "a:Guid");
- AssertThrows<FormatException> (() => { Guid z = (Guid) new XElement (b); }, "b:Guid");
- AssertThrows<FormatException> (() => { int z = (int) new XElement (a); }, "a:int");
- AssertThrows<FormatException> (() => { int z = (int) new XElement (b); }, "b:int");
- AssertThrows<FormatException> (() => { long z = (long) new XElement (a); }, "a:long");
- AssertThrows<FormatException> (() => { long z = (long) new XElement (b); }, "b:long");
- AssertThrows<FormatException> (() => { uint z = (uint) new XElement (a); }, "a:uint");
- AssertThrows<FormatException> (() => { uint z = (uint) new XElement (b); }, "b:uint");
- AssertThrows<FormatException> (() => { ulong z = (ulong) new XElement (a); }, "a:ulong");
- AssertThrows<FormatException> (() => { ulong z = (ulong) new XElement (b); }, "b:ulong");
- AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XElement (a); }, "a:TimeSpan");
- AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XElement (b); }, "b:TimeSpan");
- }
- [Test]
- public void CastSpaces ()
- {
- XElement a = new XElement ("a", " ");
- XElement b = new XElement ("b", new XCData (" "));
- // Verify expected "cloning" and "space" behaviour as prerequisites
- Assert.IsFalse (a.IsEmpty, "#1-1a");
- Assert.IsFalse (b.IsEmpty, "#1-1b");
- Assert.IsFalse (new XElement (a).IsEmpty, "#1-2a");
- Assert.IsFalse (new XElement (b).IsEmpty, "#1-2b");
- Assert.AreEqual (" ", a.Value, "#2-1a");
- Assert.AreEqual (" ", b.Value, "#2-1b");
- Assert.AreEqual (" ", new XElement (a).Value, "#2-2a");
- Assert.AreEqual (" ", new XElement (b).Value, "#2-2b");
- Assert.AreNotSame (a, new XElement (a), "#3-1a");
- Assert.AreNotSame (b, new XElement (b), "#3-1b");
- Assert.AreEqual (a.ToString (), new XElement (a).ToString (), "#3-2a");
- Assert.AreEqual (b.ToString (), new XElement (b).ToString (), "#3-2b");
- Assert.AreEqual ("<a> </a>", a.ToString (), "#3-3a");
- Assert.AreEqual ("<b><![CDATA[ ]]></b>", b.ToString (), "#3-3b");
- Assert.AreEqual (a.ToString (), new XElement ("a", ' ').ToString (), "#3-4");
- // Execute the primary assertions of this test
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (a); }, "a:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (b); }, "b:bool?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (a); }, "a:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (b); }, "b:DateTime?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (a); }, "a:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (b); }, "b:DateTimeOffset?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (a); }, "a:decimal?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (b); }, "b:decimal?");
- AssertThrows<FormatException> (() => { double? z = (double?) new XElement (a); }, "a:double?");
- AssertThrows<FormatException> (() => { double? z = (double?) new XElement (b); }, "b:double?");
- AssertThrows<FormatException> (() => { float? z = (float?) new XElement (a); }, "a:float?");
- AssertThrows<FormatException> (() => { float? z = (float?) new XElement (b); }, "b:float?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (a); }, "a:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (b); }, "b:Guid?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (a); }, "a:int?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (b); }, "b:int?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (a); }, "a:long?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (b); }, "b:long?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (a); }, "a:uint?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (b); }, "b:uint?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (a); }, "a:ulong?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (b); }, "b:ulong?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (a); }, "a:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (b); }, "b:TimeSpan?");
- Assert.AreEqual (" ", (string) new XElement (a), "a:string");
- Assert.AreEqual (" ", (string) new XElement (b), "b:string");
- AssertThrows<FormatException> (() => { bool z = (bool) new XElement (a); }, "a:bool");
- AssertThrows<FormatException> (() => { bool z = (bool) new XElement (b); }, "b:bool");
- AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XElement (a); }, "a:DateTime");
- AssertThrows<FormatException> (() => { DateTime z = (DateTime) new XElement (b); }, "b:DateTime");
- AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XElement (a); }, "a:DateTimeOffset");
- AssertThrows<FormatException> (() => { DateTimeOffset z = (DateTimeOffset) new XElement (b); }, "b:DateTimeOffset");
- AssertThrows<FormatException> (() => { decimal z = (decimal) new XElement (a); }, "a:decimal");
- AssertThrows<FormatException> (() => { decimal z = (decimal) new XElement (b); }, "b:decimal");
- AssertThrows<FormatException> (() => { double z = (double) new XElement (a); }, "a:double");
- AssertThrows<FormatException> (() => { double z = (double) new XElement (b); }, "b:double");
- AssertThrows<FormatException> (() => { float z = (float) new XElement (a); }, "a:float");
- AssertThrows<FormatException> (() => { float z = (float) new XElement (b); }, "b:float");
- AssertThrows<FormatException> (() => { Guid z = (Guid) new XElement (a); }, "a:Guid");
- AssertThrows<FormatException> (() => { Guid z = (Guid) new XElement (b); }, "b:Guid");
- AssertThrows<FormatException> (() => { int z = (int) new XElement (a); }, "a:int");
- AssertThrows<FormatException> (() => { int z = (int) new XElement (b); }, "b:int");
- AssertThrows<FormatException> (() => { long z = (long) new XElement (a); }, "a:long");
- AssertThrows<FormatException> (() => { long z = (long) new XElement (b); }, "b:long");
- AssertThrows<FormatException> (() => { uint z = (uint) new XElement (a); }, "a:uint");
- AssertThrows<FormatException> (() => { uint z = (uint) new XElement (b); }, "b:uint");
- AssertThrows<FormatException> (() => { ulong z = (ulong) new XElement (a); }, "a:ulong");
- AssertThrows<FormatException> (() => { ulong z = (ulong) new XElement (b); }, "b:ulong");
- AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XElement (a); }, "a:TimeSpan");
- AssertThrows<FormatException> (() => { TimeSpan z = (TimeSpan) new XElement (b); }, "b:TimeSpan");
- }
- [Test]
- public void CastNumbers ()
- {
- XElement a = new XElement ("a", "7");
- XElement b = new XElement ("b", new XCData (" 42 "));
- XElement c = new XElement ("c", " \r\n 13 \t ");
- XElement d = new XElement ("d", -101);
- XElement o = new XElement ("o", "0");
- XElement l = new XElement ("l", "1");
- XElement I = new XElement ("I", "INF");
- XElement i = new XElement ("i", " Infinity ");
- XElement M = new XElement ("M", " -INF ");
- XElement m = new XElement ("m", "-Infinity");
- XElement n = new XElement ("n", "\t NaN ");
- // Verify expected "cloning" and basic conversion behaviour as prerequisites
- Assert.IsFalse (a.IsEmpty, "#1-1");
- Assert.IsFalse (new XElement (b).IsEmpty, "#1-2");
- Assert.AreEqual (" \r\n 13 \t ", c.Value, "#2-1");
- Assert.AreEqual ("-101", new XElement (d).Value, "#2-2");
- Assert.AreNotSame (o, new XElement (o), "#3-1");
- Assert.AreEqual (l.ToString (), new XElement (l).ToString (), "#3-2");
- Assert.AreEqual ("<a>7</a>", a.ToString (), "#3-3a");
- Assert.AreEqual ("<b><![CDATA[ 42 ]]></b>", b.ToString (), "#3-3b");
- Assert.AreEqual ("<c> \r\n 13 \t </c>", c.ToString (), "#3-3c");
- Assert.AreEqual ("<d>-101</d>", d.ToString (), "#3-3d");
- Assert.AreEqual ("<o>0</o>", new XElement ("o", 0.0).ToString (), "#3-3o");
- Assert.AreEqual ("<l>1</l>", new XElement ("l", 1.0f).ToString (), "#3-3l");
- Assert.AreEqual ("<n>NaN</n>", new XElement ("n", double.NaN).ToString (), "#3-3n");
- Assert.AreEqual (a.ToString (), new XElement ("a", '7').ToString (), "#3-4a");
- Assert.AreEqual (d.ToString (), new XElement ("d", "-101").ToString (), "#3-4d");
- Assert.AreEqual (o.ToString (), new XElement ("o", 0L).ToString (), "#3-4o");
- Assert.AreEqual (l.ToString (), new XElement ("l", 1m).ToString (), "#3-4l");
- // Execute the primary assertions of this test
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (a); }, "a:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (b); }, "b:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (c); }, "c:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (d); }, "d:bool?");
- Assert.IsNotNull ((bool?) new XElement (o), "o:bool?:null");
- Assert.AreEqual (false, ((bool?) new XElement (o)).Value, "o:bool?:value");
- Assert.IsNotNull ((bool?) new XElement (l), "l:bool?:null");
- Assert.AreEqual (true, ((bool?) new XElement (l)).Value, "l:bool?:value");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (I); }, "I:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (i); }, "i:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (M); }, "M:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (m); }, "m:bool?");
- AssertThrows<FormatException> (() => { bool? z = (bool?) new XElement (n); }, "n:bool?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (a); }, "a:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (b); }, "b:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (c); }, "c:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (d); }, "d:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (o); }, "o:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (l); }, "l:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (I); }, "I:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (i); }, "i:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (M); }, "M:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (m); }, "m:DateTime?");
- AssertThrows<FormatException> (() => { DateTime? z = (DateTime?) new XElement (n); }, "n:DateTime?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (a); }, "a:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (b); }, "b:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (c); }, "c:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (d); }, "d:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (o); }, "o:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (l); }, "l:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (I); }, "I:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (i); }, "i:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (M); }, "M:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (m); }, "m:DateTimeOffset?");
- AssertThrows<FormatException> (() => { DateTimeOffset? z = (DateTimeOffset?) new XElement (n); }, "n:DateTimeOffset?");
- Assert.IsNotNull ((decimal?) new XElement (a), "a:decimal?:null");
- Assert.AreEqual (7m, ((decimal?) new XElement (a)).Value, "a:decimal?:value");
- Assert.IsNotNull ((decimal?) new XElement (b), "b:decimal?:null");
- Assert.AreEqual (42m, ((decimal?) new XElement (b)).Value, "b:decimal?:value");
- Assert.IsNotNull ((decimal?) new XElement (c), "c:decimal?:null");
- Assert.AreEqual (13m, ((decimal?) new XElement (c)).Value, "c:decimal?:value");
- Assert.IsNotNull ((decimal?) new XElement (d), "d:decimal?:null");
- Assert.AreEqual (-101m, ((decimal?) new XElement (d)).Value, "d:decimal?:value");
- Assert.IsNotNull ((decimal?) new XElement (o), "o:decimal?:null");
- Assert.AreEqual (0m, ((decimal?) new XElement (o)).Value, "o:decimal?:value");
- Assert.IsNotNull ((decimal?) new XElement (l), "l:decimal?:null");
- Assert.AreEqual (1m, ((decimal?) new XElement (l)).Value, "l:decimal?:value");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (I); }, "I:decimal?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (i); }, "i:decimal?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (M); }, "M:decimal?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (m); }, "m:decimal?");
- AssertThrows<FormatException> (() => { decimal? z = (decimal?) new XElement (n); }, "n:decimal?");
- Assert.IsNotNull ((double?) new XElement (a), "a:double?:null");
- Assert.AreEqual (7d, ((double?) new XElement (a)).Value, "a:double?:value");
- Assert.IsNotNull ((double?) new XElement (b), "b:double?:null");
- Assert.AreEqual (42d, ((double?) new XElement (b)).Value, "b:double?:value");
- Assert.IsNotNull ((double?) new XElement (c), "c:double?:null");
- Assert.AreEqual (13d, ((double?) new XElement (c)).Value, "c:double?:value");
- Assert.IsNotNull ((double?) new XElement (d), "d:double?:null");
- Assert.AreEqual (-101d, ((double?) new XElement (d)).Value, "d:double?:value");
- Assert.IsNotNull ((double?) new XElement (o), "o:double?:null");
- Assert.AreEqual (0d, ((double?) new XElement (o)).Value, "o:double?:value");
- Assert.IsNotNull ((double?) new XElement (l), "l:double?:null");
- Assert.AreEqual (1d, ((double?) new XElement (l)).Value, "l:double?:value");
- Assert.IsNotNull ((double?) new XElement (I), "I:double?:null");
- Assert.AreEqual (double.PositiveInfinity, ((double?) new XElement (I)).Value, "I:double?:value");
- Assert.IsNotNull ((double?) new XElement (i), "i:double?:null");
- Assert.AreEqual (double.PositiveInfinity, ((double?) new XElement (i)).Value, "i:double?:value");
- Assert.IsNotNull ((double?) new XElement (M), "M:double?:null");
- Assert.AreEqual (double.NegativeInfinity, ((double?) new XElement (M)).Value, "M:double?:value");
- Assert.IsNotNull ((double?) new XElement (m), "m:double?:null");
- Assert.AreEqual (double.NegativeInfinity, ((double?) new XElement (m)).Value, "m:double?:value");
- Assert.IsNotNull ((double?) new XElement (n), "n:double?:null");
- Assert.IsNaN (((double?) new XElement (n)).Value, "n:double?:value");
- Assert.IsNotNull ((float?) new XElement (a), "a:float?:null");
- Assert.AreEqual (7f, ((float?) new XElement (a)).Value, "a:float?:value");
- Assert.IsNotNull ((float?) new XElement (b), "b:float?:null");
- Assert.AreEqual (42f, ((float?) new XElement (b)).Value, "b:float?:value");
- Assert.IsNotNull ((float?) new XElement (c), "c:float?:null");
- Assert.AreEqual (13f, ((float?) new XElement (c)).Value, "c:float?:value");
- Assert.IsNotNull ((float?) new XElement (d), "d:float?:null");
- Assert.AreEqual (-101f, ((float?) new XElement (d)).Value, "d:float?:value");
- Assert.IsNotNull ((float?) new XElement (o), "o:float?:null");
- Assert.AreEqual (0f, ((float?) new XElement (o)).Value, "o:float?:value");
- Assert.IsNotNull ((float?) new XElement (l), "l:float?:null");
- Assert.AreEqual (1f, ((float?) new XElement (l)).Value, "l:float?:value");
- Assert.IsNotNull ((float?) new XElement (I), "I:float?:null");
- Assert.AreEqual (float.PositiveInfinity, ((float?) new XElement (I)).Value, "I:float?:value");
- Assert.IsNotNull ((float?) new XElement (i), "i:float?:null");
- Assert.AreEqual (float.PositiveInfinity, ((float?) new XElement (i)).Value, "i:float?:value");
- Assert.IsNotNull ((float?) new XElement (M), "M:float?:null");
- Assert.AreEqual (float.NegativeInfinity, ((float?) new XElement (M)).Value, "M:float?:value");
- Assert.IsNotNull ((float?) new XElement (m), "m:float?:null");
- Assert.AreEqual (float.NegativeInfinity, ((float?) new XElement (m)).Value, "m:float?:value");
- Assert.IsNotNull ((float?) new XElement (n), "n:float?:null");
- Assert.IsNaN (((float?) new XElement (n)).Value, "n:float?:value");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (a); }, "a:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (b); }, "b:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (c); }, "c:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (d); }, "d:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (o); }, "o:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (l); }, "l:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (I); }, "I:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (i); }, "i:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (M); }, "M:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (m); }, "m:Guid?");
- AssertThrows<FormatException> (() => { Guid? z = (Guid?) new XElement (n); }, "n:Guid?");
- Assert.IsNotNull ((int?) new XElement (a), "a:int?:null");
- Assert.AreEqual (7, ((int?) new XElement (a)).Value, "a:int?:value");
- Assert.IsNotNull ((int?) new XElement (b), "b:int?:null");
- Assert.AreEqual (42, ((int?) new XElement (b)).Value, "b:int?:value");
- Assert.IsNotNull ((int?) new XElement (c), "c:int?:null");
- Assert.AreEqual (13, ((int?) new XElement (c)).Value, "c:int?:value");
- Assert.IsNotNull ((int?) new XElement (d), "d:int?:null");
- Assert.AreEqual (-101, ((int?) new XElement (d)).Value, "d:int?:value");
- Assert.IsNotNull ((int?) new XElement (o), "o:int?:null");
- Assert.AreEqual (0, ((int?) new XElement (o)).Value, "o:int?:value");
- Assert.IsNotNull ((int?) new XElement (l), "l:int?:null");
- Assert.AreEqual (1, ((int?) new XElement (l)).Value, "l:int?:value");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (I); }, "I:int?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (i); }, "i:int?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (M); }, "M:int?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (m); }, "m:int?");
- AssertThrows<FormatException> (() => { int? z = (int?) new XElement (n); }, "n:int?");
- Assert.IsNotNull ((long?) new XElement (a), "a:long?:null");
- Assert.AreEqual (7L, ((long?) new XElement (a)).Value, "a:long?:value");
- Assert.IsNotNull ((long?) new XElement (b), "b:long?:null");
- Assert.AreEqual (42L, ((long?) new XElement (b)).Value, "b:long?:value");
- Assert.IsNotNull ((long?) new XElement (c), "c:long?:null");
- Assert.AreEqual (13L, ((long?) new XElement (c)).Value, "c:long?:value");
- Assert.IsNotNull ((long?) new XElement (d), "d:long?:null");
- Assert.AreEqual (-101L, ((long?) new XElement (d)).Value, "d:long?:value");
- Assert.IsNotNull ((long?) new XElement (o), "o:long?:null");
- Assert.AreEqual (0L, ((long?) new XElement (o)).Value, "o:long?:value");
- Assert.IsNotNull ((long?) new XElement (l), "l:long?:null");
- Assert.AreEqual (1L, ((long?) new XElement (l)).Value, "l:long?:value");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (I); }, "I:long?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (i); }, "i:long?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (M); }, "M:long?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (m); }, "m:long?");
- AssertThrows<FormatException> (() => { long? z = (long?) new XElement (n); }, "n:long?");
- Assert.IsNotNull ((uint?) new XElement (a), "a:uint?:null");
- Assert.AreEqual (7u, ((uint?) new XElement (a)).Value, "a:uint?:value");
- Assert.IsNotNull ((uint?) new XElement (b), "b:uint?:null");
- Assert.AreEqual (42u, ((uint?) new XElement (b)).Value, "b:uint?:value");
- Assert.IsNotNull ((uint?) new XElement (c), "c:uint?:null");
- Assert.AreEqual (13u, ((uint?) new XElement (c)).Value, "c:uint?:value");
- // LAMESPEC: see XmlConvertTests.ToUInt32().
- //AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (d); }, "d:uint?");
- Assert.IsNotNull ((uint?) new XElement (o), "o:uint?:null");
- Assert.AreEqual (0u, ((uint?) new XElement (o)).Value, "o:uint?:value");
- Assert.IsNotNull ((uint?) new XElement (l), "l:uint?:null");
- Assert.AreEqual (1u, ((uint?) new XElement (l)).Value, "l:uint?:value");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (I); }, "I:uint?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (i); }, "i:uint?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (M); }, "M:uint?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (m); }, "m:uint?");
- AssertThrows<FormatException> (() => { uint? z = (uint?) new XElement (n); }, "n:uint?");
- Assert.IsNotNull ((ulong?) new XElement (a), "a:ulong?:null");
- Assert.AreEqual (7UL, ((ulong?) new XElement (a)).Value, "a:ulong?:value");
- Assert.IsNotNull ((ulong?) new XElement (b), "b:ulong?:null");
- Assert.AreEqual (42UL, ((ulong?) new XElement (b)).Value, "b:ulong?:value");
- Assert.IsNotNull ((ulong?) new XElement (c), "c:ulong?:null");
- Assert.AreEqual (13UL, ((ulong?) new XElement (c)).Value, "c:ulong?:value");
- // LAMESPEC: see XmlConvertTests.ToUInt64().
- //AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (d); }, "d:ulong?");
- Assert.IsNotNull ((ulong?) new XElement (o), "o:ulong?:null");
- Assert.AreEqual (0UL, ((ulong?) new XElement (o)).Value, "o:ulong?:value");
- Assert.IsNotNull ((ulong?) new XElement (l), "l:ulong?:null");
- Assert.AreEqual (1UL, ((ulong?) new XElement (l)).Value, "l:ulong?:value");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (I); }, "I:ulong?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (i); }, "i:ulong?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (M); }, "M:ulong?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (m); }, "m:ulong?");
- AssertThrows<FormatException> (() => { ulong? z = (ulong?) new XElement (n); }, "n:ulong?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (a); }, "a:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (b); }, "b:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (c); }, "c:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (d); }, "d:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (o); }, "o:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (l); }, "l:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (I); }, "I:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (i); }, "i:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (M); }, "M:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (m); }, "m:TimeSpan?");
- AssertThrows<FormatException> (() => { TimeSpan? z = (TimeSpan?) new XElement (n); }, "n:TimeSpan?");
- Assert.AreEqual ("7", (string) new XElement (a), "a:string");
- Assert.AreEqual (" 42 ", (string) new XElement (b), "b:string");
- Assert.AreEqual (" \r\n 13 \t ", (string) new XElement (c), "c:string");
- Assert.AreEqual ("-101", (string) new XElement (d), "d:string");
- Assert.AreEqual ("0", (string) new XElement (o), "o:string");
- Assert.AreEqual ("1", (string) new XElement (l), "l:string");
- Assert.AreEqual ("INF", (string) new XElement (I), "I:string");
- Assert.AreEqual (…
Large files files are truncated, but you can click here to view the full file