Exemple #1
0
 public object Get(ComplexClassForOpenRastaSerializationTests data)
 {
   ObjectSerializer serializer = new ObjectSerializer(data.GetType());
   ObjectToStringPropertyVisitor visitor = new ObjectToStringPropertyVisitor();
   serializer.Serialize(data, visitor);
   return visitor.Result;
 }
        public void CanPostComplexClass()
        {
            // Arrange
              Guid g = Guid.NewGuid();
              ComplexClassForOpenRastaSerializationTests o = new ComplexClassForOpenRastaSerializationTests
              {
            X = 15,
            Y = "Abc",
            IntArray = new List<int> { 1, 2 },
            SubC = new ComplexClassForOpenRastaSerializationTests.SubClass
            {
              SubC = new ComplexClassForOpenRastaSerializationTests.SubClass
              {
            Data = new List<string> { "Benny" }
              },
              Data = new List<string> { "Brian" }
            },
            Dict = new Dictionary<string,string>(),
            Date = new DateTime(2012, 10, 30, 12, 13, 14),
            Dou = 15.234,
            GID = g
              };
              o.Dict["abc"] = "123";
              o.Dict["qwe"] = "xyz";

              Session.SerializerSettings = new ObjectSerializerSettings
              {
            ArrayFormat = "{0}:{1}",
            DictionaryFormat = "{0}:{1}",
            PropertyFormat = "{0}.{1}"
              };

              Request request = Session.Bind(ComplexClassTemplate);

              // Act
              using (Response<string> response = request.Accept("text/plain")
                                                .AsFormUrlEncoded()
                                                .Post<string>(o))
              {
            // Assert
            Console.WriteLine(response.Body);
            Assert.AreEqual("|X=15|Y=Abc|IntArray[0]=1|IntArray[1]=2|SubC.SubC.Data[0]=Benny|SubC.Data[0]=Brian|Dict[abc]=123|Dict[qwe]=xyz|Date=2012-10-30T12:13:14|Dou=15.234|GID=" + g.ToString(), response.Body);
              }
        }