FileInfoTest.cs 19 KB

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