232e3667bdfa18e6a89dcf565d4fbb0e372fb569
[mono.git] / mcs / class / corlib / Test / System.IO / FileInfoTest.cs
1 // FileInfoTest.cs - NUnit Test Cases for System.IO.FileInfo class\r
2 //\r
3 // Ville Palo (vi64pa@koti.soon.fi)\r
4 // \r
5 // (C) 2003 Ville Palo\r
6 // \r
7 \r
8 \r
9 using NUnit.Framework;\r
10 using System;\r
11 using System.IO;\r
12 \r
13 namespace MonoTests.System.IO\r
14 {\r
15         [TestFixture]\r
16         public class FileInfoTest : Assertion\r
17         {\r
18                 string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");\r
19                 static readonly char DSC = Path.DirectorySeparatorChar;\r
20 \r
21                 [SetUp]\r
22                 protected void SetUp() {\r
23                         if (Directory.Exists (TempFolder))\r
24                                 Directory.Delete (TempFolder, true);\r
25                         Directory.CreateDirectory (TempFolder);\r
26                 }\r
27                 \r
28                 [TearDown]\r
29                 protected void TearDown() {\r
30                         if (Directory.Exists (TempFolder))\r
31                                 Directory.Delete (TempFolder, true);\r
32                 }\r
33                 \r
34                 [Test]\r
35                 public void Ctr ()\r
36                 {\r
37                         string path = TempFolder + DSC + "FIT.Ctr.Test";\r
38                         DeleteFile (path);\r
39                         \r
40                         FileInfo info = new FileInfo (path);\r
41                         AssertEquals ("test#01", true, info.DirectoryName.EndsWith (".Tests"));\r
42                         AssertEquals ("test#02", false, info.Exists);\r
43                         AssertEquals ("test#03", ".Test", info.Extension);\r
44                         AssertEquals ("test#05", "FIT.Ctr.Test", info.Name);                    \r
45                 }\r
46                 \r
47                 [Test]\r
48                 [ExpectedException(typeof(ArgumentNullException))]\r
49                 public void CtorArgumentNullException ()\r
50                 {\r
51                         FileInfo info = new FileInfo (null);                    \r
52                 }\r
53                 \r
54                 [Test]\r
55                 [ExpectedException(typeof(ArgumentException))]\r
56                 public void CtorArgumentException1 ()\r
57                 {\r
58                         FileInfo info = new FileInfo ("");                      \r
59                 }\r
60                 \r
61                 [Test]\r
62                 [ExpectedException(typeof(ArgumentException))]\r
63                 public void CtorArgumentException2 ()\r
64                 {\r
65                         FileInfo info = new FileInfo ("      ");                        \r
66                 }\r
67 \r
68                 [Test]\r
69                 [ExpectedException(typeof(ArgumentException))]\r
70                 public void CtorArgumentException3 ()\r
71                 {\r
72                         string path = "";\r
73                         foreach (char c in Path.InvalidPathChars) {\r
74                                 path += c;\r
75                         }\r
76                         FileInfo info = new FileInfo (path);                    \r
77                 }\r
78                                \r
79                 [Test]\r
80                 public void DirectoryTest ()\r
81                 {\r
82                         string path = TempFolder + DSC + "FIT.Directory.Test";\r
83                         DeleteFile (path);\r
84                         \r
85                         FileInfo info = new FileInfo (path);\r
86                         DirectoryInfo dir = info.Directory;\r
87                         AssertEquals ("test#01", "MonoTests.System.IO.Tests", dir.Name);\r
88                 }\r
89                 \r
90                 [Test]\r
91                 public void Exists ()\r
92                 {\r
93                         string path = TempFolder + DSC + "FIT.Exists.Test";\r
94                         DeleteFile (path);\r
95                         \r
96                         try {\r
97                                 FileInfo info = new FileInfo (path);\r
98                                 AssertEquals ("test#01", false, info.Exists);\r
99                         \r
100                                 File.Create (path).Close ();\r
101                                 AssertEquals ("test#02", false, info.Exists);\r
102                                 info = new FileInfo (path);\r
103                                 AssertEquals ("test#03", true, info.Exists);                    \r
104                         } finally {\r
105                                 DeleteFile (path);\r
106                         }\r
107                 }\r
108                 \r
109                 [Test]\r
110                 public void Length ()\r
111                 {\r
112                         string path = TempFolder + DSC + "FIT.Length.Test";\r
113                         DeleteFile (path);\r
114                         \r
115                         try {\r
116                                 FileStream stream = File.Create (path);\r
117                                 FileInfo info = new FileInfo (path);\r
118                                 AssertEquals ("test#01", 0, info.Length);\r
119                                 stream.WriteByte (12);\r
120                                 stream.Flush ();\r
121                                 AssertEquals ("test#02", 0, info.Length);\r
122                                 info = new FileInfo (path);\r
123                                 AssertEquals ("test#03", 1, info.Length);\r
124                                 stream.Close ();\r
125                         } finally {\r
126                                 DeleteFile (path);\r
127                         }\r
128                 }\r
129                 \r
130                 [Test]\r
131                 [ExpectedException (typeof (FileNotFoundException))]\r
132                 public void LengthException ()\r
133                 {\r
134                         string path = TempFolder + DSC + "FIT.LengthException.Test";\r
135                         DeleteFile (path);\r
136                         FileInfo info = new FileInfo (path);\r
137                         long l = info.Length;\r
138                 }\r
139                 \r
140                 [Test]\r
141                 public void AppendText ()\r
142                 {\r
143                         string path = TempFolder + DSC + "FIT.AppendText.Test";\r
144                         DeleteFile (path);\r
145                         \r
146                         try {\r
147                                 FileInfo info = new FileInfo (path);\r
148                         \r
149                                 AssertEquals ("test#01", false, info.Exists);\r
150                         \r
151                                 StreamWriter writer = info.AppendText ();\r
152                                 info = new FileInfo (path);\r
153                                 AssertEquals ("test#02", true, info.Exists );\r
154                                 \r
155                                 writer.Write ("aaa");\r
156                                 writer.Flush ();\r
157                                 writer.Close ();\r
158                         \r
159                                 AssertEquals ("test#03", 0, info.Length);\r
160                                 info = new FileInfo (path);\r
161                                 AssertEquals ("test#04", 3, info.Length);\r
162                         } finally {\r
163                                 DeleteFile (path);\r
164                         }\r
165                         \r
166                 }\r
167                 \r
168                 [Test]\r
169                 public void CopyTo ()\r
170                 {\r
171                         string path1 = TempFolder + DSC + "FIT.CopyTo.Source.Test";\r
172                         string path2 = TempFolder + DSC + "FIT.CopyTo.Dest.Test";\r
173                         DeleteFile (path1);\r
174                         DeleteFile (path2);\r
175                         try {\r
176                                 File.Create (path1).Close ();\r
177                         \r
178                                 FileInfo info = new FileInfo (path1);\r
179                                 AssertEquals ("test#01", true, info.Exists);\r
180                                                 \r
181                                 FileInfo info2 = info.CopyTo (path2);\r
182                                 info = new FileInfo (path1);\r
183                                 AssertEquals ("test#02", true, info2.Exists);\r
184                         } finally {\r
185                                 DeleteFile (path1);\r
186                                 DeleteFile (path2);                     \r
187                         }\r
188                 }\r
189                 \r
190                 [Test]\r
191                 public void CopyTo2 ()\r
192                 {\r
193                         string path1 = TempFolder + DSC + "FIT.CopyTo2.Source.Test";\r
194                         string path2 = TempFolder + DSC + "FIT.CopyTo2.Dest.Test";\r
195                         DeleteFile (path1);\r
196                         DeleteFile (path2);\r
197                         try {\r
198                                 File.Create (path1).Close ();\r
199                                 File.Create (path2).Close ();           \r
200                                 FileInfo info = new FileInfo (path1);\r
201                         \r
202                                 FileInfo info2 = info.CopyTo (path2, true);\r
203                                 info = new FileInfo (path1);\r
204                                 AssertEquals ("test#01", true, info.Exists);\r
205                                 AssertEquals ("test#02", true, info2.Exists);\r
206                         } finally {\r
207                                 DeleteFile (path1);\r
208                                 DeleteFile (path2);\r
209                         }\r
210                 }\r
211                 \r
212                 [Test]\r
213                 [ExpectedException (typeof (IOException))]\r
214                 public void CopyToIOException ()\r
215                 {\r
216                         string path1 = TempFolder + DSC + "FIT.CopyToException.Source.Test";\r
217                         string path2 = TempFolder + DSC + "FIT.CopyToException.Dest.Test";\r
218 \r
219                         try {\r
220                                 DeleteFile (path1);\r
221                                 DeleteFile (path2);\r
222                                 File.Create (path1).Close ();\r
223                                 File.Create (path2).Close ();           \r
224                                 FileInfo info = new FileInfo (path1);                   \r
225                                 FileInfo info2 = info.CopyTo (path2);                   \r
226                         } finally {\r
227                                 DeleteFile (path1);\r
228                                 DeleteFile (path2);\r
229                         }\r
230                 }\r
231 \r
232                 [Test]\r
233                 [ExpectedException (typeof (IOException))]\r
234                 public void CopyToIOException2 ()\r
235                 {\r
236                         string path1 = TempFolder + DSC + "FIT.CopyToException.Source.Test";\r
237                         string path2 = TempFolder + DSC + "FIT.CopyToException.Dest.Test";\r
238 \r
239                         try {\r
240                                 DeleteFile (path1);\r
241                                 DeleteFile (path2);\r
242                                 File.Create (path1).Close ();\r
243                                 File.Create (path2).Close ();           \r
244                                 FileInfo info = new FileInfo (path1);                   \r
245                                 FileInfo info2 = info.CopyTo (path2, false);\r
246                         } finally {\r
247                                 DeleteFile (path1);\r
248                                 DeleteFile (path2);\r
249                         }\r
250                 }\r
251                 \r
252                 [Test]\r
253                 [ExpectedException (typeof (ArgumentNullException))]\r
254                 public void CopyToArgumentNullException ()\r
255                 {\r
256                         string path = TempFolder + DSC + "FIT.CopyToArgumentNullException.Test";\r
257                         DeleteFile (path);\r
258                         try {\r
259                                 File.Create (path).Close ();\r
260                                 FileInfo info = new FileInfo (path);\r
261                                 info.CopyTo (null, false);\r
262                         } finally {\r
263                                 DeleteFile (path);\r
264                         }\r
265                 }\r
266 \r
267                 [Test]\r
268                 [ExpectedException (typeof (ArgumentException))]\r
269                 public void CopyToArgumentException1 ()\r
270                 {\r
271                         string path = TempFolder + DSC + "FIT.CopyToArgument1Exception.Test";\r
272                         DeleteFile (path);\r
273                         \r
274                         try {\r
275                                 File.Create (path).Close ();\r
276                                 FileInfo info = new FileInfo (path);\r
277                                 info.CopyTo ("", false);\r
278                         } finally {\r
279                                 DeleteFile (path);\r
280                         }\r
281                 }\r
282 \r
283                 [Test]\r
284                 [ExpectedException (typeof (ArgumentException))]\r
285                 public void CopyToArgumentException2 ()\r
286                 {\r
287                         string path = TempFolder + DSC + "FIT.CopyToArgument2Exception.Test";\r
288                         DeleteFile (path);\r
289                         \r
290                         try {\r
291                                 File.Create (path).Close ();\r
292                                 FileInfo info = new FileInfo (path);\r
293                                 info.CopyTo ("    ", false);\r
294                         } finally {\r
295                                 DeleteFile (path);\r
296                         }\r
297                 }\r
298 \r
299                 [Test]\r
300                 [ExpectedException (typeof (ArgumentException))]\r
301                 public void CopyToArgumentException3 ()\r
302                 {\r
303                         string path = TempFolder + DSC + "FIT.CopyToArgument3Exception.Test";\r
304                         DeleteFile (path);\r
305                         \r
306                         try {\r
307                                 File.Create (path).Close ();\r
308                                 FileInfo info = new FileInfo (path);\r
309                                 info.CopyTo ("    ", false);\r
310                         } finally {\r
311                                 DeleteFile (path);\r
312                         }\r
313                 }\r
314 \r
315                 [Test]\r
316                 [ExpectedException (typeof (ArgumentException))]\r
317                 public void CopyToArgumentException4 ()\r
318                 {\r
319                         string path = TempFolder + DSC + "FIT.CopyToArgument4Exception.Test";\r
320                         string path2 = "";\r
321                         DeleteFile (path);\r
322                         \r
323                         try {\r
324                                 File.Create (path).Close ();\r
325                                 FileInfo info = new FileInfo (path);\r
326                         \r
327                                 foreach (char c in Path.InvalidPathChars) {\r
328                                         path2 += c;\r
329                                 }\r
330                                 info.CopyTo (path2, false);\r
331                         } finally {\r
332                                 DeleteFile (path);\r
333                         }\r
334                 }\r
335                 \r
336                 [Test]\r
337                 public void Create ()\r
338                 {\r
339                         string path = TempFolder + DSC + "FIT.Create.Test";\r
340                         DeleteFile (path);\r
341                         \r
342                         try {\r
343                                 FileInfo info = new FileInfo (path);\r
344                                 AssertEquals ("test#01", false, info.Exists);\r
345                                 FileStream stream = info.Create ();                             \r
346                                 AssertEquals ("test#02", false, info.Exists);\r
347                                 info = new FileInfo (path);\r
348                                 AssertEquals ("test#03", true, info.Exists);\r
349                                 AssertEquals ("test#04", true, stream.CanRead);\r
350                                 AssertEquals ("test#05", true, stream.CanWrite);\r
351                                 AssertEquals ("test#06", true, stream.CanSeek);\r
352                                 stream.Close ();\r
353                         } finally {\r
354                                 DeleteFile (path);\r
355                         }\r
356                 }\r
357                 \r
358                 [Test]\r
359                 public void CreateText ()\r
360                 {\r
361                         string path = TempFolder + DSC + "FIT.CreateText.Test";\r
362                         DeleteFile (path);\r
363                         \r
364                         try {\r
365                                 FileInfo info = new FileInfo (path);\r
366                                 AssertEquals ("test#01", false, info.Exists);\r
367                                 StreamWriter writer = info.CreateText ();\r
368                                 writer.WriteLine ("test");\r
369                                 writer.Close ();\r
370                                 info = new FileInfo (path);\r
371                                 AssertEquals ("test#02", true, info.Exists);\r
372                         } finally {\r
373                                 DeleteFile (path);\r
374                         }\r
375                 }\r
376                 \r
377                 [Test]\r
378                 [ExpectedException (typeof (UnauthorizedAccessException))]\r
379                 public void CreateTextUnauthorizedAccessException ()\r
380                 {\r
381                         string path = TempFolder;\r
382                         \r
383                         FileInfo info = new FileInfo (path);\r
384                         AssertEquals ("test#01", false, info.Exists);\r
385                         StreamWriter writer = info.CreateText ();\r
386                         \r
387                 }\r
388                 \r
389                 [Test]\r
390                 public void Delete ()\r
391                 {\r
392                         string path = TempFolder + DSC + "FIT.Delete.Test";\r
393                         DeleteFile (path);\r
394                         \r
395                         try {\r
396                                 FileInfo info = new FileInfo (path);\r
397                                 AssertEquals ("test#01", false, info.Exists);\r
398                                 info.Create ().Close ();\r
399                                 info = new FileInfo (path);\r
400                                 AssertEquals ("test#02", true, info.Exists);\r
401                                 info.Delete ();\r
402                                 AssertEquals ("test#03", true, info.Exists);\r
403                                 info = new FileInfo (path);\r
404                                 AssertEquals ("test#04", false, info.Exists);                                                           \r
405                         } finally {\r
406                                 DeleteFile (path);\r
407                         }\r
408                 }\r
409                 \r
410                 [Test]\r
411                 [ExpectedException (typeof (UnauthorizedAccessException))]\r
412                 public void DeleteUnauthorizedAccessException ()\r
413                 {\r
414                         string path = TempFolder;\r
415                         FileInfo info = new FileInfo (path);\r
416                         info.Delete ();                 \r
417                 }\r
418                 \r
419                 [Test]\r
420                 public void MoveTo ()\r
421                 {\r
422                         string path1 = TempFolder + DSC + "FIT.MoveTo.Source.Test";\r
423                         string path2 = TempFolder + DSC + "FIT.MoveTo.Dest.Test";\r
424                         DeleteFile (path1);\r
425                         DeleteFile (path2);\r
426                         \r
427                         try {\r
428                                 File.Create (path1).Close ();\r
429                                 FileInfo info = new FileInfo (path1);\r
430                                 FileInfo info2 = new FileInfo (path2);\r
431                                 AssertEquals ("test#01", false, info2.Exists);\r
432                                 \r
433                                 info.MoveTo (path2);\r
434                                 info2 = new FileInfo (path2);\r
435                                 AssertEquals ("test#02", true, info2.Exists);   \r
436                         } finally {\r
437                                 DeleteFile (path1);\r
438                                 DeleteFile (path2);                     \r
439                         }                       \r
440                 }\r
441                 \r
442                 [Test]\r
443                 [ExpectedException (typeof (IOException))]\r
444                 public void MoveToIOException ()\r
445                 {\r
446                         string path1 = TempFolder + DSC + "FIT.MoveToIOException.Source.Test";\r
447                         string path2 = TempFolder + DSC + "FIT.MoveToIOException.Dest.Test";\r
448                         DeleteFile (path1);\r
449                         DeleteFile (path2);\r
450 \r
451                         try {\r
452                                 File.Create (path1).Close ();\r
453                                 File.Create (path2).Close ();\r
454                                 \r
455                                 FileInfo info = new FileInfo (path1);\r
456                                 info.MoveTo (path2);\r
457                         } finally {\r
458                                 DeleteFile (path1);\r
459                                 DeleteFile (path2);\r
460                         }\r
461                 }\r
462 \r
463                 [Test]\r
464                 [ExpectedException (typeof (ArgumentNullException))]\r
465                 public void MoveToArgumentNullException ()\r
466                 {\r
467                         string path = TempFolder + DSC + "FIT.MoveToArgumentNullException.Test";\r
468                         DeleteFile (path);\r
469 \r
470                         try {\r
471                                 File.Create (path).Close ();                            \r
472                                 FileInfo info = new FileInfo (path);\r
473                                 info.MoveTo (null);\r
474                         } finally {\r
475                                 DeleteFile (path);\r
476                         }\r
477                 }\r
478 \r
479                 [Test]\r
480                 [ExpectedException (typeof (ArgumentException))]\r
481                 public void MoveToArgumentException ()\r
482                 {\r
483                         string path = TempFolder + DSC + "FIT.MoveToArgumentException.Test";\r
484                         DeleteFile (path);\r
485 \r
486                         try {\r
487                                 File.Create (path).Close ();                            \r
488                                 FileInfo info = new FileInfo (path);\r
489                                 info.MoveTo ("   ");\r
490                         } finally {\r
491                                 DeleteFile (path);\r
492                         }\r
493                 }\r
494 \r
495                 /// <summary>\r
496                 /// msdn says this should throw UnauthorizedAccessException, byt\r
497                 /// it throws IOException.\r
498                 /// </summary>\r
499                 [Test]\r
500                 [ExpectedException (typeof (IOException))]\r
501                 public void MoveToUnauthorizedAccessException ()\r
502                 {\r
503                         string path = TempFolder + DSC + "FIT.UnauthorizedAccessException.Test";\r
504                         DeleteFile (path);\r
505 \r
506                         try {\r
507                                 File.Create (path).Close ();\r
508                                 FileInfo info = new FileInfo (path);\r
509                                 info.MoveTo (TempFolder);\r
510                         } finally {\r
511                                 DeleteFile (path);\r
512                         }\r
513                 }\r
514                 \r
515                 [Test]\r
516                 [ExpectedException (typeof (FileNotFoundException))]\r
517                 public void MoveToFileNotFoundException ()\r
518                 {\r
519                         string path1 = TempFolder + DSC + "FIT.MoveToFileNotFoundException.Src";\r
520                         string path2 = TempFolder + DSC + "FIT.MoveToFileNotFoundException.Dst";\r
521                         DeleteFile (path1);\r
522                         DeleteFile (path2);\r
523                         \r
524                         try {\r
525                                 FileInfo info = new FileInfo (path1);\r
526                                 info.MoveTo (path2);\r
527                         } finally {\r
528                                 DeleteFile (path1);\r
529                                 DeleteFile (path2);\r
530                         }\r
531                 }\r
532                                 \r
533                 [Test]\r
534                 public void Open ()\r
535                 {\r
536                         string path = TempFolder + DSC + "FIT.Open.Test";\r
537                         DeleteFile (path);\r
538                         FileStream stream = null;\r
539                         try {\r
540                                 FileInfo info = new FileInfo (path);\r
541                                 stream = info.Open (FileMode.CreateNew);\r
542                                 AssertEquals ("test#01", true, stream.CanRead);\r
543                                 AssertEquals ("test#02", true, stream.CanSeek);\r
544                                 AssertEquals ("test#03", true, stream.CanWrite);                                \r
545                                 stream.Close ();\r
546                                 \r
547                                 stream = info.Open (FileMode.Open);                             \r
548                                 AssertEquals ("test#04", true, stream.CanRead);\r
549                                 AssertEquals ("test#05", true, stream.CanSeek);\r
550                                 AssertEquals ("test#06", true, stream.CanWrite);                                \r
551                                 stream.Close ();\r
552                                 \r
553                                 stream = info.Open (FileMode.Append, FileAccess.Write);\r
554                                 AssertEquals ("test#07", false, stream.CanRead);\r
555                                 AssertEquals ("test#08", true, stream.CanSeek);\r
556                                 AssertEquals ("test#09", true, stream.CanWrite);                                \r
557                                 stream.Close ();                                \r
558 \r
559                                 stream = info.Open (FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);\r
560                                 AssertEquals ("test#10", true, stream.CanRead);\r
561                                 AssertEquals ("test#11", true, stream.CanSeek);\r
562                                 AssertEquals ("test#12", true, stream.CanWrite);                                \r
563                                 stream.Close ();                                                                                                \r
564                         } finally {\r
565                                 if (stream != null)\r
566                                         stream.Close ();\r
567                                 DeleteFile (path);\r
568                         }\r
569                 }\r
570                 \r
571                 [Test]\r
572                 [ExpectedException(typeof(FileNotFoundException))]\r
573                 public void OpenFileNotFoundException ()\r
574                 {\r
575                         string path = TempFolder + DSC + "FIT.OpenFileNotFoundException.Test";\r
576                         DeleteFile (path);\r
577                         \r
578                         FileInfo info = new FileInfo (path);\r
579                         info.Open (FileMode.Open);\r
580                 }\r
581                 \r
582                 [Test]\r
583                 public void OpenRead ()\r
584                 {\r
585                         string path = TempFolder + DSC + "FIT.OpenRead.Test";\r
586                         DeleteFile (path);\r
587                         FileStream stream = null;\r
588                         try {\r
589                                 File.Create (path).Close ();\r
590                                 FileInfo info = new FileInfo (path);\r
591                                 stream = info.OpenRead ();\r
592                                 AssertEquals ("test#01", true, stream.CanRead);\r
593                                 AssertEquals ("test#02", true, stream.CanSeek);\r
594                                 AssertEquals ("test#03", false, stream.CanWrite);\r
595                                 stream.Close ();\r
596                                 \r
597                         } finally {\r
598                                 if (stream != null)\r
599                                         stream.Close ();\r
600                                 DeleteFile (path);\r
601                         }\r
602                 }\r
603                 \r
604                 [Test]\r
605                 [ExpectedException(typeof (IOException))]\r
606                 public void OpenReadIOException ()\r
607                 {\r
608                         string path = TempFolder + DSC + "FIT.OpenReadIOException.Test";\r
609                         DeleteFile (path);\r
610                         FileStream stream = null;\r
611                         \r
612                         try {\r
613                                 stream = File.Create (path);\r
614                                 FileInfo info = new FileInfo (path);\r
615                                 info.OpenRead ();\r
616                         } finally {\r
617                                 if (stream != null)\r
618                                         stream.Close ();\r
619                                 DeleteFile (path);\r
620                         }\r
621                 }\r
622 \r
623                 [Test]\r
624                 [ExpectedException(typeof (UnauthorizedAccessException))]\r
625                 public void OpenReadUnauthorizedAccessException ()\r
626                 {\r
627                         string path = TempFolder;\r
628                         \r
629                         FileInfo info = new FileInfo (path);\r
630                         info.OpenRead ();\r
631                 }\r
632                 \r
633                 [Test]\r
634                 public void OpenText ()\r
635                 {\r
636                         string path = TempFolder + DSC + "FIT.OpenText.Test";\r
637                         DeleteFile (path);\r
638                         StreamReader reader = null;\r
639                         try {\r
640                                 File.Create (path).Close ();\r
641                                 FileInfo info = new FileInfo (path);\r
642                                 reader = info.OpenText ();\r
643                                 AssertEquals ("test#01", -1, reader.Peek ());           \r
644                         } finally {\r
645                                 \r
646                                 if (reader != null)\r
647                                         reader.Close ();\r
648                                 DeleteFile (path);\r
649                         }\r
650                 }\r
651                 \r
652                 [Test]\r
653                 [ExpectedException(typeof (FileNotFoundException))]\r
654                 public void OpenTextFileNotFoundException ()\r
655                 {\r
656                         string path = TempFolder + DSC + "FIT.OpenTextFileNotFoundException.Test";\r
657                         DeleteFile (path);\r
658                         FileInfo info = new FileInfo (path);\r
659                         info.OpenText ();\r
660                 }\r
661 \r
662                 [Test]\r
663                 [ExpectedException(typeof (UnauthorizedAccessException))]\r
664                 public void OpenTextUnauthorizedAccessException ()\r
665                 {\r
666                         string path = TempFolder;\r
667                         \r
668                         FileInfo info = new FileInfo (path);\r
669                         info.OpenText ();\r
670                 }\r
671 \r
672                 [Test]\r
673                 public void OpenWrite ()\r
674                 {\r
675                         string path = TempFolder + DSC + "FIT.OpenWrite.Test";\r
676                         DeleteFile (path);\r
677                         FileStream stream = null;\r
678                         try {\r
679                                 File.Create (path).Close ();\r
680                                 FileInfo info = new FileInfo (path);\r
681                                 stream = info.OpenWrite ();\r
682                                 AssertEquals ("test#01", false, stream.CanRead);\r
683                                 AssertEquals ("test#02", true, stream.CanSeek);\r
684                                 AssertEquals ("test#03", true, stream.CanWrite);\r
685                         } finally {\r
686                                 \r
687                                 if (stream != null)\r
688                                         stream.Close ();\r
689                                 DeleteFile (path);\r
690                         }\r
691                 }\r
692                 \r
693                 [Test]\r
694                 [ExpectedException(typeof (UnauthorizedAccessException))]\r
695                 public void OpenWriteUnauthorizedAccessException ()\r
696                 {\r
697                         string path = TempFolder;\r
698                         \r
699                         FileInfo info = new FileInfo (path);\r
700                         info.OpenWrite ();\r
701                 }\r
702 \r
703                 private void DeleteFile (string path)\r
704                 {\r
705                         if (File.Exists (path))\r
706                                 File.Delete (path);\r
707                 }\r
708 \r
709                 [Test]\r
710                 public void ToStringVariety ()\r
711                 {\r
712                         AssertEquals ("foo", new FileInfo ("foo").ToString ());\r
713                         AssertEquals ("c:/foo", new FileInfo ("c:/foo").ToString ());\r
714                         AssertEquals ("/usr/local/foo", new FileInfo ("/usr/local/foo").ToString ());\r
715                         AssertEquals ("c:\\foo", new FileInfo ("c:\\foo").ToString ());\r
716                         AssertEquals ("/usr/local\\foo", new FileInfo ("/usr/local\\foo").ToString ());\r
717                         AssertEquals ("foo/BAR/baz", new FileInfo ("foo/BAR/baz").ToString ());\r
718                         AssertEquals ("c:/documents and settings", new FileInfo ("c:/documents and settings").ToString ());\r
719                         AssertEquals ("c:/docUme~1", new FileInfo ("c:/docUme~1").ToString ());\r
720                 }\r
721         }\r
722 }\r
723 \r