-Tests
This commit is contained in:
@@ -2672,7 +2672,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeExplicitAttributeNamespace()
|
public void SerializeElementExplicitAttributeNamespace()
|
||||||
{
|
{
|
||||||
var original = XElement.Parse("<MyElement xmlns=\"http://example.com\" />");
|
var original = XElement.Parse("<MyElement xmlns=\"http://example.com\" />");
|
||||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
||||||
@@ -2685,7 +2685,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeImplicitAttributeNamespace()
|
public void SerializeElementImplicitAttributeNamespace()
|
||||||
{
|
{
|
||||||
var original = new XElement("{http://example.com}MyElement");
|
var original = new XElement("{http://example.com}MyElement");
|
||||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
||||||
@@ -2696,6 +2696,32 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
var deserialized = JsonConvert.DeserializeObject<XElement>(json);
|
var deserialized = JsonConvert.DeserializeObject<XElement>(json);
|
||||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
|
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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user