public void Can_deserialize_object() { const string xml = "<?xml version=\"1.0\"?><response xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><testObject id=\"1\"> <name>A big test object</name><listOfThings><string>one</string><string>two</string><string>three</string></listOfThings><listOfInnerObjects><InnerObject id=\"1\"><Name>Trevor</Name></InnerObject><InnerObject id=\"2\"><Name>Bill</Name></InnerObject></listOfInnerObjects></testObject></response>"; var xmlSerializer = new ApiXmlDeSerializer<TestObject>(new ApiResourceDeSerializer<TestObject>(), new XmlErrorHandler()); Assert.DoesNotThrow(() => xmlSerializer.DeSerialize(xml)); TestObject testObject = xmlSerializer.DeSerialize(xml); Assert.That(testObject.Id, Is.EqualTo(GetTestObject().Id)); }
public void Should_throw_api_exception_with_correct_error_if_error_xml_received() { var apiXmlDeSerializer = new ApiXmlDeSerializer<Status>(null, new XmlErrorHandler()); var apiException = Assert.Throws<ApiXmlException>(() => apiXmlDeSerializer.DeSerialize(string.Empty)); Assert.That(apiException.Message, Is.StringContaining("An error has occured in the Api")); Assert.That(apiException.Error.Code, Is.EqualTo(9001)); }
public void should_deserialize_emtpy_release_type_to_unknown() { var response = XDocument.Load("StubResponses/ArtistReleases.xml"); var xmlSerializer = new ApiXmlDeSerializer<ArtistReleases>(new ApiResourceDeSerializer<ArtistReleases>(), new XmlErrorHandler()); var release = xmlSerializer.DeSerialize(response.ToString()).Releases.First(); Assert.That(release.Type,Is.EqualTo(ReleaseType.Unknown)); }