2 // IsolatedStorageFileStreamTest.cs
3 // - Unit Tests for abstract IsolatedStorageFileStream class
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.IO.IsolatedStorage;
34 using Microsoft.Win32.SafeHandles;
37 using NUnit.Framework;
39 namespace MonoTests.System.IO.IsolatedStorageTests {
42 public class IsolatedStorageFileStreamTest {
44 private void CheckCommonDetails (string prefix, IsolatedStorageFileStream isfs, bool read, bool write)
46 Assert.AreEqual (read, isfs.CanRead, prefix + ".CanRead");
47 Assert.IsTrue (isfs.CanSeek, prefix + ".CanSeek");
48 Assert.AreEqual (write, isfs.CanWrite, prefix + ".CanWrite");
49 Assert.IsFalse (isfs.IsAsync, prefix + ".IsAsync");
50 Assert.AreEqual (0, isfs.Length, prefix + ".Length");
51 Assert.AreEqual ("[Unknown]", isfs.Name, prefix + ".Name");
52 Assert.AreEqual (0, isfs.Position, prefix + ".Position");
54 Assert.IsFalse (isfs.CanTimeout, prefix + ".CanTimeout");
59 [ExpectedException (typeof (ArgumentNullException))]
60 public void Constructor_StringNullMode ()
62 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (null, FileMode.CreateNew);
66 [Category ("NotWorking")]
67 [ExpectedException (typeof (ArgumentException))] // Mono's FileStream throw an ArgumentOutOfRangeException
68 public void Constructor_StringModeBad ()
70 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("badmode", (FileMode)Int32.MinValue);
74 public void Constructor_StringMode ()
76 string test = "string-filemode";
77 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (test, FileMode.Create);
78 CheckCommonDetails (test, isfs, true, true);
82 [ExpectedException (typeof (ArgumentOutOfRangeException))]
83 public void Constructor_StringModeAccessBad ()
85 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("badaccess", FileMode.Create, (FileAccess)Int32.MinValue);
89 public void Constructor_StringModeAccess ()
91 string test = "string-filemode-fileaccess";
92 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (test, FileMode.Create, FileAccess.ReadWrite);
93 CheckCommonDetails (test, isfs, true, true);
97 [ExpectedException (typeof (ArgumentOutOfRangeException))]
98 public void Constructor_StringModeAccessShareBad ()
100 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("badshare", FileMode.Create, FileAccess.Read, (FileShare)Int32.MinValue);
104 public void Constructor_StringModeAccessShare ()
106 string test = "string-filemode-fileaccess-fileshare";
107 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (test, FileMode.Create, FileAccess.Write, FileShare.Read);
108 CheckCommonDetails (test, isfs, false, true);
112 [ExpectedException (typeof (IsolatedStorageException))]
113 public void Handle ()
115 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("handle", FileMode.Create);
116 IntPtr p = isfs.Handle;
120 [ExpectedException (typeof (IsolatedStorageException))]
121 public void SafeFileHandle_ ()
123 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("safeFileHandle", FileMode.Create);
124 SafeFileHandle sfh = isfs.SafeFileHandle;
128 [ExpectedException (typeof (InvalidOperationException))]
129 public void ReadTimeOut ()
131 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("readTimeout", FileMode.Create);
132 int t = isfs.ReadTimeout;
136 [ExpectedException (typeof (InvalidOperationException))]
137 public void WriteTimeOut ()
139 IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("writeTimeout", FileMode.Create);
140 int t = isfs.WriteTimeout;