This commit is contained in:
James Newton-King
2016-04-10 15:17:55 +12:00
parent 221beff235
commit b24be98fcc
@@ -2672,7 +2672,7 @@ namespace Newtonsoft.Json.Tests.Converters
}
[Test]
public void SerializeExplicitAttributeNamespace()
public void SerializeElementExplicitAttributeNamespace()
{
var original = XElement.Parse("<MyElement xmlns=\"http://example.com\" />");
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
@@ -2685,7 +2685,7 @@ namespace Newtonsoft.Json.Tests.Converters
}
[Test]
public void SerializeImplicitAttributeNamespace()
public void SerializeElementImplicitAttributeNamespace()
{
var original = new XElement("{http://example.com}MyElement");
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
@@ -2696,6 +2696,32 @@ namespace Newtonsoft.Json.Tests.Converters
var deserialized = JsonConvert.DeserializeObject<XElement>(json);
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
}
[Test]
public void SerializeDocumentExplicitAttributeNamespace()
{
var original = XDocument.Parse("<MyElement xmlns=\"http://example.com\" />");
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
var json = JsonConvert.SerializeObject(original);
Assert.AreEqual(@"{""MyElement"":{""@xmlns"":""http://example.com""}}", json);
var deserialized = JsonConvert.DeserializeObject<XDocument>(json);
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
}
[Test]
public void SerializeDocumentImplicitAttributeNamespace()
{
var original = new XDocument(new XElement("{http://example.com}MyElement"));
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
var json = JsonConvert.SerializeObject(original);
Assert.AreEqual(@"{""MyElement"":{""@xmlns"":""http://example.com""}}", json);
var deserialized = JsonConvert.DeserializeObject<XDocument>(json);
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
}
#endif
}
}