2 // MonoTests.System.Resources.ResourceReaderTest.cs
\r
5 // Nick Drochak (ndrochak@gol.com)
\r
7 // (C) 2001 Nick Drochak II
\r
12 using System.Resources;
\r
15 using System.Collections;
\r
16 using MonoTests.System.Resources;
\r
17 using NUnit.Framework;
\r
19 namespace MonoTests.System.Resources {
\r
21 public class ResourceReaderTest : TestCase {
\r
22 private static string m_ResourceFile = "resources" + Path.DirectorySeparatorChar + "MyResources.resources";
\r
23 private static string m_BadResourceFile = "resources" + Path.DirectorySeparatorChar + "Empty.resources";
\r
25 public ResourceReaderTest() : base ("MonoTests.System.Resources.ResourceReaderTest testcase") { }
\r
26 public ResourceReaderTest(String name) : base(name) {
\r
29 public static ITest Suite {
\r
31 return new TestSuite(typeof(ResourceReaderTest));
\r
35 protected override void SetUp() {
\r
38 public void TestConstructorStringExceptions() {
\r
41 r = new ResourceReader((String)null);
\r
42 Fail("Should throw exception on null");
\r
45 r = new ResourceReader("");
\r
46 Fail("Should throw exception on empty path");
\r
49 // use a file name that is *very* unlikely to exsist
\r
50 r = new ResourceReader("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");
\r
51 Fail("Should throw exception on file not found");
\r
54 r = new ResourceReader(m_BadResourceFile);
\r
55 Fail("Should throw exception on bad resource file");
\r
60 public void TestConstructorString() {
\r
61 if (!File.Exists(m_ResourceFile)) {
\r
62 Fail("Resource file is not where it should be:" + Directory.GetCurrentDirectory()+ "\\" + m_ResourceFile);
\r
64 ResourceReader r = null;
\r
66 r = new ResourceReader(m_ResourceFile);
\r
69 Fail("Should have been able to open resource file.");
\r
75 Assert("String constructor should not be null", null != r);
\r
78 public void TestConstructorStreamExceptions() {
\r
81 r = new ResourceReader((Stream)null);
\r
82 Fail("Should throw exception on null");
\r
86 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
88 r = new ResourceReader(stream);
\r
89 Fail("Should throw exception on cannot read");
\r
93 public void TestStream(){
\r
94 ResourceReader r = null;
\r
96 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
97 r = new ResourceReader(stream);
\r
100 Fail("Should not throw exception constructing from stream");
\r
109 public void TestClose() {
\r
110 ResourceReader r = null;
\r
111 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
112 r = new ResourceReader(stream);
\r
115 stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
118 Fail("Should be able to open the stream again after close");
\r
121 if (null != stream) {
\r
127 public void TestEnumerator(){
\r
128 ResourceReader reader = null;
\r
129 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
130 reader = new ResourceReader(stream);
\r
131 IDictionaryEnumerator en = reader.GetEnumerator();
\r
132 // Goes through the enumerator, printing out the key and value pairs.
\r
133 while (en.MoveNext()) {
\r
134 DictionaryEntry de = (DictionaryEntry)en.Current;
\r
135 Assert("Current.Key should not be empty",String.Empty != (string)de.Key);
\r
136 Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
\r
137 Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
\r
138 Assert("Entry.Key should not be empty",String.Empty != (string)en.Key);
\r
139 Assert("Entry.Value should not be empty",String.Empty != (string)en.Value);
\r
143 } // class ResourceReaderTest
\r
144 } // namespace MonoTests.System.Resources