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); }
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 int[] { 1, 2, 3, 4, 5 }; XmlDocument xdoc = Utils.Serialize("SerializeTest.testStruct", str1, Encoding.UTF8, MappingAction.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)); }
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 int[] { 1, 2, 3, 4, 5 }; Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { str1 }; req.method = "Foo"; XmlRpcSerializer ser = new XmlRpcSerializer(); 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</")); }