Skip to content

Commit 40f922f

Browse files
author
Michael Hallett
committed
Added a test to deserialize xml into a struct
1 parent 2d69bcc commit 40f922f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

RestSharp.Tests/XmlDeserializerTests.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,26 @@ private string PathFor(string sampleFile)
3636
return Path.Combine(SampleDataPath, sampleFile);
3737
}
3838

39+
[Fact]
40+
public void Can_Deserialize_Into_Struct()
41+
{
42+
const string content = "<root><one>oneOneOne</one><two>twoTwoTwo</two><three>3</three></root>";
43+
var xml = new XmlDeserializer();
44+
var output = xml.Deserialize<SimpleStruct>(new RestResponse { Content = content });
45+
46+
Assert.NotNull(output);
47+
Assert.Equal("oneOneOne", output.One);
48+
Assert.Equal("twoTwoTwo", output.Two);
49+
Assert.Equal(3, output.Three);
50+
}
3951
[Fact]
4052
public void Can_Deserialize_Lists_of_Simple_Types()
4153
{
4254
var xmlpath = PathFor("xmllists.xml");
4355
var doc = XDocument.Load(xmlpath);
4456

4557
var xml = new XmlDeserializer();
46-
var output = xml.Deserialize<SimpleTypesListSample>(new RestResponse() { Content = doc.ToString() });
58+
var output = xml.Deserialize<SimpleTypesListSample>(new RestResponse { Content = doc.ToString() });
4759

4860
Assert.NotEmpty(output.Names);
4961
Assert.NotEmpty(output.Numbers);
@@ -216,7 +228,7 @@ public void Can_Deserialize_Elements_to_Nullable_Values()
216228
{
217229
var culture = CultureInfo.InvariantCulture;
218230
var doc = CreateXmlWithoutEmptyValues(culture);
219-
var xml = new XmlDeserializer() { Culture = culture };
231+
var xml = new XmlDeserializer { Culture = culture };
220232
var output = xml.Deserialize<NullableValues>(new RestResponse { Content = doc });
221233

222234
Assert.NotNull(output.Id);

0 commit comments

Comments
 (0)