[System] UriKind.RelativeOrAbsolute workaround.
[mono.git] / mcs / class / corlib / Test / System.IO.IsolatedStorage / IsolatedStorageFileTest.cs
1 //
2 // IsolatedStorageFileTest.cs 
3 //      - Unit Tests for abstract IsolatedStorageFile class
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
9 // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Collections;
33 using System.IO;
34 using System.IO.IsolatedStorage;
35 using System.Reflection;
36 using System.Security;
37 using System.Security.Permissions;
38 using System.Security.Policy;
39
40 using NUnit.Framework;
41
42 namespace MonoTests.System.IO.IsolatedStorageTest {
43
44         [TestFixture]
45         public class IsolatedStorageFileTest {
46
47                 private const string dirname = "mono-unit-test";
48
49                 private void CheckEnumerated (int n, IsolatedStorageScope scope, IsolatedStorageFile isf)
50                 {
51                         string prefix = n.ToString () + " - " + scope.ToString () + " - ";
52                         Assert.IsNotNull (isf, prefix + "IsolatedStorageFile");
53                         Assert.IsTrue (((scope & isf.Scope) != 0), prefix + "Scope");
54
55                         if ((isf.Scope & IsolatedStorageScope.Assembly) != 0)
56                                 Assert.IsNotNull (isf.AssemblyIdentity, prefix + "AssemblyIdentity");
57                         if ((isf.Scope & IsolatedStorageScope.Domain) != 0)
58                                 Assert.IsNotNull (isf.DomainIdentity, prefix + "DomainIdentity");
59                         if ((isf.Scope & IsolatedStorageScope.Application) != 0)
60                                 Assert.IsNotNull (isf.ApplicationIdentity, prefix + "ApplicationIdentity");
61                 }
62
63                 private void GetEnumerator (IsolatedStorageScope scope)
64                 {
65                         IEnumerator e = IsolatedStorageFile.GetEnumerator (scope);
66                         int n = 0;
67                         while (e.MoveNext ())
68                         {
69                                 IsolatedStorageFile isf = (IsolatedStorageFile)e.Current;
70                                 CheckEnumerated (++n, scope, isf);
71                         }
72                 }
73
74                 [Test]
75                 public void GetEnumerator_User ()
76                 {
77                         GetEnumerator (IsolatedStorageScope.User);
78                 }
79
80                 [Test]
81                 [ExpectedException (typeof (ArgumentException))]
82                 public void GetEnumerator_User_Details ()
83                 {
84                         // giving more details is bad
85                         GetEnumerator (IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain);
86                 }
87
88                 [Test]
89                 public void GetEnumerator_UserRoaming ()
90                 {
91                         GetEnumerator (IsolatedStorageScope.User | IsolatedStorageScope.Roaming);
92                 }
93
94                 [Test]
95                 [ExpectedException (typeof (ArgumentException))]
96                 public void GetEnumerator_UserRoaming_Details ()
97                 {
98                         // giving more details is bad
99                         GetEnumerator (IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.Roaming);
100                 }
101                 [Test]
102                 public void GetEnumerator_Machine ()
103                 {
104                         GetEnumerator (IsolatedStorageScope.Machine);
105                 }
106
107                 [Test]
108                 [ExpectedException (typeof (ArgumentException))]
109                 public void GetEnumerator_Machine_Details ()
110                 {
111                         GetEnumerator (IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly);
112                 }
113
114                 [Test]
115                 [ExpectedException (typeof (ArgumentException))]
116                 public void GetEnumerator_Application ()
117                 {
118                         // we can't enum application
119                         GetEnumerator (IsolatedStorageScope.Application);
120                 }
121                 [Test]
122                 public void GetUserStoreForAssembly ()
123                 {
124                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
125                         Assert.AreEqual (Int64.MaxValue, isf.MaximumSize, "MaximumSize");
126                         Assert.AreEqual (IsolatedStorageScope.User | IsolatedStorageScope.Assembly, isf.Scope, "Scope");
127 #if !NET_2_1
128                         Assert.IsTrue ((isf.AssemblyIdentity is Url), "AssemblyIdentity");
129                         // note: mono transforms the CodeBase into uppercase
130                         // for net 1.1 which uses file:// and not file:///
131                         string codebase = Assembly.GetExecutingAssembly ().CodeBase.ToUpper ().Substring (8);
132                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().ToUpper ().IndexOf (codebase) > 0), "Url");
133                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().ToUpper ().IndexOf (codebase) > 0), "Url");
134 #endif
135                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
136                 }
137
138                 [Test]
139                 [ExpectedException (typeof (InvalidOperationException))]
140                 public void GetUserStoreForAssembly_DomainIdentity ()
141                 {
142                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
143                         object o = isf.DomainIdentity;
144                 }
145
146                 [Test]
147                 [ExpectedException (typeof (InvalidOperationException))]
148                 public void GetUserStoreForAssembly_ApplicationIdentity ()
149                 {
150                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
151                         object o = isf.ApplicationIdentity;
152                 }
153
154                 [Test]
155                 public void GetUserStoreForDomain ()
156                 {
157                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
158                         Assert.AreEqual (Int64.MaxValue, isf.MaximumSize, "MaximumSize");
159                         Assert.AreEqual (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, isf.Scope, "Scope");
160 #if !NET_2_1
161                         Assert.IsTrue ((isf.AssemblyIdentity is Url), "AssemblyIdentity");
162                         // note: mono transforms the CodeBase into uppercase
163                         // for net 1.1 which uses file:// and not file:///
164                         string codebase = Assembly.GetExecutingAssembly ().CodeBase.ToUpper ().Substring (8);
165                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().ToUpper ().IndexOf (codebase) > 0), "Url");
166                         Assert.IsTrue ((isf.DomainIdentity is Url), "DomainIdentity");
167                         // note: with MS Assembly.GetEntryAssembly () only works in the default (first) AppDomain
168                         // so we're using the first parameter to GetCommandLineArgs
169                         string exe = Environment.GetCommandLineArgs ()[0].Replace ("\\", "/").ToUpper ();
170                         Assert.IsTrue ((isf.DomainIdentity.ToString ().ToUpper ().IndexOf (exe) > 0), exe + "\n" + isf.DomainIdentity.ToString ().ToUpper ()); //"Url - Domain");
171 #endif
172                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
173                 }
174
175                 [Test]
176                 [ExpectedException (typeof (InvalidOperationException))]
177                 public void GetUserStoreForDomain_ApplicationIdentity ()
178                 {
179                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
180                         object o = isf.ApplicationIdentity;
181                 }
182
183                 [Test]
184 #if !MOBILE
185                 [ExpectedException (typeof (IsolatedStorageException))]
186 #endif
187                 public void GetUserStoreForApplication_WithoutApplicationIdentity ()
188                 {
189                         // note: a manifest is required
190                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ();
191                 }
192
193                 [Test]
194 #if !MOBILE
195                 [ExpectedException (typeof (IsolatedStorageException))]
196 #endif
197                 public void GetUserStoreForApplication ()
198                 {
199                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ();
200                         Assert.AreEqual (Int64.MaxValue, isf.MaximumSize, "MaximumSize");
201 #if !NET_2_1
202                         Assert.AreEqual (IsolatedStorageScope.User | IsolatedStorageScope.Assembly, isf.Scope, "Scope");
203                         Assert.IsTrue ((isf.AssemblyIdentity is Url), "AssemblyIdentity");
204                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().IndexOf (Assembly.GetExecutingAssembly ().CodeBase) > 0), "Url");
205 #endif
206                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
207                 }
208                 
209 #if !NET_2_1
210                 [Test]
211                 [ExpectedException (typeof (IsolatedStorageException))]
212                 public void GetUserStoreForApplication_AssemblyIdentity ()
213                 {
214                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ();
215                         object o = isf.AssemblyIdentity;
216                 }
217
218                 [Test]
219                 [ExpectedException (typeof (IsolatedStorageException))]
220                 public void GetUserStoreForApplication_DomainIdentity ()
221                 {
222                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ();
223                         object o = isf.DomainIdentity;
224                 }
225 #endif
226
227 #if NET_4_0
228                 // This is supposed to be working only in SL.
229                 [Test]
230                 [ExpectedException (typeof (NotSupportedException))]
231                 public void GetUserStoreForSite ()
232                 {
233                         IsolatedStorageFile.GetUserStoreForSite ();
234                 }
235 #endif
236
237                 [Test]
238                 public void GetStore_Domain_Zone ()
239                 {
240                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
241                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, typeof (Zone), typeof (Zone));
242                         Assert.AreEqual (Int64.MaxValue, isf.MaximumSize, "MaximumSize");
243 #if !NET_2_1
244                         Assert.AreEqual (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, isf.Scope, "Scope");
245                         Assert.IsTrue ((isf.AssemblyIdentity is Zone), "AssemblyIdentity");
246                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().IndexOf ("MyComputer") > 0), "Zone - Assembly");
247                         Assert.IsTrue ((isf.DomainIdentity is Zone), "DomainIdentity");
248                         Assert.IsTrue ((isf.DomainIdentity.ToString ().IndexOf ("MyComputer") > 0), "Zone - Domain");
249 #endif
250                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
251                 }
252
253                 [Test]
254 #if !MOBILE
255                 [ExpectedException (typeof (IsolatedStorageException))]
256 #endif
257                 public void GetStore_Domain_NonPresentEvidences ()
258                 {
259                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
260                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, typeof (StrongName), typeof (Publisher));
261                 }
262
263                 [Test]
264                 public void GetStore_Assembly_NonPresentDomainEvidences ()
265                 {
266                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Assembly;
267                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, typeof (StrongName), typeof (Url));
268                         Assert.AreEqual (Int64.MaxValue, isf.MaximumSize, "MaximumSize");
269                         Assert.AreEqual (scope, isf.Scope, "Scope");
270 #if !NET_2_1
271                         Assert.IsTrue ((isf.AssemblyIdentity is Url), "AssemblyIdentity");
272                         // note: mono transforms the CodeBase into uppercase
273                         // for net 1.1 which uses file:// and not file:///
274                         string codebase = Assembly.GetExecutingAssembly ().CodeBase.ToUpper ().Substring (8);
275                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().ToUpper ().IndexOf (codebase) > 0), "Url");
276                         // DomainIdentity throws a InvalidOperationException
277 #endif
278                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
279                 }
280
281 #if !MOBILE
282                 [Test]
283                 [ExpectedException (typeof (ArgumentNullException))]
284                 public void GetStore_Domain_DomainNullObject ()
285                 {
286                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
287                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, (object)null, new Zone (SecurityZone.MyComputer));
288                 }
289
290                 [Test]
291                 [ExpectedException (typeof (ArgumentNullException))]
292                 public void GetStore_Domain_AssemblyNullObject ()
293                 {
294                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
295                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, new Zone (SecurityZone.MyComputer), (object)null);
296                 }
297
298                 [Test]
299                 public void GetStore_Assembly_DomainNullObject ()
300                 {
301                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Assembly;
302                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, (object)null, new Zone (SecurityZone.Internet));
303                         Assert.AreEqual (Int64.MaxValue, isf.MaximumSize, "MaximumSize");
304                         Assert.AreEqual (scope, isf.Scope, "Scope");
305                         Assert.IsTrue ((isf.AssemblyIdentity is Zone), "AssemblyIdentity");
306                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().IndexOf ("Internet") > 0), "Zone - Assembly");
307                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
308                 }
309
310                 [Test]
311                 [ExpectedException (typeof (ArgumentNullException))]
312                 public void GetStore_Assembly_AssemblyNullObject ()
313                 {
314                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Assembly;
315                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, new Zone (SecurityZone.MyComputer), (object)null);
316                 }
317
318                 [Test]
319                 public void GetStore_Domain_ZoneObjectZoneObject ()
320                 {
321                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
322                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, new Zone (SecurityZone.Internet), new Zone (SecurityZone.Internet));
323                         Assert.AreEqual (Int64.MaxValue, isf.MaximumSize, "MaximumSize");
324                         Assert.AreEqual (scope, isf.Scope, "Scope");
325                         Assert.IsTrue ((isf.AssemblyIdentity is Zone), "AssemblyIdentity");
326                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().IndexOf ("Internet") > 0), "Zone - Assembly");
327                         Assert.IsTrue ((isf.DomainIdentity is Zone), "DomainIdentity");
328                         Assert.IsTrue ((isf.DomainIdentity.ToString ().IndexOf ("Internet") > 0), "Zone - Domain");
329                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
330                 }
331 #endif
332
333                 [Test]
334                 [ExpectedException (typeof (ArgumentNullException))]
335                 public void GetStore_Application_NullObject ()
336                 {
337                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Application;
338                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, (object)null);
339                 }
340
341                 [Test]
342 #if !MOBILE
343                 [ExpectedException (typeof (IsolatedStorageException))]
344 #endif
345                 public void GetStore_Application_NullType ()
346                 {
347                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Application;
348                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, (Type)null);
349                         // again it's the lack of a manifest
350                 }
351
352 #if !MOBILE
353                 [Test]
354                 public void GetStore_DomainScope_Evidences ()
355                 {
356                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
357
358                         Evidence de = new Evidence ();
359                         de.AddHost (new Zone (SecurityZone.Internet));
360                         Evidence ae = new Evidence ();
361                         ae.AddHost (new Zone (SecurityZone.Intranet));
362                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, de, typeof (Zone), ae, typeof (Zone));
363
364                         // Maximum size for Internet isn't (by default) Int64.MaxValue
365                         Assert.AreEqual (scope, isf.Scope, "Scope");
366 #if !NET_2_1
367                         Assert.IsTrue ((isf.AssemblyIdentity is Zone), "AssemblyIdentity");
368                         Assert.IsTrue ((isf.AssemblyIdentity.ToString ().IndexOf ("Intranet") > 0), "Zone - Assembly");
369                         Assert.IsTrue ((isf.DomainIdentity is Zone), "DomainIdentity");
370                         Assert.IsTrue ((isf.DomainIdentity.ToString ().IndexOf ("Internet") > 0), isf.DomainIdentity.ToString ()); //"Zone - Domain");
371 #endif
372                         Assert.IsTrue ((isf.CurrentSize >= 0), "CurrentSize");
373                 }
374
375                 [Test]
376                 [ExpectedException (typeof (ArgumentNullException))]
377                 public void GetStore_DomainScope_Evidence_NullAssemblyEvidence ()
378                 {
379                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
380
381                         Evidence de = new Evidence ();
382                         de.AddHost (new Zone (SecurityZone.Internet));
383                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, de, typeof (Zone), null, null);
384                 }
385
386                 [Test]
387                 [ExpectedException (typeof (ArgumentNullException))]
388                 public void GetStore_DomainScope_Evidence_NullDomainEvidence ()
389                 {
390                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
391
392                         Evidence ae = new Evidence ();
393                         ae.AddHost (new Zone (SecurityZone.Internet));
394                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, null, null, ae, typeof (Zone));
395                 }
396
397                 [Test]
398                 [ExpectedException (typeof (ArgumentNullException))]
399                 public void GetStore_AssemblyScope_Evidence_NullAssemblyEvidence ()
400                 {
401                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Assembly;
402
403                         Evidence de = new Evidence ();
404                         de.AddHost (new Zone (SecurityZone.Internet));
405                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, de, typeof (Zone), null, null);
406                 }
407
408                 [Test]
409                 public void GetStore_AssemblyScope_Evidence_NullDomainEvidence ()
410                 {
411                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Assembly;
412
413                         Evidence ae = new Evidence ();
414                         ae.AddHost (new Zone (SecurityZone.Internet));
415                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, null, null, ae, typeof (Zone));
416                 }
417 #endif
418
419                 [Test]
420                 public void RegressionBNC354539 ()
421                 {
422                         string filename = "test-bnc-354539";
423                         byte[] expected = new byte[] { 0x01, 0x42, 0x00 };
424                         byte[] actual = new byte [expected.Length];
425
426                         using (IsolatedStorageFile file = IsolatedStorageFile.GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) {
427                                 using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream (filename, FileMode.Create, FileAccess.Write, FileShare.None, file)) {
428                                         stream.Write (expected, 0, expected.Length);
429                                 }
430                         }
431
432                         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly ()) {
433                                 using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream (filename, FileMode.Open, FileAccess.Read, FileShare.Read, file)) {
434                                         stream.Read (actual, 0, actual.Length);
435                                 }
436
437                                 file.DeleteFile (filename);
438                         }
439                         
440                         Assert.AreEqual (expected, actual);
441                 }
442
443                 [Test]
444                 [ExpectedException (typeof (ArgumentNullException))]
445                 public void CreateDirectory_Null ()
446                 {
447                         IsolatedStorageFile.GetUserStoreForAssembly ().CreateDirectory (null);
448                 }
449
450                 [Test]
451                 public void CreateDirectory_FileWithSameNameExists ()
452                 {
453                         string path = "bug374377";
454                         using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ()) {
455                                 using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream (path, FileMode.OpenOrCreate, isf)) {
456                                 }
457                                 try {
458                                         isf.CreateDirectory (path);
459                                 }
460 #if NET_4_0
461                                 catch (IsolatedStorageException ex) {
462                                         Assert.IsFalse (ex.Message.IndexOf (path) >= 0, "Message");
463                                         Assert.IsNull (ex.InnerException, "InnerException");
464                                 }
465 #else
466                                 catch (IOException ex) {
467                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "Type");
468                                         // don't leak path information
469                                         Assert.IsFalse (ex.Message.IndexOf (path) >= 0, "Message");
470                                         Assert.IsNull (ex.InnerException, "InnerException");
471                                 }
472 #endif
473                         }
474                 }
475
476                 [Test]
477                 public void CreateDirectory_DirectoryWithSameNameExists ()
478                 {
479                         string dir = "new-dir";
480                         string file = Path.Combine (dir, "new-file");
481                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
482                         try {
483                                 isf.CreateDirectory (dir);
484                                 using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (file, FileMode.OpenOrCreate, isf)) {
485                                         isfs.WriteByte (0);
486                                 }
487                                 string pattern = Path.Combine (dir, "*");
488                                 Assert.AreEqual (1, isf.GetFileNames (file).Length, "file exists");
489
490                                 // create again directory
491                                 isf.CreateDirectory (dir);
492                                 Assert.AreEqual (1, isf.GetFileNames (file).Length, "file still exists");
493                         }
494                         finally {
495                                 isf.DeleteFile (file);
496                                 isf.DeleteDirectory (dir);
497                         }
498                 }
499
500                 [Test]
501 #if NET_4_0
502                 [ExpectedException (typeof (ArgumentException))]
503 #else
504                 [ExpectedException (typeof (SecurityException))]
505 #endif
506                 public void GetFilesInSubdirs ()
507                 {
508                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
509                         string pattern = Path.Combine ("..", "*");
510                         isf.GetFileNames (pattern);
511                 }
512
513         
514 #if NET_4_0
515                 [Test]
516                 [ExpectedException (typeof (ArgumentException))]
517                 public void GetDirsInSubDirs ()
518                 {
519                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
520                         isf.CreateDirectory ("subdir");
521                         string [] dir_names = isf.GetDirectoryNames ("subdir/../*");
522                 }
523 #endif
524
525                 [Test] // https://bugzilla.novell.com/show_bug.cgi?id=376188
526                 public void CreateSubDirectory ()
527                 {
528                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
529                         isf.CreateDirectory ("subdir");
530                         isf.CreateDirectory ("subdir/subdir2");
531                         Assert.AreEqual (1, isf.GetDirectoryNames ("*").Length, "subdir");
532                         Assert.AreEqual (1, isf.GetDirectoryNames ("subdir/*").Length, "subdir/subdir2");
533                         isf.DeleteDirectory ("subdir/subdir2");
534                         isf.DeleteDirectory ("subdir");
535                 }
536
537                 [Test]
538                 [ExpectedException (typeof (IsolatedStorageException))]
539                 public void DeleteDirectory_NonEmpty ()
540                 {
541                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
542                         isf.CreateDirectory ("subdir");
543                         isf.CreateDirectory ("subdir/subdir2");
544                         isf.DeleteDirectory ("subdir");
545                 }
546
547                 [Test]
548                 public void DeleteFile ()
549                 {
550                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
551
552                         try {
553                                 isf.DeleteFile (null);
554                                 Assert.Fail ("#Exc0");
555                         } catch (ArgumentNullException) {
556                         }
557
558 #if NET_4_0
559                         // We are getting an internal IndexOutOfRangeException in 2.0
560                         // Not sure we want to mimic that one.
561                         try {
562                                 isf.DeleteFile (String.Empty);
563                                 Assert.Fail ("#Exc1");
564                         } catch (IsolatedStorageException) {
565                         }
566 #endif
567
568                         try {
569                                 isf.DeleteFile ("idontexist");
570                                 Assert.Fail ("#Exc2");
571                         } catch (IsolatedStorageException) {
572                         }
573
574 #if NET_4_0
575                         try {
576                                 isf.DeleteFile ("../../file");
577                                 Assert.Fail ("#Exc3");
578                         } catch (IsolatedStorageException) {
579                         }
580 #endif
581                 
582                         try {
583                                 isf.DeleteFile ("subdir/file");
584                                 Assert.Fail ("#Exc4");
585                         } catch (IsolatedStorageException) {
586                         }
587
588                         isf.CreateDirectory ("subdir");
589                         try {
590                                 isf.DeleteFile ("subdir");
591                                 Assert.Fail ("#Exc5");
592                         } catch (IsolatedStorageException) {
593                         }
594                 }
595
596                 [Test]
597                 public void GetStore_NullTypes ()
598                 {
599                         IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Roaming | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain;
600                         IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, null, null);
601 #if !NET_2_1
602                         Assert.AreEqual (typeof (Url), isf.AssemblyIdentity.GetType (), "AssemblyIdentity");
603                         Assert.AreEqual (typeof (Url), isf.DomainIdentity.GetType (), "DomainIdentity");
604 #endif
605                 }
606
607                 [Test]
608                 public void RemoveFromOtherInstance ()
609                 {
610                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
611                         IsolatedStorageFile isf2 = IsolatedStorageFile.GetUserStoreForAssembly ();
612
613                         isf.Remove ();
614                         try {
615                                 isf2.Remove ();
616                                 Assert.Fail ("#Exc1");
617                         } catch (IsolatedStorageException) {
618                         }
619                 }
620
621 #if NET_4_0
622                 [Test]
623                 public void Remove ()
624                 {
625                         // Test that we can call Remove several times
626                         IsolatedStorageFile.Remove (IsolatedStorageScope.User);
627                         IsolatedStorageFile.Remove (IsolatedStorageScope.User);
628
629                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
630                         isf.Remove ();
631
632                         // The second call to Remove should cause an InvalidOperationException, due to
633                         // marking itself as closed.
634                         try {
635                                 isf.Remove ();
636                                 Assert.Fail ("#Exc1");
637                         } catch (InvalidOperationException) {
638                         }
639
640                         // Open, Close and try to Remove
641                         isf = IsolatedStorageFile.GetUserStoreForAssembly ();
642                         isf.Close ();
643                         try {
644                                 isf.Remove ();
645                                 Assert.Fail ("#Exc2");
646                         } catch (InvalidOperationException) {
647                         }
648                 }
649
650                 [Test]
651                 public void UsedSize ()
652                 {
653                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
654                         IsolatedStorageFileStream isfs = isf.CreateFile ("file");
655                         StreamWriter writer = new StreamWriter (isfs);
656                         writer.WriteLine ("hello mono");
657                         writer.Close ();
658
659                         Assert.AreEqual (true, isf.UsedSize > 0, "#A0");
660
661                         isf.Close ();
662                         try {
663                                 Console.WriteLine (isf.UsedSize);
664                                 Assert.Fail ("#Exc1");
665                         } catch (InvalidOperationException) {
666                         }
667
668                         isf.Dispose ();
669                         try {
670                                 Console.WriteLine (isf.UsedSize);
671                                 Assert.Fail ("#Exc2");
672                         } catch (ObjectDisposedException) {
673                         }
674                 }
675
676                 [Test]
677                 public void IncreateQuotaTo ()
678                 {
679                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
680
681                         try {
682                                 isf.IncreaseQuotaTo (-2);
683                                 Assert.Fail ("#Exc1");
684                         } catch (ArgumentException) {
685                         }
686
687                         // I wonder how this behaves on some systems
688                         try {
689                                 isf.IncreaseQuotaTo (100);
690                                 Assert.Fail ("#Exc2");
691                         } catch (ArgumentException) {
692                         }
693
694                         // Since 'Quota' seems to be returning Int64.MaxValue, we cannot truly test against a value
695                         // larger than that.
696                 }
697
698                 [Test]
699                 public void DirectoryExists ()
700                 {
701                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
702                         isf.CreateDirectory ("subdir");
703                         isf.CreateDirectory ("subdir/subdir2");
704                         isf.CreateDirectory ("subdir3");
705
706                         Assert.AreEqual (true, isf.DirectoryExists ("subdir/"), "#A0");
707                         Assert.AreEqual (true, isf.DirectoryExists ("subdir/subdir2/"), "#A1");
708                         Assert.AreEqual (true, isf.DirectoryExists ("subdir3"), "#A2");
709                         Assert.AreEqual (true, isf.DirectoryExists (String.Empty), "#A3"); // Weird
710                         Assert.AreEqual (false, isf.DirectoryExists ("subdir99"), "#A4");
711                         Assert.AreEqual (false, isf.DirectoryExists ("../../subdir"), "#A5");
712                         Assert.AreEqual (false, isf.DirectoryExists ("*"), "#A5");
713                         Assert.AreEqual (false, isf.DirectoryExists ("subdir*"), "#A6");
714
715                         isf.DeleteDirectory ("subdir3");
716                         Assert.AreEqual (false, isf.DirectoryExists ("subdir3"), "#B0");
717
718                         isf.DeleteDirectory ("subdir/subdir2");
719                         isf.DeleteDirectory ("subdir");
720
721                         try {
722                                 isf.DirectoryExists (null);
723                                 Assert.Fail ("#Exc1");
724                         } catch (ArgumentNullException) {
725                         }
726
727                         isf.Close ();
728                         try {
729                                 isf.DirectoryExists ("subdir");
730                                 Assert.Fail ("#Exc2");
731                         } catch (InvalidOperationException) {
732                         }
733
734                         isf.Dispose ();
735                         try {
736                                 isf.DirectoryExists ("subdir");
737                                 Assert.Fail ("#Exc3");
738                         } catch (ObjectDisposedException) {
739                         }
740
741                         // We want to be sure that if not closing but disposing
742                         // should fire ObjectDisposedException instead of InvalidOperationException
743                         isf = IsolatedStorageFile.GetUserStoreForAssembly ();
744                         isf.Dispose ();
745
746                         try {
747                                 isf.DirectoryExists ("subdir");
748                                 Assert.Fail ("#Exc4");
749                         } catch (ObjectDisposedException) {
750                         }
751                 }
752
753                 [Test]
754                 public void FileExists ()
755                 {
756                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
757                         IsolatedStorageFileStream file_a = new IsolatedStorageFileStream ("file-a", FileMode.Create, isf);
758                         IsolatedStorageFileStream file_b = new IsolatedStorageFileStream ("file-b", FileMode.Create, isf);
759                         file_a.Close ();
760                         file_b.Close ();
761
762                         Assert.AreEqual (true, isf.FileExists ("file-a"), "#A0");
763                         Assert.AreEqual (true, isf.FileExists ("file-b"), "#A1");
764                         Assert.AreEqual (false, isf.FileExists (String.Empty), "#A2");
765                         Assert.AreEqual (false, isf.FileExists ("file-"), "#A3");
766                         Assert.AreEqual (false, isf.FileExists ("file-*"), "#A4");
767                         Assert.AreEqual (false, isf.FileExists ("../../file-a"), "#A5");
768
769                         isf.CreateDirectory ("subdir");
770                         Assert.AreEqual (false, isf.FileExists ("subdir"), "#B0");
771
772                         try {
773                                 isf.FileExists (null);
774                                 Assert.Fail ("#Exc1");
775                         } catch (ArgumentNullException) {
776                         }
777
778                         isf.Close ();
779                         try {
780                                 isf.FileExists ("file-a");
781                                 Assert.Fail ("#Exc2");
782                         } catch (InvalidOperationException) {
783                         }
784
785                         isf.Dispose ();
786                         try {
787                                 isf.FileExists ("file-a");
788                                 Assert.Fail ("#Exc3");
789                         } catch (ObjectDisposedException) {
790                         }
791                 }
792
793                 [Test]
794                 public void CreateFile ()
795                 {
796                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
797                         // Make sure we are actually creating it, by first removing it in case it already exists
798                         if (isf.FileExists ("file-a"))
799                                 isf.DeleteFile ("file-a");
800
801                         IsolatedStorageFileStream isf_stream = isf.CreateFile ("file-a");
802                         isf_stream.Close ();
803                         Assert.AreEqual (true, isf.FileExists ("file-a"), "#A0");
804
805                         // Re-open the file that is already created, so we make sure we are passing
806                         // the proper FileOpen
807                         isf_stream = isf.CreateFile ("file-a");
808                         isf_stream.Close ();
809
810                         try {
811                                 isf.CreateFile (null);
812                                 Assert.Fail ("#Exc1");
813                         } catch (ArgumentNullException) {
814                         }
815
816                         try {
817                                 isf.CreateFile ("random-dir/fileb");
818                                 Assert.Fail ("#Exc2");
819                         } catch (DirectoryNotFoundException) {
820                         }
821
822                         isf.Close ();
823                         try {
824                                 isf.CreateFile ("file-b");
825                                 Assert.Fail ("#Exc3");
826                         } catch (InvalidOperationException) {
827                         }
828
829                         isf.Dispose ();
830                         try {
831                                 isf.CreateFile ("file-a");
832                                 Assert.Fail ("#Exc4");
833                         } catch (ObjectDisposedException) {
834                         }
835                 }
836
837                 [Test]
838                 public void GetCreationTime ()
839                 {
840                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
841
842                         // This is not causing an exception
843                         isf.GetCreationTime ("doesntexist");
844                         isf.GetCreationTime ("dir/doesntexist");
845
846                         try {
847                                 isf.GetCreationTime (String.Empty);
848                                 Assert.Fail ("#Exc1");
849                         } catch (ArgumentException) {
850                         }
851
852                         try {
853                                 isf.GetCreationTime ("   ");
854                                 Assert.Fail ("#Exc2");
855                         } catch (ArgumentException) {
856                         }
857
858                         isf.Close ();
859                         try {
860                                 isf.GetCreationTime ("doesntexist");
861                                 Assert.Fail ("#Exc3");
862                         } catch (InvalidOperationException) {
863                         }
864
865                         isf.Dispose ();
866                         try {
867                                 isf.GetCreationTime ("doesntexist");
868                                 Assert.Fail ("#Exc4");
869                         } catch (ObjectDisposedException) {
870                         }
871                 }
872
873                 [Test]
874                 public void MoveDirectory ()
875                 {
876                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
877                         // Mare sure to remove them if they exist already
878                         if (isf.DirectoryExists ("subdir"))
879                                 isf.DeleteDirectory ("subdir");
880                         if (isf.DirectoryExists ("subdir-new"))
881                                 isf.DeleteDirectory ("subdir-new");
882
883                         isf.CreateDirectory ("subdir");
884                         Assert.AreEqual (true, isf.DirectoryExists ("subdir"), "#A0");
885
886                         isf.MoveDirectory ("subdir", "subdir-new");
887                         Assert.AreEqual (false, isf.DirectoryExists ("subdir"), "#A1");
888                         Assert.AreEqual (true, isf.DirectoryExists ("subdir-new"), "#A2");
889
890                         try {
891                                 isf.MoveDirectory (String.Empty, "subdir-new-new");
892                                 Assert.Fail ("#Exc1");
893                         } catch (ArgumentException) {
894                         }
895
896                         try {
897                                 isf.MoveDirectory ("  ", "subdir-new-new");
898                                 Assert.Fail ("#Exc2");
899                         } catch (ArgumentException) {
900                         }
901
902                         try {
903                                 isf.MoveDirectory ("doesntexist", "subdir-new-new");
904                                 Assert.Fail ("#Exc3");
905                         } catch (DirectoryNotFoundException) {
906                         }
907
908                         try {
909                                 isf.MoveDirectory ("doesnexist/doesntexist", "subdir-new-new");
910                                 Assert.Fail ("#Exc4");
911                         } catch (DirectoryNotFoundException) {
912                         }
913
914                         try {
915                                 isf.MoveDirectory ("subdir-new", "doesntexist/doesntexist");
916                                 Assert.Fail ("#Exc5");
917                         } catch (DirectoryNotFoundException) {
918                         }
919
920                         // Out of storage dir
921                         try {
922                                 isf.MoveDirectory ("subdir-new", "../../subdir-new");
923                                 Assert.Fail ("#Exc6");
924                         } catch (IsolatedStorageException) {
925                         }
926
927                         isf.Remove ();
928                         isf.Close ();
929                         isf.Dispose ();
930                 }
931
932                 [Test]
933                 public void CopyFile ()
934                 {
935                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
936                         if (isf.FileExists ("file"))
937                                 isf.DeleteFile ("file");
938                         if (isf.FileExists ("file-new"))
939                                 isf.DeleteFile ("file-new");
940
941                         isf.CreateFile ("file").Close ();
942                         isf.CopyFile ("file", "file-new");
943                         Assert.AreEqual (true, isf.FileExists ("file"), "#A0");
944                         Assert.AreEqual (true, isf.FileExists ("file-new"), "#A1");
945
946                         // At this point 'file-exists' already exists.
947                         isf.CopyFile ("file", "file-new", true);
948                         Assert.AreEqual (true, isf.FileExists ("file"), "#B0");
949                         Assert.AreEqual (true, isf.FileExists ("file-new"), "#B1");
950
951                         isf.CreateDirectory ("subdir");
952                         isf.CreateFile ("subdir/subfile").Close ();
953                         isf.CopyFile ("subdir/subfile", "subdir/subfile-new");
954                         Assert.AreEqual (true, isf.FileExists ("subdir/subfile"), "#C0");
955                         Assert.AreEqual (true, isf.FileExists ("subdir/subfile-new"), "#C1");
956
957                         try {
958                                 isf.CopyFile ("file", "file-new");
959                                 Assert.Fail ("#Exc0");
960                         } catch (IsolatedStorageException) {
961                         }
962
963                         // Using the same file name is failing for even when passing override=true.
964                         try {
965                                 isf.CopyFile ("file-new", "file-new", true);
966                                 Assert.Fail ("#Exc1");
967                         } catch (IsolatedStorageException) {
968                         }
969
970                         try {
971                                 isf.CopyFile ("file-new", "file-new", false);
972                                 Assert.Fail ("#Exc2");
973                         } catch (IsolatedStorageException) {
974                         }
975
976                         // Remove 'file-new' for cleaness purposes.
977                         isf.DeleteFile ("file-new");
978
979                         try {
980                                 isf.CopyFile ("doesntexist", "file-new", false);
981                                 Assert.Fail ("#Exc3");
982                         } catch (FileNotFoundException) {
983                         }
984
985                         try {
986                                 isf.CopyFile ("doesnexist/doesntexist", "file-new", false);
987                                 Assert.Fail ("#Exc4");
988                         } catch (DirectoryNotFoundException) {
989                         }
990
991                         // I'd have expected a DirectoryNotFoundException here.
992                         try {
993                                 isf.CopyFile ("file", "doesntexist/doesntexist");
994                                 Assert.Fail ("#Exc5");
995                         } catch (IsolatedStorageException) {
996                         }
997
998                         // Out of storage dir
999                         try {
1000                                 isf.CopyFile ("file", "../../file");
1001                                 Assert.Fail ("#Exc6");
1002                         } catch (IsolatedStorageException) {
1003                         }
1004
1005                         try {
1006                                 isf.CopyFile ("../file", "file-new");
1007                                 Assert.Fail ("#Exc7");
1008                         } catch (IsolatedStorageException) {
1009                         }
1010
1011                         // We are creating a subdirectory and files within it, so remove it just in case.
1012                         isf.Remove ();
1013
1014                         isf.Close ();
1015                         isf.Dispose ();
1016                 }
1017
1018                 [Test]
1019                 public void MoveFile ()
1020                 {
1021                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
1022                         // Mare sure to remove them if they exist already
1023                         if (isf.FileExists ("file"))
1024                                 isf.DeleteFile ("file");
1025                         if (isf.FileExists ("file-new"))
1026                                 isf.DeleteFile ("file-new");
1027                         if (isf.FileExists ("subdir/subfile"))
1028                                 isf.DeleteFile ("subdir/subfile");
1029                         if (isf.FileExists ("subdir/subfile-new"))
1030                                 isf.DeleteFile ("subdir/subfile-new");
1031
1032                         isf.CreateFile ("file").Close ();
1033                         Assert.AreEqual (true, isf.FileExists ("file"), "#A0");
1034
1035                         // Same file
1036                         isf.MoveFile ("file", "file");
1037                         Assert.AreEqual (true, isf.FileExists ("file"), "#A0-1");
1038
1039                         isf.MoveFile ("file", "file-new");
1040                         Assert.AreEqual (false, isf.FileExists ("file"), "#A1");
1041                         Assert.AreEqual (true, isf.FileExists ("file-new"), "#A2");
1042
1043                         isf.CreateDirectory ("subdir");
1044                         isf.CreateFile ("subdir/subfile").Close ();
1045                         isf.MoveFile ("subdir/subfile", "subdir/subfile-new");
1046                         Assert.AreEqual (false, isf.FileExists ("subdir/subfile"), "#B0");
1047                         Assert.AreEqual (true, isf.FileExists ("subdir/subfile-new"), "#B1");
1048
1049                         try {
1050                                 isf.MoveFile (String.Empty, "file-new-new");
1051                                 Assert.Fail ("#Exc1");
1052                         } catch (ArgumentException) {
1053                         }
1054
1055                         try {
1056                                 isf.MoveFile ("  ", "file-new-new");
1057                                 Assert.Fail ("#Exc2");
1058                         } catch (ArgumentException e) {
1059                                 Console.WriteLine (e);
1060                         }
1061
1062                         try {
1063                                 isf.MoveFile ("doesntexist", "file-new-new");
1064                                 Assert.Fail ("#Exc3");
1065                         } catch (FileNotFoundException) {
1066                         }
1067
1068                         // CopyFile is throwing a DirectoryNotFoundException here.
1069                         try {
1070                                 isf.MoveFile ("doesnexist/doesntexist", "file-new-new");
1071                                 Assert.Fail ("#Exc4");
1072                         } catch (FileNotFoundException) {
1073                         }
1074
1075                         // I'd have expected a DirectoryNotFoundException here.
1076                         try {
1077                                 isf.MoveFile ("file-new", "doesntexist/doesntexist");
1078                                 Assert.Fail ("#Exc5");
1079                         } catch (IsolatedStorageException) {
1080                         }
1081
1082                         // Out of storage dir
1083                         try {
1084                                 isf.MoveFile ("file-new", "../../file-new");
1085                                 Assert.Fail ("#Exc6");
1086                         } catch (IsolatedStorageException) {
1087                         }
1088
1089                         isf.Remove ();
1090                         isf.Close ();
1091                         isf.Dispose ();
1092                 }
1093
1094                 [Test]
1095                 public void MultiLevel ()
1096                 {
1097                         // see bug #4101
1098                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
1099                         try {
1100                                 isf.CreateDirectory ("dir1");
1101                                 string [] dirs = isf.GetDirectoryNames ("*");
1102                                 Assert.AreEqual (dirs.Length, 1, "1a");
1103                                 Assert.AreEqual (dirs [0], "dir1", "1b");
1104         
1105                                 isf.CreateDirectory ("dir1/test");
1106                                 dirs = isf.GetDirectoryNames ("dir1/*");
1107                                 Assert.AreEqual (dirs.Length, 1, "2a");
1108                                 Assert.AreEqual (dirs [0], "test", "2b");
1109         
1110                                 isf.CreateDirectory ("dir1/test/test2a");
1111                                 isf.CreateDirectory ("dir1/test/test2b");
1112                                 dirs = isf.GetDirectoryNames ("dir1/test/*");
1113                                 Assert.AreEqual (dirs.Length, 2, "3a");
1114                                 Assert.AreEqual (dirs [0], "test2a", "3b");
1115                                 Assert.AreEqual (dirs [1], "test2b", "3c");
1116                         }
1117                         finally {
1118                                 isf.DeleteDirectory ("dir1/test/test2a");
1119                                 isf.DeleteDirectory ("dir1/test/test2b");
1120                                 isf.DeleteDirectory ("dir1/test");
1121                                 isf.DeleteDirectory ("dir1");
1122                         }
1123                 }
1124 #endif
1125                 [Test]
1126                 public void RootedDirectory ()
1127                 {
1128                         IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
1129                         try {
1130                                 isf.CreateDirectory ("test/nested/directory/structure/without/root");
1131                                 isf.CreateDirectory ("/test/nested/directory/structure/with/root");
1132                         }
1133                         finally {
1134                                 isf.DeleteDirectory ("test/nested/directory/structure/without/root");
1135                                 isf.DeleteDirectory ("test/nested/directory/structure/without");
1136
1137                                 isf.DeleteDirectory ("/test/nested/directory/structure/with/root");
1138                                 isf.DeleteDirectory ("/test/nested/directory/structure/with");
1139                                 isf.DeleteDirectory ("/test/nested/directory/structure");
1140                                 isf.DeleteDirectory ("/test/nested/directory");
1141                                 isf.DeleteDirectory ("/test/nested");
1142                                 isf.DeleteDirectory ("/test");
1143                         }
1144                 }
1145         }
1146 }