* StreamWriter.cs: Removed duplicate argument checks from .ctor taking
authorGert Driesen <drieseng@users.sourceforge.net>
Fri, 15 Aug 2008 21:18:10 +0000 (21:18 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Fri, 15 Aug 2008 21:18:10 +0000 (21:18 -0000)
path, as these checks are already done in FileStream .ctor. Removed
parameter name from ArgumentException to match MS.
* StreamWriterTest.cs: Moved ctor argument checks to separate methods.
Added and improved ctor tests. Added test for Close. Improved
(Auto)Flush tests. Use Assert class instead of Assertion.

svn path=/trunk/mcs/; revision=110610

mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/StreamWriter.cs
mcs/class/corlib/Test/System.IO/ChangeLog
mcs/class/corlib/Test/System.IO/StreamWriterTest.cs

index 95e38b003f1203b2ef46b98592661d154c14501e..46386ed575a893b53d2ef38fa3fb4764229c8f32 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-15  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * StreamWriter.cs: Removed duplicate argument checks from .ctor taking
+       path, as these checks are already done in FileStream .ctor. Removed
+       parameter name from ArgumentException to match MS.
+
 2008-07-28  Marek Safar <marek.safar@gmail.com>
 
        * File.cs: Delay DateTime .cctor invocation.
index dd785e3bb3557c62b12e233833ece22db150838e..9d9a29010be53561a0506bf680e9f25babe950f2 100644 (file)
@@ -85,7 +85,6 @@ namespace System.IO {
                                preamble_done = true;\r
                }\r
 \r
-               //[MonoTODO("Nothing is done with bufferSize")]\r
                public StreamWriter (Stream stream, Encoding encoding, int bufferSize) {\r
                        if (null == stream)\r
                                throw new ArgumentNullException("stream");\r
@@ -94,7 +93,7 @@ namespace System.IO {
                        if (bufferSize < 0)\r
                                throw new ArgumentOutOfRangeException("bufferSize");\r
                        if (!stream.CanWrite)\r
-                               throw new ArgumentException("Can not write to stream", "stream");\r
+                               throw new ArgumentException ("Can not write to stream");\r
 \r
                        internalStream = stream;\r
 \r
@@ -111,22 +110,11 @@ namespace System.IO {
                        : this (path, append, encoding, DefaultFileBufferSize) {}\r
                \r
                public StreamWriter (string path, bool append, Encoding encoding, int bufferSize) {\r
-                       if (null == path)\r
-                               throw new ArgumentNullException("path");\r
-                       if (String.Empty == path)\r
-                               throw new ArgumentException("path cannot be empty string");\r
-                       if (path.IndexOfAny (Path.InvalidPathChars) != -1)\r
-                               throw new ArgumentException("path contains invalid characters");\r
-\r
                        if (null == encoding)\r
                                throw new ArgumentNullException("encoding");\r
                        if (bufferSize < 0)\r
                                throw new ArgumentOutOfRangeException("bufferSize");\r
 \r
-                       string DirName = Path.GetDirectoryName(path);\r
-                       if (DirName != String.Empty && !Directory.Exists(DirName))\r
-                               throw new DirectoryNotFoundException();\r
-\r
                        FileMode mode;\r
 \r
                        if (append)\r
index 10addba293df02f032e3ec8b276d51be6d7ba22d..ded86336b867d7715e83662740ba0f4b07a9a857 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-15  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * StreamWriterTest.cs: Moved ctor argument checks to separate methods.
+       Added and improved ctor tests. Added test for Close. Improved
+       (Auto)Flush tests. Use Assert class instead of Assertion.
+
 2008-06-21  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * PathCas.cs: Updated method names to reflect changes in PathTest.
index 2d200f4e38e1f627f8f3e3918edbb101003e7d66..2bbb85491553ec49d437b78b93624477692dd6b4 100644 (file)
@@ -14,9 +14,8 @@ namespace MonoTests.System.IO
 {
 
 [TestFixture]
-public class StreamWriterTest : Assertion
+public class StreamWriterTest
 {
-
        static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
        private string _codeFileName = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
        private string _thisCodeFileName = TempFolder + Path.DirectorySeparatorChar + "StreamWriterTest.temp";
@@ -39,335 +38,370 @@ public class StreamWriterTest : Assertion
                        Directory.Delete (TempFolder, true);
        }
 
+       [Test] // .ctor (Stream)
+       public void Constructor1 ()
+       {
+               FileStream f = new FileStream(_codeFileName, 
+                                             FileMode.Append, 
+                                             FileAccess.Write);
+               StreamWriter r = new StreamWriter (f);
+               Assert.IsFalse (r.AutoFlush, "#1");
+               Assert.AreSame (f, r.BaseStream, "#2");
+               Assert.IsNotNull (r.Encoding, "#3");
+               Assert.AreEqual (typeof (UTF8Encoding), r.Encoding.GetType (), "#4");
+               r.Close();
+               f.Close();
+       }
 
-       // TODO - ctors
        [Test]
-       public void TestCtor1() {
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter((Stream)null);
-                       } catch (ArgumentNullException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 1: " + e.ToString());
-                       }
-                       Assert("null string error not thrown", errorThrown);
+       public void Constructor1_Stream_NotWritable ()
+       {
+               FileStream f = new FileStream (_thisCodeFileName, FileMode.Open,
+                       FileAccess.Read);
+               try {
+                       new StreamWriter (f);
+                       Assert.Fail ("#B1");
+               } catch (ArgumentException ex) {
+                       // Stream was not writable
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNull (ex.ParamName, "#5");
+               } finally {
+                       f.Close ();
                }
-               {
-                       bool errorThrown = false;
-                       FileStream f = new FileStream(_thisCodeFileName, 
-                                                     FileMode.Open, 
-                                                     FileAccess.Read);
-                       try {
-                               StreamWriter r = new StreamWriter(f);
-                               r.Close();
-                       } catch (ArgumentException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 2: " + e.ToString());
-                       }
-                       f.Close();
-                       Assert("no read error not thrown", errorThrown);
+       }
+
+       [Test] // .ctor (Stream)
+       public void Constructor1_Stream_Null ()
+       {
+               try {
+                       new StreamWriter((Stream) null);
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.AreEqual ("stream", ex.ParamName, "#5");
                }
-               {
-                       FileStream f = new FileStream(_codeFileName, 
-                                                     FileMode.Append, 
-                                                     FileAccess.Write);
-                       StreamWriter r = new StreamWriter(f);
-                       AssertNotNull("no stream writer", r);
-                       r.Close();
-                       f.Close();
+       }
+
+       [Test] // .ctor (String)
+       public void Constructor2 ()
+       {
+               // TODO - Security/Auth exceptions
+               using (StreamWriter r = new StreamWriter (_codeFileName)) {
+                       Assert.IsFalse (r.AutoFlush, "#1");
+                       Assert.IsNotNull (r.BaseStream, "#2");
+                       Assert.AreEqual (typeof (FileStream), r.BaseStream.GetType (), "#3");
+                       Assert.IsNotNull (r.Encoding, "#4");
+                       Assert.AreEqual (typeof (UTF8Encoding), r.Encoding.GetType (), "#5");
+                       r.Close ();
                }
        }
 
-       [Test]
-       public void TestCtor2() {
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("");
-                       } catch (ArgumentException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 1: " + e.ToString());
-                       }
-                       Assert("empty string error not thrown", errorThrown);
+       [Test] // .ctor (String)
+       public void Constructor2_Path_DirectoryNotFound ()
+       {
+               Directory.Delete (TempFolder, true);
+
+               try {
+                       new StreamWriter (_codeFileName);
+                       Assert.Fail ("#1");
+               } catch (DirectoryNotFoundException ex) {
+                       // Could not find a part of the path '...'
+                       Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsTrue (ex.Message.IndexOf (TempFolder) != -1, "#5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter((string)null);
-                       } catch (ArgumentNullException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 2: " + e.ToString());
-                       }
-                       Assert("null string error not thrown", errorThrown);
+       }
+
+       [Test] // .ctor (String)
+       public void Constructor2_Path_Empty ()
+       {
+               try {
+                       new StreamWriter (string.Empty);
+                       Assert.Fail ("#1");
+               } catch (ArgumentException ex) {
+                       // Empty path name is not legal
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNull (ex.ParamName, "#5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("nonexistentdir/file");
-                       } catch (DirectoryNotFoundException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 3: " + e.ToString());
-                       }
-                       Assert("dirNotFound error not thrown", errorThrown);
+       }
+
+       [Test] // .ctor (String)
+       public void Constructor2_Path_IllegalChars ()
+       {
+               try {
+                       new StreamWriter ("!$what? what? Huh? !$*#" + Path.InvalidPathChars [0]);
+                       Assert.Fail ("#1");
+               } catch (ArgumentException ex) {
+                       // Illegal characters in path
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNull (ex.ParamName, "#5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("!$what? what? Huh? !$*#" + Path.InvalidPathChars[0]);
-                       } catch (IOException) {
-                               errorThrown = true;
-                       } catch (ArgumentException) {
-                               // FIXME - the spec says 'IOExc', but the
-                               //   compiler says 'ArgExc'...
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 4: " + e.ToString());
-                       }
-                       Assert("1 invalid filename error not thrown", errorThrown);
+       }
+
+       [Test] // .ctor (String)
+       public void Constructor2_Path_Null ()
+       {
+               try {
+                       new StreamWriter ((string) null);
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.AreEqual ("path", ex.ParamName, "#5");
                }
-               // TODO - Security/Auth exceptions
-               {
-                       StreamWriter r = new StreamWriter(_codeFileName);
-                       AssertNotNull("no stream writer", r);
-                       r.Close();
+       }
+
+       [Test] // .ctor (String)
+       public void Constructor2_Path_Whitespace ()
+       {
+               try {
+                       new StreamWriter (" \r\n ");
+                       Assert.Fail ("#1");
+               } catch (ArgumentException ex) {
+                       // Illegal characters in path
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNull (ex.ParamName, "#5");
                }
        }
 
-       [Test]
-       public void TestCtor3() {
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("", false);
-                       } catch (ArgumentException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 1: " + e.ToString());
-                       }
-                       Assert("empty string error not thrown", errorThrown);
+       [Test] // .ctor (String, Boolean)
+       public void Constructor3 ()
+       {
+               using (StreamWriter r = new StreamWriter (_codeFileName, false)) {
+                       r.Close();
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter((string)null, false);
-                       } catch (ArgumentNullException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 2: " + e.ToString());
-                       }
-                       Assert("null string error not thrown", errorThrown);
+
+               using (StreamWriter r = new StreamWriter(_codeFileName, true)) {
+                       r.Close();
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("nonexistentdir/file", false);
-                       } catch (DirectoryNotFoundException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 3: " + e.ToString());
-                       }
-                       Assert("dirNotFound error not thrown", errorThrown);
+       }
+
+       [Test] // .ctor (String, Boolean)
+       public void Constructor3_Path_DirectoryNotFound ()
+       {
+               Directory.Delete (TempFolder, true);
+
+               try {
+                       new StreamWriter (_codeFileName, false);
+                       Assert.Fail ("#A1");
+               } catch (DirectoryNotFoundException ex) {
+                       // Could not find a part of the path '...'
+                       Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#A2");
+                       Assert.IsNull (ex.InnerException, "#A3");
+                       Assert.IsNotNull (ex.Message, "#A4");
+                       Assert.IsTrue (ex.Message.IndexOf (TempFolder) != -1, "#A5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("!$what? what? Huh? !$*#" + Path.InvalidPathChars[0], false);
-                       } catch (IOException) {
-                               errorThrown = true;
-                       } catch (ArgumentException) {
-                               // FIXME - the spec says 'IOExc', but the
-                               //   compiler says 'ArgExc'...
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 4: " + e.ToString());
-                       }
-                       Assert("2 invalid filename error not thrown", errorThrown);
+
+               try {
+                       new StreamWriter (_codeFileName, true);
+                       Assert.Fail ("#B1");
+               } catch (DirectoryNotFoundException ex) {
+                       // Could not find a part of the path '...'
+                       Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#B2");
+                       Assert.IsNull (ex.InnerException, "#B3");
+                       Assert.IsNotNull (ex.Message, "#B4");
+                       Assert.IsTrue (ex.Message.IndexOf (TempFolder) != -1, "#B5");
                }
-               {
-                       StreamWriter r = new StreamWriter(_codeFileName, false);
-                       AssertNotNull("no stream writer", r);
-                       r.Close();
+       }
+
+       [Test] // .ctor (String, Boolean)
+       public void Constructor3_Path_Empty ()
+       {
+               try {
+                       new StreamWriter (string.Empty, false);
+                       Assert.Fail ("#A1");
+               } catch (ArgumentException ex) {
+                       // Empty path name is not legal
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                       Assert.IsNull (ex.InnerException, "#A3");
+                       Assert.IsNotNull (ex.Message, "#A4");
+                       Assert.IsNull (ex.ParamName, "#A5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("", true);
-                       } catch (ArgumentException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 5: " + e.ToString());
-                       }
-                       Assert("empty string error not thrown", errorThrown);
+
+               try {
+                       new StreamWriter (string.Empty, true);
+                       Assert.Fail ("#B1");
+               } catch (ArgumentException ex) {
+                       // Empty path name is not legal
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                       Assert.IsNull (ex.InnerException, "#B3");
+                       Assert.IsNotNull (ex.Message, "#B4");
+                       Assert.IsNull (ex.ParamName, "#B5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter((string)null, true);
-                       } catch (ArgumentNullException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 6: " + e.ToString());
-                       }
-                       Assert("null string error not thrown", errorThrown);
+       }
+
+       [Test] // .ctor (String, Boolean)
+       public void Constructor3_Path_InvalidChars ()
+       {
+               try {
+                       new StreamWriter ("!$what? what? Huh? !$*#" + Path.InvalidPathChars [0], false);
+                       Assert.Fail ("#A1");
+               } catch (ArgumentException ex) {
+                       // Illegal characters in path
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                       Assert.IsNull (ex.InnerException, "#A3");
+                       Assert.IsNotNull (ex.Message, "#A4");
+                       Assert.IsNull (ex.ParamName, "#A5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("nonexistentdir/file", true);
-                       } catch (DirectoryNotFoundException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 7: " + e.ToString());
-                       }
-                       Assert("dirNotFound error not thrown", errorThrown);
+
+               try {
+                       new StreamWriter ("!$what? what? Huh? !$*#" + Path.InvalidPathChars [0], true);
+                       Assert.Fail ("#B1");
+               } catch (ArgumentException ex) {
+                       // Illegal characters in path
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                       Assert.IsNull (ex.InnerException, "#B3");
+                       Assert.IsNotNull (ex.Message, "#B4");
+                       Assert.IsNull (ex.ParamName, "#B5");
                }
-               {
-                       bool errorThrown = false;
-                       try {
-                               StreamWriter r = new StreamWriter("!$what? what? Huh? !$*#" + Path.InvalidPathChars[0], true);
-                       } catch (IOException) {
-                               errorThrown = true;
-                       } catch (ArgumentException) {
-                               // FIXME - the spec says 'IOExc', but the
-                               //   compiler says 'ArgExc'...
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 8: " + e.ToString());
-                       }
-                       Assert("3 invalid filename error not thrown", errorThrown);
+       }
+
+       [Test] // .ctor (String, Boolean)
+       public void Constructor3_Path_Null ()
+       {
+               try {
+                       new StreamWriter ((string) null, false);
+                       Assert.Fail ("#A1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                       Assert.IsNull (ex.InnerException, "#A3");
+                       Assert.IsNotNull (ex.Message, "#A4");
+                       Assert.AreEqual ("path", ex.ParamName, "#A5");
                }
-               {
-                       try {
-                               StreamWriter r = new StreamWriter(_codeFileName, true);
-                               AssertNotNull("no stream writer", r);
-                               r.Close();
-                       } catch (Exception e) {
-                               Fail ("Unxpected exception e=" + e.ToString());
-                       }
+
+               try {
+                       new StreamWriter ((string) null, true);
+                       Assert.Fail ("#B1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
+                       Assert.IsNull (ex.InnerException, "#B3");
+                       Assert.IsNotNull (ex.Message, "#B4");
+                       Assert.AreEqual ("path", ex.ParamName, "#B5");
                }
        }
 
        // TODO - ctors with Encoding
 
-       // TODO - AutoFlush
        [Test]
-       public void TestAutoFlush() {
-               {
-                       MemoryStream m = new MemoryStream();
-                       StreamWriter w = new StreamWriter(m);
-                       w.AutoFlush = false;
-                       w.Write(1);
-                       w.Write(2);
-                       w.Write(3);
-                       w.Write(4);
-                       AssertEquals("Should be nothing before flush",
-                                    0L, m.Length);
-                       w.Flush();
-                       AssertEquals("Should be something after flush",
-                                    4L, m.Length);
-               }               
-               {
-                       MemoryStream m = new MemoryStream();
-                       StreamWriter w = new StreamWriter(m);
-                       w.AutoFlush = true;
-                       w.Write(1);
-                       w.Write(2);
-                       w.Write(3);
-                       w.Write(4);
-                       AssertEquals("Should be something before flush",
-                                    4L, m.Length);
-                       w.Flush();
-                       AssertEquals("Should be something after flush",
-                                    4L, m.Length);
-               }               
+       public void AutoFlush ()
+       {
+               MemoryStream m;
+               StreamWriter w;
+
+               m = new MemoryStream ();
+               w = new StreamWriter (m);
+               w.Write (1);
+               w.Write (2);
+               w.Write (3);
+               w.Write (4);
+               Assert.AreEqual (0, m.Length, "#A1");
+               w.AutoFlush = true;
+               Assert.IsTrue (w.AutoFlush, "#A2");
+               Assert.AreEqual (4, m.Length, "#A3");
+               w.Flush ();
+               Assert.AreEqual (4, m.Length, "#A4");
+
+               m = new MemoryStream ();
+               w = new StreamWriter(m);
+               w.AutoFlush = true;
+               Assert.IsTrue (w.AutoFlush, "#B1");
+               w.Write (1);
+               w.Write (2);
+               w.Write (3);
+               w.Write (4);
+               Assert.AreEqual (4, m.Length, "#B2");
+               w.Flush ();
+               Assert.AreEqual (4, m.Length, "#B3");
+               w.AutoFlush = false;
+               Assert.IsFalse (w.AutoFlush, "#B4");
+               w.Write (4);
+               Assert.AreEqual (4, m.Length, "#B5");
+               w.Flush ();
+               Assert.AreEqual (5, m.Length, "#B6");
        }
 
        [Test]
-       public void TestBaseStream() {
-               FileStream f = new FileStream(_codeFileName, 
-                                             FileMode.Append, 
-                                             FileAccess.Write);
-               StreamWriter r = new StreamWriter(f);
-               AssertEquals("wrong base stream ", f, r.BaseStream);
-               r.Close();
-               f.Close();
+       [Category ("NotWorking")]
+       public void AutoFlush_Disposed ()
+       {
+               StreamWriter w;
+               
+               w = new StreamWriter (new MemoryStream ());
+               w.Close ();
+               w.AutoFlush = false;
+               Assert.IsFalse (w.AutoFlush, "#A1");
+               try {
+                       w.AutoFlush = true;
+                       Assert.Fail ("#A2");
+               } catch (ObjectDisposedException) {
+               }
+               Assert.IsTrue (w.AutoFlush, "#A3");
+
+               w = new StreamWriter (new MemoryStream ());
+               w.AutoFlush = true;
+               w.Close ();
+               Assert.IsTrue (w.AutoFlush, "#B1");
+               try {
+                       w.AutoFlush = true;
+                       Assert.Fail ("#B2");
+               } catch (ObjectDisposedException) {
+               }
+               Assert.IsTrue (w.AutoFlush, "#B3");
+               w.AutoFlush = false;
+               Assert.IsFalse (w.AutoFlush, "#B4");
        }
 
        [Test]
-       public void TestEncoding() {
-               StreamWriter r = new StreamWriter(_codeFileName);
-               AssertEquals("wrong encoding", 
-                            Encoding.UTF8.GetType(), r.Encoding.GetType());
-               r.Close();
+       public void Close ()
+       {
+               Encoding encoding = Encoding.ASCII;
+               MemoryStream m = new MemoryStream ();
+               StreamWriter w = new StreamWriter (m, encoding);
+               w.Write (2);
+               Assert.AreEqual (0, m.Length, "#1");
+               w.Close ();
+               Assert.IsFalse (m.CanWrite, "#2");
+               Assert.AreEqual (50, m.GetBuffer () [0], "#3");
+               Assert.IsNull (w.BaseStream, "#4");
+               Assert.IsNull (w.Encoding, "#5");
        }
 
-       // TODO - Close - not entirely sure how to test Close
-       //public void TestClose() {
-       //{
-       //MemoryStream m = new MemoryStream();
-       //StreamWriter w = new StreamWriter(m);
-       //StreamReader r = new StreamReader(m);
-       //w.Write(1);
-       //w.Write(2);
-       //w.Write(3);
-       //w.Write(4);
-       //AssertEquals("Should be nothing before close",
-       //0, m.Length);
-       //AssertEquals("Should be nothing in reader",
-       //-1, r.Peek());
-       //w.Close();
-       //AssertEquals("Should be something after close",
-       //1, r.Peek());
-        //}            
-       //}
-
-       // TODO - Flush
        [Test]
-       public void TestFlush() {
-               {
-                       bool errorThrown = false;
-                       try {
-                               FileStream f = new FileStream(_codeFileName, 
-                                                             FileMode.Append, 
-                                                             FileAccess.Write);
-                               StreamWriter r = new StreamWriter(f);
-                               r.Close();
-                               r.Flush();
-                       } catch (ObjectDisposedException) {
-                               errorThrown = true;
-                       } catch (Exception e) {
-                               Fail ("Incorrect exception thrown at 1: " + e.ToString());
-                       }
-                       Assert("can't flush closed error not thrown", errorThrown);
-               }
-               {
-                       MemoryStream m = new MemoryStream();
-                       StreamWriter w = new StreamWriter(m);
-                       w.Write(1);
-                       w.Write(2);
-                       w.Write(3);
-                       w.Write(4);
-                       AssertEquals("Should be nothing before flush",
-                                    0L, m.Length);
-                       w.Flush();
-                       AssertEquals("Should be something after flush",
-                                    4L, m.Length);
-               }               
+       public void Flush ()
+       {
+               MemoryStream m = new MemoryStream();
+               StreamWriter w = new StreamWriter(m);
+               w.Write(1);
+               w.Write(2);
+               w.Write(3);
+               w.Write(4);
+               Assert.AreEqual (0L, m.Length, "#1");
+               w.Flush();
+               Assert.AreEqual (4L, m.Length, "#2");
        }
 
        [Test]
-       [ExpectedException (typeof (ObjectDisposedException))]
-       public void AutoFlush_Disposed () 
+       public void Flush_Disposed ()
        {
-               StreamWriter w = new StreamWriter (new MemoryStream ());
-               w.Close ();
-               w.AutoFlush = true;
+               StreamWriter w = new StreamWriter(new MemoryStream ());
+               w.Close();
+               try {
+                       w.Flush ();
+                       Assert.Fail ("#1");
+               } catch (ObjectDisposedException) {
+               }
        }
 
        [Test]
@@ -390,7 +424,6 @@ public class StreamWriterTest : Assertion
        }
 
        [Test]
-       // accepted [ExpectedException (typeof (ArgumentNullException))]
        public void WriteCharArray_Null () 
        {
                char[] c = null;
@@ -426,7 +459,6 @@ public class StreamWriterTest : Assertion
        }
 
        [Test]
-       // accepted [ExpectedException (typeof (ArgumentNullException))]
        public void WriteString_Null () 
        {
                string s = null;
@@ -441,14 +473,13 @@ public class StreamWriterTest : Assertion
                StreamWriter w = new StreamWriter (ms, Encoding.UTF8);
                w.Write ("a");
                w.Flush ();
-               AssertEquals ("Incorrect size after writing 1 byte plus header", ms.Position, 4);
+               Assert.AreEqual (4, ms.Position, "#1");
 
                // Append 1 byte, should skip the preamble now.
                w.Write ("a");
                w.Flush ();
                w = new StreamWriter (ms, Encoding.UTF8);
-               AssertEquals ("Incorrect size after writing 1 byte, must have been 5", ms.Position, 5);
-               
+               Assert.AreEqual (5, ms.Position, "#2");
        }
        
        // TODO - Write - test errors, functionality tested in TestFlush.