2 // IsolatedStorageTest.cs - Unit Tests for abstract IsolatedStorage class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Security;
32 using System.Security.Permissions;
33 using System.IO.IsolatedStorage;
35 using NUnit.Framework;
37 namespace MonoTests.System.IO.IsolatedStorageTest {
39 // note: IsolatedStorage is abstract so we create a
40 // non-abstract class to test it
42 // naming a class with the same name as a namespace is a BAD idea
43 public class NonAbstractIsolatedStorage : global::System.IO.IsolatedStorage.IsolatedStorage
45 public NonAbstractIsolatedStorage ()
50 public NonAbstractIsolatedStorage (IsolatedStorageScope scope, Type domain, Type assembly)
52 InitStore (scope, domain, assembly);
55 public NonAbstractIsolatedStorage(IsolatedStorageScope scope, Type application)
57 InitStore (scope, application);
60 protected override IsolatedStoragePermission GetPermission (PermissionSet ps)
62 throw new NotImplementedException();
65 public override void Remove ()
67 throw new NotImplementedException();
70 public char PublicSeparatorExternal {
71 get { return base.SeparatorExternal; }
74 public char PublicSeparatorInternal {
75 get { return base.SeparatorInternal; }
80 public class IsolatedStorageTest {
83 [ExpectedException (typeof (ArgumentException))]
84 public void IsolatedStorage_Bad_Null ()
86 IsolatedStorageScope bad = (IsolatedStorageScope)Int32.MinValue;
87 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (bad, null, null);
91 [ExpectedException (typeof (ArgumentException))]
92 public void IsolatedStorage_None_Null ()
94 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.None, null, null);
98 [ExpectedException (typeof (ArgumentException))]
99 public void IsolatedStorage_None ()
101 Type t = typeof (object);
102 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.None, t, t);
106 [ExpectedException (typeof (ArgumentException))]
107 public void IsolatedStorage_User ()
109 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.User, null, null);
113 [ExpectedException (typeof (ArgumentException))]
114 public void IsolatedStorage_Domain ()
116 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Domain, null, null);
120 [ExpectedException (typeof (ArgumentException))]
121 public void IsolatedStorage_Assembly ()
123 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Assembly, null, null);
127 [ExpectedException (typeof (ArgumentException))]
128 public void IsolatedStorage_Roaming ()
130 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Roaming, null, null);
134 [ExpectedException (typeof (ArgumentException))]
135 public void IsolatedStorage_Machine ()
137 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Machine, null, null);
142 [ExpectedException (typeof (IsolatedStorageException))]
144 public void IsolatedStorage_Application ()
146 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Application, null);
150 [ExpectedException (typeof (NotImplementedException))]
151 public void IsolatedStorage_AssemblyUser ()
153 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Assembly | IsolatedStorageScope.User, null, null);
157 [ExpectedException (typeof (NotImplementedException))]
158 public void IsolatedStorage_AssemblyUserDomain ()
160 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Assembly | IsolatedStorageScope.User | IsolatedStorageScope.Domain, null, null);
164 public void IsolatedStorage ()
166 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
167 Assert.AreEqual (IsolatedStorageScope.None, nais.Scope, "Scope");
168 Assert.AreEqual (Path.DirectorySeparatorChar, nais.PublicSeparatorExternal, "SeparatorExternal");
169 Assert.AreEqual ('.', nais.PublicSeparatorInternal, "SeparatorInternal");
172 [ExpectedException (typeof (InvalidOperationException))]
173 public void IsolatedStorage_ApplicationIdentity ()
175 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
176 object o = nais.ApplicationIdentity;
180 [ExpectedException (typeof (InvalidOperationException))]
181 public void IsolatedStorage_AssemblyIdentity ()
183 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
184 object o = nais.AssemblyIdentity;
188 [ExpectedException (typeof (InvalidOperationException))]
189 public void IsolatedStorage_CurrentSize ()
191 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
192 ulong ul = nais.CurrentSize;
196 [ExpectedException (typeof (InvalidOperationException))]
197 public void IsolatedStorage_DomainIdentity ()
199 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
200 object o = nais.DomainIdentity;
204 [ExpectedException (typeof (InvalidOperationException))]
205 public void IsolatedStorage_MaximumSize ()
207 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
208 ulong ul = nais.MaximumSize;
212 public void MultiLevel ()
215 IsolatedStorageFile isf;
217 isf = IsolatedStorageFile.GetUserStoreForApplication ();
219 isf = IsolatedStorageFile.GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain,
220 typeof (global::System.Security.Policy.Url), typeof (global::System.Security.Policy.Url));
224 isf.CreateDirectory ("dir1");
225 string [] dirs = isf.GetDirectoryNames ("*");
226 Assert.AreEqual (1, dirs.Length, "1a");
227 Assert.AreEqual ("dir1", dirs [0], "1b");
229 isf.CreateDirectory ("dir1/test");
230 dirs = isf.GetDirectoryNames ("dir1/*");
231 Assert.AreEqual (1, dirs.Length, "2a");
232 Assert.AreEqual ("test", dirs [0], "2b");
234 isf.CreateDirectory ("dir1/test/test2a");
235 isf.CreateDirectory ("dir1/test/test2b");
236 dirs = isf.GetDirectoryNames ("dir1/test/*");
237 Assert.AreEqual (2, dirs.Length, "3a");
238 Assert.AreEqual ("test2a", dirs [0], "3b");
239 Assert.AreEqual ("test2b", dirs [1], "3c");
241 isf.DeleteDirectory ("dir1/test/test2a");
242 isf.DeleteDirectory ("dir1/test/test2b");
243 isf.DeleteDirectory ("dir1/test");
244 isf.DeleteDirectory ("dir1");
249 [ExpectedException (typeof (InvalidOperationException))]
250 public void IsolatedStorage_UsedSize ()
252 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
253 Console.WriteLine (nais.UsedSize);
257 [ExpectedException (typeof (InvalidOperationException))]
258 public void IsolatedStorage_AvailableFreeSpace ()
260 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
261 Console.WriteLine (nais.AvailableFreeSpace);
265 [ExpectedException (typeof (InvalidOperationException))]
266 public void IsolatedStorage_Quota ()
268 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
269 Console.WriteLine (nais.Quota);
273 public void IsolatedStorage_IncreaseQuotaTo ()
275 NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
276 Assert.AreEqual (false, nais.IncreaseQuotaTo (-10), "#A0");
277 Assert.AreEqual (false, nais.IncreaseQuotaTo (0), "#A1");
278 Assert.AreEqual (false, nais.IncreaseQuotaTo (100), "#A2");