Make System.Drawing unit tests use Assert.Throws instead of [ExpectedException] ...
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestImage.cs
index e064a4337a3e551072f28241e66773d459380806..c53d061bad056434bb99b5d5871f1cc8fe2155dc 100644 (file)
@@ -69,10 +69,9 @@ namespace MonoTests.System.Drawing{
                }
 
                [Test]
-               [ExpectedException (typeof (FileNotFoundException))]
                public void FileDoesNotExists ()
                {
-                       Image.FromFile ("FileDoesNotExists.jpg");
+                       Assert.Throws<FileNotFoundException> (() => Image.FromFile ("FileDoesNotExists.jpg"));
                }
 
                private bool CallbackTrue ()
@@ -101,20 +100,18 @@ namespace MonoTests.System.Drawing{
                }
 
                [Test]
-               [ExpectedException (typeof (OutOfMemoryException))]
                public void GetThumbnailImage_Height_Zero ()
                {
                        using (Bitmap bmp = new Bitmap (10, 10)) {
-                               Image tn = bmp.GetThumbnailImage (5, 0, new Image.GetThumbnailImageAbort (CallbackFalse), IntPtr.Zero);
+                               Assert.Throws<OutOfMemoryException> (() => bmp.GetThumbnailImage (5, 0, new Image.GetThumbnailImageAbort (CallbackFalse), IntPtr.Zero));
                        }
                }
 
                [Test]
-               [ExpectedException (typeof (OutOfMemoryException))]
                public void GetThumbnailImage_Width_Negative ()
                {
                        using (Bitmap bmp = new Bitmap (10, 10)) {
-                               Image tn = bmp.GetThumbnailImage (-5, 5, new Image.GetThumbnailImageAbort (CallbackFalse), IntPtr.Zero);
+                               Assert.Throws<OutOfMemoryException> (() => bmp.GetThumbnailImage (-5, 5, new Image.GetThumbnailImageAbort (CallbackFalse), IntPtr.Zero));
                        }
                }
 
@@ -245,13 +242,12 @@ namespace MonoTests.System.Drawing{
 
                [Test]
                [Category ("NotWorking")] // https://bugzilla.novell.com/show_bug.cgi?id=338779
-               [ExpectedException (typeof (ArgumentException))]
                public void FromStream_Metafile_Wmf_NotOrigin ()
                {
                        string filename = TestBitmap.getInFile ("bitmaps/telescope_01.wmf");
                        using (FileStream fs = File.OpenRead (filename)) {
                                fs.Position = fs.Length / 2;
-                               Image.FromStream (fs);
+                               Assert.Throws<ArgumentException> (() => Image.FromStream (fs));
                        }
                }
 
@@ -287,31 +283,28 @@ namespace MonoTests.System.Drawing{
 
                [Test]
                [Category ("NotWorking")] // https://bugzilla.novell.com/show_bug.cgi?id=338779
-               [ExpectedException (typeof (ArgumentException))]
                public void FromStream_Metafile_Emf_NotOrigin ()
                {
                        string filename = TestBitmap.getInFile ("bitmaps/milkmateya01.emf");
                        using (FileStream fs = File.OpenRead (filename)) {
                                fs.Position = fs.Length / 2;
-                               Image.FromStream (fs);
+                               Assert.Throws<ArgumentException> (() => Image.FromStream (fs));
                        }
                }
 
                [Test]
-               [ExpectedException (typeof (OutOfMemoryException))]
                public void FromFile_Invalid ()
                {
                        string filename = Assembly.GetExecutingAssembly ().Location;
-                       Image.FromFile (filename);
+                       Assert.Throws<OutOfMemoryException> (() => Image.FromFile (filename));
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void FromStream_Invalid ()
                {
                        string filename = Assembly.GetExecutingAssembly ().Location;
                        using (FileStream fs = File.OpenRead (filename)) {
-                               Image.FromStream (fs);
+                               Assert.Throws<ArgumentException> (() => Image.FromStream (fs));
                        }
                }
 
@@ -350,7 +343,6 @@ namespace MonoTests.System.Drawing{
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void StreamJunkSaveLoad ()
                {
                        using (MemoryStream ms = new MemoryStream ()) {
@@ -363,7 +355,7 @@ namespace MonoTests.System.Drawing{
                                        bmp.Save (ms, ImageFormat.Bmp);
                                        Assert.IsTrue (ms.Position > 2, "Position-2");
                                        // exception here
-                                       Image.FromStream (ms);
+                                       Assert.Throws<ArgumentException> (() => Image.FromStream (ms));
                                }
                        }
                }