Esempio n. 1
0
        public void TestComplexXml()
        {
            Complex complex1 = Complex.Create();
            string  xml1     = Proto <Complex> .ToXml(complex1);

            Complex complex2 = Proto <Complex> .FromXml(xml1);

            string xml2 = Proto <Complex> .ToXml(complex2);

            Assert.Equal(xml1, xml2);
        }
Esempio n. 2
0
        public void TestSimpleXml()
        {
            Simple simple1 = Simple.Random();
            string xml1    = Proto <Simple> .ToXml(simple1);

            Simple simple2 = Proto <Simple> .FromXml(xml1);

            string xml2 = Proto <Simple> .ToXml(simple2);

            Assert.Equal(xml1, xml2);
        }
Esempio n. 3
0
        static void Dump(string url, CookieCollection cookies)
        {
            List <PCookie> list = new List <PCookie>();

            foreach (System.Net.Cookie cookie in cookies)
            {
                PCookie c = new PCookie
                {
                    Name       = cookie.Name,
                    Value      = cookie.Value,
                    Version    = cookie.Version,
                    Comment    = cookie.Comment,
                    CommentUri = cookie.CommentUri?.AbsolutePath,
                    Domain     = cookie.Domain,
                    Port       = cookie.Port,
                    Path       = cookie.Path,
                    Expired    = cookie.Expired,
                    Expires    = cookie.Expires,
                    HttpOnly   = cookie.HttpOnly,
                    Secure     = cookie.Secure,
                    Timestamp  = cookie.TimeStamp
                };
                list.Add(c);
            }

            PCookies cc = new PCookies
            {
                Cookies = new Dictionary <string, List <PCookie> >
                {
                    { url, list }
                },
            };

            string json = Proto <PCookies> .ToJson(cc);

            Console.WriteLine(json);
            Console.WriteLine();
            Console.WriteLine(Proto <PCookies> .ToJson(Proto <PCookies> .FromJson(json)));
            Console.WriteLine();
            string xml = Proto <PCookies> .ToXml(cc);

            Console.WriteLine(xml);
            Console.WriteLine(Proto <PCookies> .ToXml(Proto <PCookies> .FromXml(xml)));
            Console.WriteLine();
            Console.WriteLine();
        }
Esempio n. 4
0
        public override void ComplexTest()
        {
            trans.Clear();
            Proto <Complex> .Write(prot, complexInput);

            PrintBuf();
            trans.Seek(0, SeekOrigin.Begin);
            complexOutput = Proto <Complex> .Read(prot, complexOutput);

            if (this.xml)
            {
                string xml1 = Proto <Complex> .ToXml(complexOutput);

                WriteLine(xml1);
                complexOutput = Proto <Complex> .FromXml(xml1);

                string xml2 = Proto <Complex> .ToXml(complexOutput);

                CommonUtils.ThrowIfFalse(xml1 == xml2);
            }

            if (this.json)
            {
                string json1 = Proto <Complex> .ToJson(complexOutput);

                WriteLine(json1);
                complexOutput = Proto <Complex> .FromJson(json1);

                string json2 = Proto <Complex> .ToJson(complexOutput);

                WriteLine(json2);
                CommonUtils.ThrowIfFalse(json1 == json2);
            }

            WriteLine("simple:{0},{1},{2},{3}",
                      complexOutput.SimpleValue.Value,
                      complexOutput.SimpleValue.ShortValue,
                      complexOutput.SimpleValue.IntValue,
                      complexOutput.SimpleValue.LongValue);

            if (complexOutput.ListValue != null)
            {
                for (int i = 0; i < complexOutput.ListValue.Count; i++)
                {
                    WriteLine("list:{0},{1},{2},{3}",
                              complexOutput.ListValue[i].Value,
                              complexOutput.ListValue[i].ShortValue,
                              complexOutput.ListValue[i].IntValue,
                              complexOutput.ListValue[i].LongValue);
                }
            }

            if (complexOutput.SetValue != null)
            {
                foreach (Simple simple in complexOutput.SetValue)
                {
                    WriteLine("set:{0},{1},{2},{3}",
                              simple.Value,
                              simple.ShortValue,
                              simple.IntValue,
                              simple.LongValue);
                }
            }

            if (complexOutput.MapValue != null)
            {
                foreach (string key in complexOutput.MapValue.Keys)
                {
                    WriteLine("map[{0}]:{1},{2},{3},{4}",
                              key,
                              complexOutput.MapValue[key].Value,
                              complexOutput.MapValue[key].ShortValue,
                              complexOutput.MapValue[key].IntValue,
                              complexOutput.MapValue[key].LongValue);
                }
            }

            if (complexOutput.ArrayValue != null)
            {
                for (int i = 0; i < complexOutput.ArrayValue.Length; i++)
                {
                    WriteLine("array:{0},{1},{2},{3}",
                              complexOutput.ArrayValue[i].Value,
                              complexOutput.ArrayValue[i].ShortValue,
                              complexOutput.ArrayValue[i].IntValue,
                              complexOutput.ArrayValue[i].LongValue);
                }
            }

            if (complexOutput.StringArray != null)
            {
                for (int i = 0; i < complexOutput.StringArray.Length; i++)
                {
                    WriteLine("strarr:{0}", complexOutput.StringArray[i]);
                }
            }
        }