// Nick Drochak (ndrochak@gol.com)\r
//\r
// (C) 2001 Nick Drochak II\r
+// Copyright (C) 2004 Novell (http://www.novell.com)\r
//\r
\r
-\r
using System;\r
using System.Collections;\r
using System.IO;\r
\r
[TestFixture]\r
public class ResourceReaderTest : Assertion {\r
- private static string m_Path = "resources" + Path.DirectorySeparatorChar;\r
- private static string m_ResourceFile = m_Path + "MyResources.resources";\r
- private static string m_BadResourceFile = m_Path + "Empty.resources";\r
+ private static string m_ResourceFile;\r
+ private static string m_BadResourceFile;\r
\r
- [Test]\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
+ [TestFixtureSetUp]\r
+ public void FixtureSetUp ()\r
+ {\r
+ char ds = Path.DirectorySeparatorChar;\r
+ if (ds == '/') {\r
+ FileInfo code_base = new FileInfo (Assembly.GetExecutingAssembly ().Location);\r
+ string base_path = code_base.Directory.FullName + ds + "Test" + ds + "resources" + ds;\r
+ m_ResourceFile = base_path + "MyResources.resources";\r
+ m_BadResourceFile = base_path + "Empty.resources";\r
+ } else {\r
+ m_ResourceFile = "resources" + ds + "MyResources.resources";\r
+ m_BadResourceFile = "resources" + ds + "Empty.resources";\r
}\r
- catch {}\r
}\r
\r
[Test]\r
- public void TestConstructorString() {\r
- if (!File.Exists(m_ResourceFile)) {\r
- Fail("Resource file is not where it should be:" + 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
+ [ExpectedException (typeof (ArgumentNullException))]\r
+ public void ConstructorString_Null () \r
+ {\r
+ string s = null;\r
+ ResourceReader r = new ResourceReader (s);\r
}\r
\r
[Test]\r
- public void TestConstructorStreamException1() {\r
- ResourceReader r;\r
- try {\r
- r = new ResourceReader((Stream)null);\r
- Fail("Should throw exception on null");\r
- } catch{}\r
+ [ExpectedException (typeof (ArgumentException))]\r
+ public void ConstructorString_Empty () \r
+ {\r
+ ResourceReader r = new ResourceReader (String.Empty);\r
}\r
\r
- [Ignore("makes mono throw an NullReferenceException")]\r
+\r
[Test]\r
- public void TestConstructorStreamException2() {\r
- ResourceReader 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
+ [ExpectedException (typeof (FileNotFoundException))]\r
+ public void ConstructorString_NotFound () \r
+ {\r
+ // use a file name that is *very* unlikely to exsist\r
+ ResourceReader r = new ResourceReader("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");\r
}\r
\r
[Test]\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
+ [ExpectedException (typeof (ArgumentException))]\r
+ public void ConstructorString_Bad () \r
+ {\r
+ ResourceReader r = new ResourceReader(m_BadResourceFile);\r
+ }\r
+\r
+ [Test]\r
+ public void ConstructorString () \r
+ {\r
+ if (!File.Exists(m_ResourceFile)) {\r
+ Fail ("Resource file is not where it should be:" + m_ResourceFile);\r
}\r
+ ResourceReader r = new ResourceReader(m_ResourceFile);\r
+ AssertNotNull ("ResourceReader", r);\r
+ r.Close();\r
}\r
\r
[Test]\r
- public void TestClose() {\r
- ResourceReader r = null;\r
+ [ExpectedException (typeof (ArgumentNullException))]\r
+ public void ConstructorStream_Null ()\r
+ {\r
+ Stream s = null;\r
+ ResourceReader r = new ResourceReader (s);\r
+ Fail("Should throw exception on null");\r
+ }\r
+\r
+ [Test]\r
+ [ExpectedException (typeof (ArgumentException))]\r
+ public void ConstructorStream_Closed ()\r
+ {\r
Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
- r = new ResourceReader(stream);\r
+ stream.Close ();\r
+ ResourceReader r = new ResourceReader (stream);\r
+ }\r
+\r
+ [Test]\r
+ public void Stream ()\r
+ {\r
+ Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
+ ResourceReader r = new ResourceReader (stream);\r
+ AssertNotNull ("ResourceReader", r);\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
[Test]\r
- public void TestEnumerator(){\r
- ResourceReader reader = null;\r
+ public void Close () \r
+ {\r
Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
- reader = new ResourceReader(stream);\r
+ ResourceReader r = new ResourceReader (stream);\r
+ r.Close ();\r
+\r
+ stream = new FileStream (m_ResourceFile, FileMode.Open);\r
+ AssertNotNull ("FileStream", stream);\r
+ stream.Close ();\r
+ }\r
+\r
+ [Test]\r
+ public void Enumerator ()\r
+ {\r
+ Stream stream = new FileStream (m_ResourceFile, FileMode.Open);\r
+ ResourceReader reader = new ResourceReader (stream);\r
+\r
IDictionaryEnumerator en = reader.GetEnumerator();\r
// Goes through the enumerator, printing out the key and value pairs.\r
while (en.MoveNext()) {\r