public void DateTime() { CultureInfo oldci = Thread.CurrentThread.CurrentCulture; try { foreach (string locale in Utils.GetLocales()) { CultureInfo ci = new CultureInfo(locale); Thread.CurrentThread.CurrentCulture = ci; DateTime testDate = new DateTime(2002, 7, 6, 11, 25, 37); XmlDocument xdoc = Utils.Serialize("SerializeTest.testDateTime", testDate, Encoding.UTF8, MappingAction.Error); Type parsedType, parsedArrayType; object obj = Utils.Parse(xdoc, null, MappingAction.Error, out parsedType, out parsedArrayType); Assert.AreEqual(testDate, obj); } } catch (Exception ex) { Assert.Fail("unexpected exception: " + ex.Message); } finally { Thread.CurrentThread.CurrentCulture = oldci; } }
public void DateTimeLocales() { CultureInfo oldci = Thread.CurrentThread.CurrentCulture; try { foreach (string locale in Utils.GetLocales()) { try { CultureInfo ci = new CultureInfo(locale); Thread.CurrentThread.CurrentCulture = ci; if (ci.LCID == 0x401 || // ar-SA (Arabic - Saudi Arabia) ci.LCID == 0x465 || // div-MV (Dhivehi - Maldives) ci.LCID == 0x41e) // th-TH (Thai - Thailand) { break; } DateTime dt = new DateTime(1900, 01, 02, 03, 04, 05); while (dt < DateTime.Now) { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { dt }; req.method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; var deserializer = new XmlRpcRequestDeserializer(); XmlRpcRequest request = deserializer.DeserializeRequest(stm, null); Assert.IsTrue(request.args[0] is DateTime, "argument is DateTime"); DateTime dt0 = (DateTime)request.args[0]; Assert.AreEqual(dt0, dt, "DateTime argument 0"); dt += new TimeSpan(100, 1, 1, 1); } } catch (Exception ex) { Assert.Fail(String.Format("unexpected exception {0}: {1}", locale, ex.Message)); } } } finally { Thread.CurrentThread.CurrentCulture = oldci; } }