-//\r
-// MonoTests.System.Resources.ResourceReaderTest.cs\r
-//\r
-// Author:\r
-// Nick Drochak (ndrochak@gol.com)\r
-//\r
-// (C) 2001 Nick Drochak II\r
-//\r
-\r
-\r
-using System;\r
-using System.Resources;\r
+//
+// MonoTests.System.Resources.ResourceReaderTest.cs
+//
+// Author:
+// Nick Drochak (ndrochak@gol.com)
+//
+// (C) 2001 Nick Drochak II
+// Copyright (C) 2004 Novell (http://www.novell.com)
+//
+
+using System;
+using System.Collections;
using System.IO;
-\r
-using System.Collections;\r
-using MonoTests.System.Resources;\r
-using NUnit.Framework;\r
-\r
-namespace MonoTests.System.Resources {\r
-\r
- public class ResourceReaderTest : TestCase {\r
- private static string m_ResourceFile = "resources" + Path.DirectorySeparatorChar + "MyResources.resources";\r
- private static string m_BadResourceFile = "resources" + Path.DirectorySeparatorChar + "Empty.resources";\r
- \r
- public ResourceReaderTest() : base ("MonoTests.System.Resources.ResourceReaderTest testcase") { }\r
- public ResourceReaderTest(String name) : base(name) {\r
- }\r
- \r
- public static ITest Suite {\r
- get {\r
- return new TestSuite(typeof(ResourceReaderTest));\r
- }\r
- }\r
-\r
- protected override void SetUp() {\r
- }\r
-\r
- public void TestConstructorStringExceptions() {\r
- ResourceReader r;\r
- try {\r
- r = new ResourceReader((String)null);\r
- Fail("Should throw exception on null");\r
- } catch{}\r
- try {\r
- r = new ResourceReader("");\r
- Fail("Should throw exception on empty path");\r
- } catch{}\r
- try {\r
- // use a file name that is *very* unlikely to exsist\r
- r = new ResourceReader("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");\r
- Fail("Should throw exception on file not found");\r
- } catch{}\r
- try {\r
- r = new ResourceReader(m_BadResourceFile);\r
- Fail("Should throw exception on bad resource file");\r
- }\r
- catch {}\r
- }\r
-\r
- public void TestConstructorString() {\r
- if (!File.Exists(m_ResourceFile)) {\r
- Fail("Resource file is not where it should be:" + Directory.GetCurrentDirectory()+ "\\" + m_ResourceFile);\r
- }\r
- ResourceReader r = null;\r
- try {\r
- r = new ResourceReader(m_ResourceFile);\r
- }\r
- catch {\r
- Fail("Should have been able to open resource file.");\r
- }\r
- finally {\r
- if (null != r)\r
- r.Close();\r
- }\r
- Assert("String constructor should not be null", null != r);\r
- }\r
-\r
- public void TestConstructorStreamExceptions() {\r
- ResourceReader r;\r
- try {\r
- r = new ResourceReader((Stream)null);\r
- Fail("Should throw exception on null");\r
- } catch{}\r
-\r
- try {\r
- Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
- stream.Close();\r
- r = new ResourceReader(stream);\r
- Fail("Should throw exception on cannot read");\r
- } catch{}\r
- }\r
-\r
- public void TestStream(){\r
- ResourceReader r = null;\r
- try {\r
- Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
- r = new ResourceReader(stream);\r
- } \r
- catch{\r
- Fail("Should not throw exception constructing from stream");\r
- }\r
- finally {\r
- if (null != r) {\r
- r.Close();\r
- }\r
- }\r
- }\r
-\r
- public void TestClose() {\r
- ResourceReader r = null;\r
- Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
- r = new ResourceReader(stream);\r
- r.Close();\r
- try {\r
- stream = new FileStream (m_ResourceFile, FileMode.Open);\r
- } \r
- catch{\r
- Fail("Should be able to open the stream again after close");\r
- }\r
- finally {\r
- if (null != stream) {\r
- stream.Close();\r
- }\r
- }\r
- }\r
-\r
- public void TestEnumerator(){\r
- ResourceReader reader = null;\r
- Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
- reader = new ResourceReader(stream);\r
- IDictionaryEnumerator en = reader.GetEnumerator();\r
- // Goes through the enumerator, printing out the key and value pairs.\r
- while (en.MoveNext()) {\r
- DictionaryEntry de = (DictionaryEntry)en.Current;\r
- Assert("Current.Key should not be empty",String.Empty != (string)de.Key);\r
- Assert("Current.Value should not be empty",String.Empty != (string)de.Value);\r
- Assert("Current.Value should not be empty",String.Empty != (string)de.Value);\r
- Assert("Entry.Key should not be empty",String.Empty != (string)en.Key);\r
- Assert("Entry.Value should not be empty",String.Empty != (string)en.Value);\r
- }\r
- reader.Close();\r
- }\r
- } // class ResourceReaderTest\r
-} // namespace MonoTests.System.Resources
\ No newline at end of file
+using System.Reflection;
+using System.Resources;
+using NUnit.Framework;
+
+namespace MonoTests.System.Resources {
+
+ [TestFixture]
+ public class ResourceReaderTest : Assertion {
+ internal static string m_ResourceFile;
+ private static string m_BadResourceFile;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ char ds = Path.DirectorySeparatorChar;
+ if (ds == '/') {
+ FileInfo code_base = new FileInfo (Assembly.GetExecutingAssembly ().Location);
+ string base_path = Path.Combine (code_base.Directory.FullName, Path.Combine ("Test", "resources"));
+ m_ResourceFile = Path.Combine (base_path, "MyResources.resources");
+ m_BadResourceFile = Path.Combine (base_path, "Empty.resources");
+ } else {
+ m_ResourceFile = Path.Combine ("Test", Path.Combine ("resources","MyResources.resources"));
+ m_BadResourceFile = "resources" + ds + "Empty.resources";
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorString_Null ()
+ {
+ string s = null;
+ ResourceReader r = new ResourceReader (s);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ConstructorString_Empty ()
+ {
+ ResourceReader r = new ResourceReader (String.Empty);
+ }
+
+
+ [Test]
+ [ExpectedException (typeof (FileNotFoundException))]
+ public void ConstructorString_NotFound ()
+ {
+ // use a file name that is *very* unlikely to exsist
+ ResourceReader r = new ResourceReader("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");
+ }
+
+ [Test]
+ [Ignore("Not covered in the docs, not sure what the correct behavior should be for this")]
+ [ExpectedException (typeof (DirectoryNotFoundException))]
+ public void ConstructorString_Bad ()
+ {
+ Assert (File.Exists (m_BadResourceFile));
+ ResourceReader r = new ResourceReader(m_BadResourceFile);
+ }
+
+ [Test]
+ public void ConstructorString ()
+ {
+ if (!File.Exists(m_ResourceFile)) {
+ Fail ("Resource file is not where it should be:" + Path.Combine (Directory.GetCurrentDirectory(), m_ResourceFile));
+ }
+ ResourceReader r = new ResourceReader(m_ResourceFile);
+ AssertNotNull ("ResourceReader", r);
+ r.Close();
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorStream_Null ()
+ {
+ Stream s = null;
+ ResourceReader r = new ResourceReader (s);
+ Fail("Should throw exception on null");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ConstructorStream_Closed ()
+ {
+ Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
+ stream.Close ();
+ ResourceReader r = new ResourceReader (stream);
+ }
+
+ [Test]
+ public void Stream ()
+ {
+ Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
+ ResourceReader r = new ResourceReader (stream);
+ AssertNotNull ("ResourceReader", r);
+ r.Close();
+ }
+
+ [Test]
+ public void Close ()
+ {
+ Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
+ ResourceReader r = new ResourceReader (stream);
+ r.Close ();
+
+ stream = new FileStream (m_ResourceFile, FileMode.Open);
+ AssertNotNull ("FileStream", stream);
+ stream.Close ();
+ }
+
+ [Test]
+ public void Enumerator ()
+ {
+ Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
+ ResourceReader reader = new ResourceReader (stream);
+
+ IDictionaryEnumerator en = reader.GetEnumerator();
+ // Goes through the enumerator, printing out the key and value pairs.
+ while (en.MoveNext()) {
+ DictionaryEntry de = (DictionaryEntry)en.Current;
+ Assert("Current.Key should not be empty",String.Empty != (string)de.Key);
+ Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
+ Assert("Entry.Key should not be empty",String.Empty != (string)en.Key);
+ Assert("Entry.Value should not be empty",String.Empty != (string)en.Value);
+ }
+ reader.Close();
+ }
+ } // class ResourceReaderTest
+} // namespace MonoTests.System.Resources