2
0

FileInfoTest.cs 19 KB

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