Created
September 21, 2010 08:57
-
-
Save Andrea/589424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] //this is a the test attribute when using xUnit | |
public void When_xml_Something_Then_serialize_returns_null() | |
{ | |
string serializedObject = | |
"<?xml version=\"1.0\" encoding=\"utf-8\"?><MyClass xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://exampleA.org\" />"; | |
using (var stringReader = new StringReader(serializedObject)) | |
{ | |
Assert.Null(new XmlSerializer(typeof(MyClass)).Deserialize(stringReader)); | |
} | |
} | |
[Fact] | |
public void When_xml_Then_serialize_returns_null_with_xml_reader() | |
{ | |
string serializedObject = | |
"<?xml version=\"1.0\" encoding=\"utf-8\"?><MyClass xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://exampleA.org\" />"; | |
using (var stringReader = new StringReader(serializedObject)) | |
{ | |
var doc = new XmlDocument(); | |
doc.Load(stringReader); | |
Assert.Null(new XmlSerializer(typeof(MyClass)).Deserialize(stringReader)); | |
} | |
} | |
//--------------------------- | |
[Serializable] | |
[XmlRoot(Namespace = "http://example.org")] | |
public class MyClass | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the test throws
System.InvalidOperationException: was not expected.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMyClass.Read3_MyClass()
System.InvalidOperationException: There is an error in XML document (1, 40).
if you change the xmlns:xsd or the xmlns:xsi then the class is deserialized no probs