// Writes an object as an XmlRpc response public void Serialize(Stream stream, object o) { if (stream == null) { throw new ArgumentNullException("stream", "Argument must not be null"); } if (o == null) { throw new ArgumentNullException("o", "Argument must not be null"); } if (o is XmlRpcResponse) { StreamWriter sw = new StreamWriter(stream); XmlRpcWriter w = new XmlRpcWriter(sw); w.Write((XmlRpcResponse)o); w.Flush(); } else { // TODO This should be an exception Console.Out.WriteLine ("iMethodResponseFormatter: On No! Wrong type given: {0}, expected and object of type {1}", o.GetType(), "DotGNU.XmlRpc.XmlRpcResponse"); } }
public void MethodResponseWriterShouldSendParametersWithValues() { var mapper = new XmlRpcWriter(); var response = new XRpcMethodResponse(); response.Params.Add(new XRpcData <int> { Value = 42 }); var element = mapper.MapMethodResponse(response); Assert.That(NoSpace(element.ToString()), Is.EqualTo("<methodResponse><params><param><value><int>42</int></value></param></params></methodResponse>")); }
public void FaultShouldBeCorrectlyFormatted() { var mapper = new XmlRpcWriter(); var response = new XRpcMethodResponse { Fault = new XRpcFault(10, "foo") }; var element = mapper.MapMethodResponse(response); Assert.That(NoSpace(element.ToString()), Is.EqualTo(NoSpace(@" <methodResponse><fault> <value><struct> <member><name>faultCode</name><value><int>10</int></value></member> <member><name>faultString</name><value><string>foo</string></value></member> </struct></value> </fault></methodResponse> "))); }
public void ArrayAndStructShouldWorkAsExpected() { var mapper = new XmlRpcWriter(); var arr = new XRpcArray(); var structParam = XRpcData.For(new XRpcStruct()); arr.Data.Add(structParam); arr.Data.Add(XRpcData.For(19)); structParam.Value.Members.Add("Hello", XRpcData.For("world")); var element = mapper.MapArray(arr); Assert.That(NoSpace(element.ToString()), Is.EqualTo(NoSpace(@" <array><data> <value><struct> <member><name>Hello</name><value><string>world</string></value></member> </struct></value> <value><int>19</int></value> </data></array> "))); }
// Writes a XmlRpc MethodCall from the XmlRpcMethod object public void Serialize(Stream stream, object o) { if (stream == null) { throw new ArgumentNullException("stream", "Argument must not be null"); } if (o == null) { throw new ArgumentNullException("o", "Argument must not be null"); } if (o is XmlRpcMethod) { //StringWriter s = new StringWriter(); //XmlRpcWriter w = new XmlRpcWriter( s ); //w.Write( (XmlRpcMethod)o ); //StreamWriter sw = new StreamWriter( stream ); //sw.Write( s.ToString() ); //sw.Flush(); StreamWriter sw = new StreamWriter(stream); XmlRpcWriter w = new XmlRpcWriter(sw); w.Write((XmlRpcMethod)o); w.Flush(); } else { // TODO This should be an exception Console.Out.WriteLine ("MethodCallFormatter: Oh No! wrong type given: {0}, expected and object of type {1}", o.GetType(), "DotGNU.XmlRpc.XmlRpcMethod"); } }