Exemple #1
0
            public void DeserializeArrayOfMixedToObject()
            {
                var response = new RestResponse();

                response.Content = EmbeddedResource.LoadFile("ResponseData.ArrayOfMixedResponse.xml");
                var deSerializer = new XmlRpcDeserializer();
                var data         = deSerializer.Deserialize <DeSerializeMixedArray>(response);

                Assert.AreEqual("One", data.FirstString);
                Assert.AreEqual("Two", data.ASecondString);
                //Assert.AreEqual( 256.256, Convert.ToDecimal( data.Last() ) );
            }
Exemple #2
0
            public void DeserializeSimpleStruct()
            {
                var response = new RestResponse();

                response.Content = EmbeddedResource.LoadFile("ResponseData.SimpleStruct.xml");
                var deSerializer = new XmlRpcDeserializer();
                var data         = deSerializer.Deserialize <DeSerializeSimpleStruct>(response);

                Assert.AreEqual("Title", data.title);
                Assert.AreEqual("My Description", data.description);
                Assert.AreEqual(45, data.code);
            }
Exemple #3
0
 public static object Parse(
   string xml,
   Type valueType,
   MappingAction action,
   XmlRpcDeserializer serializer,
   out Type parsedType,
   out Type parsedArrayType)
 {
   StringReader sr = new StringReader(xml);
   XmlReader rdr = XmlRpcXmlReader.Create(sr);
   return Parse(rdr, valueType, action, serializer,
     out parsedType, out parsedArrayType);
 }
Exemple #4
0
            public void DeserializeArrayOfMixed()
            {
                var response = new RestResponse();

                response.Content = EmbeddedResource.LoadFile("ResponseData.ArrayOfMixedResponse.xml");
                var deSerializer = new XmlRpcDeserializer();
                var data         = deSerializer.Deserialize <List <object> >(response);

                Assert.AreEqual(6, data.Count);
                Assert.AreEqual("One", data.First());
                Assert.AreEqual(256.256, Convert.ToDecimal(data[4]));
                Assert.AreEqual("Two", data.Last());
            }
Exemple #5
0
        public void DateTime_Empty_Standard()
        {
            Type               parsedType, parsedArrayType;
            string             xml        = @"<?xml version=""1.0"" ?>
        <value><dateTime.iso8601></dateTime.iso8601></value>";
            XmlRpcDeserializer serializer = new XmlRpcDeserializer();

            serializer.NonStandard = XmlRpcNonStandard.MapEmptyDateTimeToMinValue;
            object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error, serializer,
                                     out parsedType, out parsedArrayType);

            Assert.AreEqual(DateTime.MinValue, (DateTime)obj);
        }
Exemple #6
0
 public static object Parse(
   XmlReader rdr,
   Type valueType,
   MappingAction action,
   XmlRpcDeserializer deserializer,
   out Type parsedType,
   out Type parsedArrayType)
 {
   parsedType = parsedArrayType = null;
   rdr.ReadToDescendant("value");
   MappingStack parseStack = new MappingStack("request");
   object obj = deserializer.ParseValueElement(rdr, valueType, parseStack, action);
   return obj;
 }
Exemple #7
0
        public void Issue72()
        {
            Type               parsedType, parsedArrayType;
            string             xml        = @"<?xml version=""1.0"" ?>
        <value><dateTime.iso8601>20090209T22:20:01+01:00</dateTime.iso8601></value>";
            XmlRpcDeserializer serializer = new XmlRpcDeserializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
            object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error,
                                     serializer, out parsedType, out parsedArrayType);

            Assert.AreEqual(new DateTime(2009, 2, 9, 21, 20, 01),
                            (DateTime)obj);
        }
        public static object Parse(
            string xml,
            Type valueType,
            MappingAction action,
            XmlRpcDeserializer serializer,
            out Type parsedType,
            out Type parsedArrayType)
        {
            StringReader sr  = new StringReader(xml);
            XmlReader    rdr = XmlRpcXmlReader.Create(sr);

            return(Parse(rdr, valueType, action, serializer,
                         out parsedType, out parsedArrayType));
        }
