1 // FileStreamSafeHandleTests.cs - Test Cases for System.IO.FileStream class
4 // Marcos Henrich (marcos.henrich@xamarin.com)
6 // Copyright 2015 Xamarin Inc (http://www.xamarin.com).
11 using System.Security.AccessControl;
12 using System.Threading;
13 using NUnit.Framework;
15 namespace MonoTests.System.IO
18 public class FileStreamWithClosedSafeHandleTests
21 private FileStream GetFileStreamWithClosedHandle ()
23 var fs1 = new FileStream ("test2", FileMode.OpenOrCreate);
24 var fs2 = new FileStream (fs1.SafeFileHandle, FileAccess.Read);
31 [ExpectedException (typeof (ObjectDisposedException))]
32 public void GetLength ()
34 var fs = GetFileStreamWithClosedHandle ();
40 [ExpectedException (typeof (ObjectDisposedException))]
41 public void GetPosition ()
43 var fs = GetFileStreamWithClosedHandle ();
49 [ExpectedException (typeof (ObjectDisposedException))]
50 public void SetPosition ()
52 var fs = GetFileStreamWithClosedHandle ();
58 [ExpectedException (typeof (ObjectDisposedException))]
59 public void GetAccessControl ()
61 var fs = GetFileStreamWithClosedHandle ();
63 fs.GetAccessControl ();
67 [ExpectedException (typeof (ObjectDisposedException))]
68 public void SetAccessControl ()
70 var fs = GetFileStreamWithClosedHandle ();
72 fs.SetAccessControl (new FileSecurity ());
76 [ExpectedException (typeof (ObjectDisposedException))]
79 var fs = GetFileStreamWithClosedHandle ();
85 [ExpectedException (typeof (ObjectDisposedException))]
86 public void SetLength ()
88 var fs = GetFileStreamWithClosedHandle ();
94 [ExpectedException (typeof (ObjectDisposedException))]
97 var fs = GetFileStreamWithClosedHandle ();
99 fs.Read (new byte [2], 0, 1);
103 [ExpectedException (typeof (ObjectDisposedException))]
106 var fs = GetFileStreamWithClosedHandle ();
108 fs.Seek (0, SeekOrigin.Begin);
112 [ExpectedException (typeof (ObjectDisposedException))]
115 var fs = GetFileStreamWithClosedHandle ();
117 fs.Write (new byte [2], 0, 1);
121 [ExpectedException (typeof (ObjectDisposedException))]
122 public void ReadByte ()
124 var fs = GetFileStreamWithClosedHandle ();
130 [ExpectedException (typeof (ObjectDisposedException))]
131 public void WriteByte ()
133 var fs = GetFileStreamWithClosedHandle ();
139 [ExpectedException (typeof (ObjectDisposedException))]
142 var fs = GetFileStreamWithClosedHandle ();
148 [ExpectedException (typeof (ObjectDisposedException))]
149 public void UnLock ()
151 var fs = GetFileStreamWithClosedHandle ();
157 [ExpectedException (typeof (ObjectDisposedException))]
158 public void ReadAsync ()
160 var fs = GetFileStreamWithClosedHandle ();
162 fs.ReadAsync (new byte [2], 0, 1);
166 [ExpectedException (typeof (ObjectDisposedException))]
167 public void WriteAsync ()
169 var fs = GetFileStreamWithClosedHandle ();
171 fs.WriteAsync (new byte [2], 0, 1);
175 [ExpectedException (typeof (ObjectDisposedException))]
176 public void FlushAsync ()
178 var fs = GetFileStreamWithClosedHandle ();
180 fs.FlushAsync (new CancellationToken ());