1 /*----------------------------------------------------------------------------
 2 Name:      Stuff.cs
 3 Project:   xmlBlaster.org
 4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
 5 Author:    "Marcel Ruff" <xmlBlaster@marcelruff.info>
 6 Date:      2007
 7 See:       http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.html
 8 -----------------------------------------------------------------------------*/
 9 using System;
10 using System.Text;
11 using NUnit.Framework;
12 using System.Collections;
13 using org.xmlBlaster.util;
14 
15 namespace org.xmlBlaster.client.util {
16    [TestFixture]
17    public class StuffTest {
18       [Test]
19       public void CheckIsoDates() {
20          string str = "2007-01-01 12:46:01Z";
21          DateTime dt = Stuff.UtcDateTimeFromIsoString(str);
22          string newStr = Stuff.ToUtcIsoDateTimeString(dt);
23          Assert.AreEqual(str, newStr);
24       }
25       [Test]
26       public void CheckEpochMillis() {
27          //Stuff.ToUtcMillisecondsEpoch(DateTime dateTime)

28          //Stuff.GetCurrentUtcMillisecondsEpoch()

29          //Stuff.DateTimeFromUtcMillisecondsEpoch(long milliEpoch)

30          
31          // From Java:

32          // millis=1183965018906

33          // gmt=     9 Jul 2007 07:10:18

34          // GMT iso= 2007-07-09 07:10:18.906Z

35          ///local=   09.07.2007 09:10:18

36          long utcMillis = 1183965018906L;
37          DateTime dateTimeUtc = Stuff.DateTimeFromUtcMillisecondsEpoch(utcMillis);
38          long newUtcMillis = Stuff.ToUtcMillisecondsEpoch(dateTimeUtc);
39          string isoUtcStr= Stuff.ToUtcIsoDateTimeString(dateTimeUtc);
40          Console.WriteLine("dateTimeUtc=" + isoUtcStr
41             + " utcMillis=" + utcMillis + " newUtcMillis=" + newUtcMillis);
42          Assert.AreEqual(utcMillis, newUtcMillis);
43          // TODO: The millis are missing!!!! Assert.AreEqual("2007-07-09 07:10:18.906Z", newUtcMillis);

44          Assert.AreEqual("2007-07-09 07:10:18.906Z", isoUtcStr);
45 
46          long millis = Stuff.GetCurrentUtcMillisecondsEpoch();
47          Console.WriteLine("Current millis=" + millis);
48       }
49       [Test]
50       public void CheckClientProperties() {
51          Hashtable h = new Hashtable();
52          //h.Add("key1", "value1");

53          h.Add("key<", "<&>!§");
54          string xml = Stuff.ToClientPropertiesXml(h, true);
55          Console.WriteLine(xml);
56          Assert.AreEqual("\n <clientProperty name='key&lt;'>&lt;&amp;&gt;!§</clientProperty>", xml);
57       }
58    }
59 }


syntax highlighted by Code2HTML, v. 0.9.1