2 // MonoTests.System.Resources.ResourceReaderTest.cs
\r
5 // Nick Drochak (ndrochak@gol.com)
\r
7 // (C) 2001 Nick Drochak II
\r
12 using System.Collections;
\r
14 using System.Reflection;
\r
15 using System.Resources;
\r
16 using NUnit.Framework;
\r
18 namespace MonoTests.System.Resources {
\r
21 public class ResourceReaderTest : Assertion {
\r
22 private static string m_Path = "resources" + Path.DirectorySeparatorChar;
\r
23 private static string m_ResourceFile = m_Path + "MyResources.resources";
\r
24 private static string m_BadResourceFile = m_Path + "Empty.resources";
\r
27 public void TestConstructorStringExceptions() {
\r
30 r = new ResourceReader((String)null);
\r
31 Fail("Should throw exception on null");
\r
34 r = new ResourceReader("");
\r
35 Fail("Should throw exception on empty path");
\r
38 // use a file name that is *very* unlikely to exsist
\r
39 r = new ResourceReader("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");
\r
40 Fail("Should throw exception on file not found");
\r
43 r = new ResourceReader(m_BadResourceFile);
\r
44 Fail("Should throw exception on bad resource file");
\r
50 public void TestConstructorString() {
\r
51 if (!File.Exists(m_ResourceFile)) {
\r
52 Fail("Resource file is not where it should be:" + m_ResourceFile);
\r
54 ResourceReader r = null;
\r
56 r = new ResourceReader(m_ResourceFile);
\r
59 Fail("Should have been able to open resource file.");
\r
65 Assert("String constructor should not be null", null != r);
\r
69 public void TestConstructorStreamException1() {
\r
72 r = new ResourceReader((Stream)null);
\r
73 Fail("Should throw exception on null");
\r
77 [Ignore("makes mono throw an NullReferenceException")]
\r
79 public void TestConstructorStreamException2() {
\r
82 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
84 r = new ResourceReader(stream);
\r
85 Fail("Should throw exception on cannot read");
\r
90 public void TestStream(){
\r
91 ResourceReader r = null;
\r
93 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
94 r = new ResourceReader(stream);
\r
97 Fail("Should not throw exception constructing from stream");
\r
107 public void TestClose() {
\r
108 ResourceReader r = null;
\r
109 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
110 r = new ResourceReader(stream);
\r
113 stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
116 Fail("Should be able to open the stream again after close");
\r
119 if (null != stream) {
\r
126 public void TestEnumerator(){
\r
127 ResourceReader reader = null;
\r
128 Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
\r
129 reader = new ResourceReader(stream);
\r
130 IDictionaryEnumerator en = reader.GetEnumerator();
\r
131 // Goes through the enumerator, printing out the key and value pairs.
\r
132 while (en.MoveNext()) {
\r
133 DictionaryEntry de = (DictionaryEntry)en.Current;
\r
134 Assert("Current.Key should not be empty",String.Empty != (string)de.Key);
\r
135 Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
\r
136 Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
\r
137 Assert("Entry.Key should not be empty",String.Empty != (string)en.Key);
\r
138 Assert("Entry.Value should not be empty",String.Empty != (string)en.Value);
\r
142 } // class ResourceReaderTest
\r
143 } // namespace MonoTests.System.Resources
\r