Committed a couple of FileSystem methods and associated Test cases
[mono.git] / mcs / class / Microsoft.VisualBasic / Test / Microsoft.VisualBasic / FileSystemTest.cs
index 58af5dbe57e29c5f541806f50c83f9bd382f764e..1b130b5bd9530103363001d93b3f7632860fdb6f 100755 (executable)
@@ -8,6 +8,7 @@
 
 using NUnit.Framework;
 using System;
+using System.IO;
 using Microsoft.VisualBasic;
 
 namespace MonoTests.Microsoft.VisualBasic
@@ -15,13 +16,74 @@ namespace MonoTests.Microsoft.VisualBasic
 
        [TestFixture]
        public class FileSystemTest : Assertion {
-       
+               string oldDir = "";
+               
                [SetUp]
-               public void GetReady() {}
+               public void GetReady() 
+               {
+                       oldDir = Environment.CurrentDirectory;
+               }
 
                [TearDown]
-               public void Clean() {}
-
+               public void Clean() 
+               {
+                       // reset dir
+                       Environment.CurrentDirectory = oldDir;
+               }       
+               
+               // ChDir
+               
+               [Test]
+               [ExpectedException (typeof(ArgumentException))]
+               public void ChDirArg1()
+               {
+                       FileSystem.ChDir ("");
+               }
+               
+               [Test]
+               [ExpectedException (typeof(FileNotFoundException))]
+               public void ChDirArg2()
+               {
+                       FileSystem.ChDir ("z:\\home\rob");
+               }
+               
+               [Test]
+               public void TestChDir()
+               {
+                       // change the current dir to parent dir
+                       DirectoryInfo parent = Directory.GetParent (Environment.CurrentDirectory);
+                       FileSystem.ChDir (parent.FullName);
+                       AssertEquals ("CHDIR#01", parent.FullName, Environment.CurrentDirectory);                       
+               }
+               
+               [Test]
+               [ExpectedException (typeof(FileNotFoundException))]
+               public void ChDriveArgs1()
+               {
+                       FileSystem.ChDir ("z:\\home\rob");
+               }
+               
+               [Test]
+               public void TestChDrive()
+               {
+                       string[] drives = Directory.GetLogicalDrives ();
+                       
+                       foreach (string drive in drives) {
+                               // skip diskdrive, if no disk is present it fails.
+                               if (drive.ToLower()[0] == 'a')
+                                       continue;
+                               FileSystem.ChDrive (drive);
+                               Assert ("ChDrive#01", Environment.CurrentDirectory.StartsWith (drive));
+                       }
+               }
+               
+               [Test]
+               public void TestCurDir()
+               {
+                       string dir = FileSystem.CurDir ();
+                       AssertEquals ("CurDir#01", Environment.CurrentDirectory, dir);
+               }
+/*
                [Test]
                [ExpectedException(typeof(ArgumentException))]
                public void TestDir() {
@@ -35,6 +97,6 @@ namespace MonoTests.Microsoft.VisualBasic
                                "FileSystem.cs",
                                FileSystem.Dir("./Microsoft.VisualBasic/FileSystem.cs", FileAttribute.Normal)) ;
                }
-
+*/
        }
 }