Exemple #9
0
        public void DateTime_ROCA()
        {
            Type               parsedType, parsedArrayType;
            string             xml        = @"<?xml version=""1.0"" ?>
        <value><dateTime.iso8601>2002-07-06T11:25:37</dateTime.iso8601></value>";
            XmlRpcDeserializer serializer = new XmlRpcDeserializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
            object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error, serializer,
                                     out parsedType, out parsedArrayType);

            Assert.AreEqual(new DateTime(2002, 7, 6, 11, 25, 37),
                            (DateTime)obj);
        }
        public static object ParseValue(string xml, Type valueType)
        {
            MappingAction action = MappingAction.Error;

            StringReader sr  = new StringReader(xml);
            XmlReader    rdr = XmlRpcXmlReader.Create(sr);

            rdr.MoveToContent();
            MappingStack parseStack = new MappingStack("value");
            var          deser      = new XmlRpcDeserializer();
            object       obj        = deser.ParseValueElement(rdr, valueType, parseStack, action);

            return(obj);
        }
Exemple #11
0
        public void DateTime_TZMinus01Colon30()
        {
            // yyyyMMddThh:mm:ssZ+00
            Type               parsedType, parsedArrayType;
            string             xml        = @"<?xml version=""1.0"" ?>
        <value><dateTime.iso8601>20020706T09:55:37-01:30</dateTime.iso8601></value>";
            XmlRpcDeserializer serializer = new XmlRpcDeserializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
            object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error,
                                     serializer, out parsedType, out parsedArrayType);

            Assert.AreEqual(new DateTime(2002, 7, 6, 11, 25, 37),
                            (DateTime)obj);
        }
        public static object Parse(
            XmlReader rdr,
            Type valueType,
            MappingAction action,
            XmlRpcDeserializer deserializer,
            out Type parsedType,
            out Type parsedArrayType)
        {
            parsedType = parsedArrayType = null;
            rdr.ReadToDescendant("value");
            MappingStack parseStack = new MappingStack("request");
            object       obj        = deserializer.ParseValueElement(rdr, valueType, parseStack, action);

            return(obj);
        }
            public void DeserializeComplexStruct()
            {
                var response = new RestResponse();

                response.Content = EmbeddedResource.LoadFile("ResponseData.ComplexStruct.xml");
                var deSerializer = new XmlRpcDeserializer()
                {
                    DateFormat = "yyyy-MM-dd'T'HH':'mm':'ss"
                };
                var data = deSerializer.Deserialize <DeSerializeComplexStruct>(response);

                Assert.AreEqual("Title", data.title);
                Assert.AreEqual("My Description", data.description);
                Assert.AreEqual(45, data.code);
                Assert.IsNotNull(data.subobject);
                Assert.AreEqual(3, data.events.Count);
                Assert.AreEqual(3, data.events.First().priceLevels.Count);
                Assert.AreEqual(3, data.events.First().priceLevels.First().priceTypes.Count);
            }
Exemple #14
0
 public void Issue72()
 {
     Type parsedType, parsedArrayType;
     const string Xml = @"<?xml version=""1.0"" ?><value><dateTime.iso8601>20090209T22:20:01+01:00</dateTime.iso8601></value>";
     var serializer = new XmlRpcDeserializer();
     serializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
     var obj = Utils.Parse(
         Xml,
         typeof(DateTime),
         MappingAction.Error,
         serializer,
         out parsedType,
         out parsedArrayType);
     obj.ShouldBe(new DateTime(2009, 2, 9, 21, 20, 01));
 }
Exemple #15
0
 public void DateTime_Empty_Standard()
 {
     Type parsedType, parsedArrayType;
     const string Xml = @"<?xml version=""1.0"" ?><value><dateTime.iso8601></dateTime.iso8601></value>";
     var serializer = new XmlRpcDeserializer();
     serializer.NonStandard = XmlRpcNonStandard.MapEmptyDateTimeToMinValue;
     var obj = Utils.Parse(
         Xml,
         typeof(DateTime),
         MappingAction.Error,
         serializer,
         out parsedType,
         out parsedArrayType);
     obj.ShouldBe(DateTime.MinValue);
 }
