2 // WriterTest.cs: Unit Tests for ResXResourceWriter.
5 // Robert Jordan <robertj@gmx.net>
9 using System.Collections;
12 using System.Resources;
13 using NUnit.Framework;
15 namespace MonoTests.System.Resources
18 public class WriterTest
20 string fileName = Path.GetTempFileName ();
23 public void TestWriter ()
25 ResXResourceWriter w = new ResXResourceWriter (fileName);
26 w.AddResource ("String", "hola");
27 w.AddResource ("String2", (object) "hello");
28 w.AddResource ("Int", 42);
29 w.AddResource ("Enum", PlatformID.Win32NT);
30 w.AddResource ("Convertible", new Point (43, 45));
31 w.AddResource ("Serializable", new ArrayList(new byte[] {1, 2, 3, 4}));
32 w.AddResource ("ByteArray", new byte[] {12, 13, 14});
33 w.AddResource ("ByteArray2", (object) new byte[] {15, 16, 17});
34 w.AddResource ("IntArray", new int[] {1012, 1013, 1014});
35 w.AddResource ("StringArray", new string[] {"hello", "world"});
39 ResXResourceReader r = new ResXResourceReader (fileName);
40 Hashtable h = new Hashtable();
41 foreach (DictionaryEntry e in r) {
42 h.Add (e.Key, e.Value);
46 Assert.AreEqual ("hola", (string) h["String"], "#1");
47 Assert.AreEqual ("hello", (string) h["String2"], "#2");
48 Assert.AreEqual (42, (int) h["Int"], "#3");
49 Assert.AreEqual (PlatformID.Win32NT, (PlatformID) h["Enum"], "#4");
50 Assert.AreEqual (43, ((Point) h["Convertible"]).X, "#5");
51 Assert.AreEqual (2, (byte) ((ArrayList) h["Serializable"])[1], "#6");
52 Assert.AreEqual (13, ((byte[]) h["ByteArray"])[1], "#7");
53 Assert.AreEqual (16, ((byte[]) h["ByteArray2"])[1], "#8");
54 Assert.AreEqual (1013, ((int[]) h["IntArray"])[1], "#9");
55 Assert.AreEqual ("world", ((string[]) h["StringArray"])[1], "#10");
57 File.Delete (fileName);