Ejemplo n.º 1
0
        public void StructTest()
        {
            byte[] testb = new byte[]
                               {
                                   121, 111, 117, 32, 99, 97, 110, 39, 116, 32, 114, 101, 97, 100, 32, 116, 104, 105, 115,
                                   33
                               };

            Struct1 str1 = new Struct1();
            str1.mi = 34567;
            str1.ms = "another test string";
            str1.mb = true;
            str1.md = 8765.123;
            str1.mdt = new DateTime(2002, 7, 6, 11, 25, 37);
            str1.mb64 = testb;
            str1.ma = new[] { 1, 2, 3, 4, 5 };
            XmlReader xdoc = Utils.Serialize(
                "SerializeTest.testStruct",
                str1,
                Encoding.UTF8,
                new MappingActions { NullMappingAction = NullMappingAction.Ignore });
            Type parsedType, parsedArrayType;
            object obj = Utils.Parse(xdoc, typeof(Struct1), MappingAction.Error, out parsedType, out parsedArrayType);
            Assert.IsTrue(obj is Struct1, "result is Struct1");
            Struct1 str2 = (Struct1)obj;
            Assert.IsTrue(str2.Equals(str1));
        }
Ejemplo n.º 2
0
            public bool Equals(Struct1 str)
            {
                if (mi != str.mi || ms != str.ms || md != str.md || mdt != str.mdt)
                {
                    return false;
                }

                if (mb64.Length != str.mb64.Length)
                {
                    return false;
                }

                for (int i = 0; i < mb64.Length; i++)
                {
                    if (mb64[i] != str.mb64[i])
                    {
                        return false;
                    }
                }

                for (int i = 0; i < ma.Length; i++)
                {
                    if (ma[i] != str.ma[i])
                    {
                        return false;
                    }
                }

                return true;
            }
Ejemplo n.º 3
0
        public void StructOrderTest()
        {
            byte[] testb = new byte[]
                               {
                                   121, 111, 117, 32, 99, 97, 110, 39, 116, 32, 114, 101, 97, 100, 32, 116, 104, 105, 115,
                                   33
                               };

            Struct1 str1 = new Struct1();
            str1.mi = 34567;
            str1.ms = "another test string";
            str1.mb = true;
            str1.md = 8765.123;
            str1.mdt = new DateTime(2002, 7, 6, 11, 25, 37);
            str1.mb64 = testb;
            str1.ma = new[] { 1, 2, 3, 4, 5 };

            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { str1 };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr = new StreamReader(stm);
            string reqstr = tr.ReadToEnd();
            Assert.Less(reqstr.IndexOf(">mi</"), reqstr.IndexOf(">ms</"));
            Assert.Less(reqstr.IndexOf(">ms</"), reqstr.IndexOf(">mb</"));
            Assert.Less(reqstr.IndexOf(">mb</"), reqstr.IndexOf(">md</"));
            Assert.Less(reqstr.IndexOf(">md</"), reqstr.IndexOf(">mdt</"));
            Assert.Less(reqstr.IndexOf(">mdt</"), reqstr.IndexOf(">mb64</"));
            Assert.Less(reqstr.IndexOf(">mb64</"), reqstr.IndexOf(">ma</"));
        }