Exemple #16
0
 public void DateTime_WordPress()
 {
     // yyyyMMddThh:mm:ssZ
     Type parsedType, parsedArrayType;
     const string Xml = @"<?xml version=""1.0"" ?><value><dateTime.iso8601>20020706T11:25:37Z</dateTime.iso8601></value>";
     var serializer = new XmlRpcDeserializer();
     serializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
     var obj = Utils.Parse(
         Xml,
         typeof(DateTime),
         MappingAction.Error,
         serializer,
         out parsedType,
         out parsedArrayType);
     obj.ShouldBe(new DateTime(2002, 7, 6, 11, 25, 37));
 }
Exemple #17
0
 public void DateTime_Empty_Standard()
 {
   Type parsedType, parsedArrayType;
   string xml = @"<?xml version=""1.0"" ?>
     <value><dateTime.iso8601></dateTime.iso8601></value>";
   XmlRpcDeserializer serializer = new XmlRpcDeserializer();
   serializer.NonStandard = XmlRpcNonStandard.MapEmptyDateTimeToMinValue;
   object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error, serializer,
     out parsedType, out parsedArrayType);
   Assert.AreEqual(DateTime.MinValue, (DateTime)obj);
 }
Exemple #18
0
 public void DateTime_Empty_NonStandard()
 {
   Type parsedType, parsedArrayType;
   string xml = @"<?xml version=""1.0"" ?>
     <value><dateTime.iso8601></dateTime.iso8601></value>";
   XmlRpcDeserializer serializer = new XmlRpcDeserializer();
   object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error, serializer,
     out parsedType, out parsedArrayType);
 }
Exemple #19
0
 public void Issue72()
 {
   Type parsedType, parsedArrayType;
   string xml = @"<?xml version=""1.0"" ?>
     <value><dateTime.iso8601>20090209T22:20:01+01:00</dateTime.iso8601></value>";
   XmlRpcDeserializer serializer = new XmlRpcDeserializer();
   serializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
   object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error,
     serializer, out parsedType, out parsedArrayType);
   Assert.AreEqual(new DateTime(2009, 2, 9, 21, 20, 01),
     (DateTime)obj);
 }
    public void String1IncorrectType()
    {
      try
      {
        string xml = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value>test string</value>
    </param>
  </params>
</methodResponse>";
        StringReader sr = new StringReader(xml);
        XmlRpcDeserializer serializer = new XmlRpcDeserializer();
        var deserializer = new XmlRpcResponseDeserializer();
        XmlRpcResponse response = deserializer.DeserializeResponse(sr, typeof(int));
        Assert.Fail("Should throw XmlRpcTypeMismatchException");
      }
      catch(XmlRpcTypeMismatchException)
      {
      }
    }
Exemple #21
0
    public static object ParseValue(string xml, Type valueType)
    {
      MappingAction action = MappingAction.Error;

      StringReader sr = new StringReader(xml);
      XmlReader rdr = XmlRpcXmlReader.Create(sr);
      rdr.MoveToContent();
      MappingStack parseStack = new MappingStack("value");
      var deser = new XmlRpcDeserializer();
      object obj = deser.ParseValueElement(rdr, valueType, parseStack, action);
      return obj;
    }
Exemple #22
0
 public void DateTime_Empty_NonStandard()
 {
     Type parsedType, parsedArrayType;
     const string Xml = @"<?xml version=""1.0"" ?><value><dateTime.iso8601></dateTime.iso8601></value>";
     var serializer = new XmlRpcDeserializer();
     Should.Throw<XmlRpcInvalidXmlRpcException>(() =>
         Utils.Parse(
             Xml,
             typeof(DateTime),
             MappingAction.Error,
             serializer,
             out parsedType,
             out parsedArrayType));
 }
Exemple #23
0
 public void DateTime_TZMinus0000()
 {
   // yyyyMMddThh:mm:ssZ+00
   Type parsedType, parsedArrayType;
   string xml = @"<?xml version=""1.0"" ?>
     <value><dateTime.iso8601>20020706T11:25:37-0000</dateTime.iso8601></value>";
   XmlRpcDeserializer serializer = new XmlRpcDeserializer();
   serializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
   object obj = Utils.Parse(xml, typeof(DateTime), MappingAction.Error,
     serializer, out parsedType, out parsedArrayType);
   Assert.AreEqual(new DateTime(2002, 7, 6, 11, 25, 37),
     (DateTime)obj);
 }