Преглед изворни кода

2010-05-24 Carlos Alberto Cortez <[email protected]>

	* IsolatedStorageFileTest.cs: New test cases for CreateFile,
	MoveDirectory and MoveFile.


svn path=/trunk/mcs/; revision=157817
Carlos Alberto Cortez пре 15 година
родитељ
комит
b2c81e0142

+ 5 - 0
mcs/class/corlib/Test/System.IO.IsolatedStorage/ChangeLog

@@ -1,3 +1,8 @@
+2010-05-24  Carlos Alberto Cortez <[email protected]>
+
+	* IsolatedStorageFileTest.cs: New test cases for CreateFile,
+	MoveDirectory and MoveFile.
+
 2010-05-23  Carlos Alberto Cortez <[email protected]>
 
 	* IsolatedStorageFileTest.cs: New test cases for DirectoryExists and

+ 88 - 0
mcs/class/corlib/Test/System.IO.IsolatedStorage/IsolatedStorageFileTest.cs

@@ -597,6 +597,94 @@ namespace MonoTests.System.IO.IsolatedStorageTest {
 			} catch (ObjectDisposedException) {
 			}
 		}
+
+		[Test]
+		public void CreateFile ()
+		{
+			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
+			// Make sure we are actually creating it, by first removing it in case it already exists
+			if (isf.FileExists ("file-a"))
+				isf.DeleteFile ("file-a");
+
+			IsolatedStorageFileStream isf_stream = isf.CreateFile ("file-a");
+			isf_stream.Close ();
+			Assert.AreEqual (true, isf.FileExists ("file-a"), "#A0");
+
+			// Re-open the file that is already created, so we make sure we are passing
+			// the proper FileOpen
+			isf_stream = isf.CreateFile ("file-a");
+			isf_stream.Close ();
+
+			try {
+				isf.CreateFile (null);
+				Assert.Fail ("#Exc1");
+			} catch (ArgumentNullException) {
+			}
+
+			try {
+				isf.CreateFile ("random-dir/fileb");
+				Assert.Fail ("#Exc2");
+			} catch (DirectoryNotFoundException) {
+			}
+
+			isf.Close ();
+			try {
+				isf.CreateFile ("file-b");
+				Assert.Fail ("#Exc3");
+			} catch (InvalidOperationException) {
+			}
+
+			isf.Dispose ();
+			try {
+				isf.CreateFile ("file-a");
+				Assert.Fail ("#Exc4");
+			} catch (ObjectDisposedException) {
+			}
+		}
+
+		[Test]
+		public void MoveDirectory ()
+		{
+			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
+			// Mare sure to remove them if they exist already
+			if (isf.DirectoryExists ("subdir"))
+				isf.DeleteDirectory ("subdir");
+			if (isf.DirectoryExists ("subdir-new"))
+				isf.DeleteDirectory ("subdir-new");
+
+			isf.CreateDirectory ("subdir");
+			Assert.AreEqual (true, isf.DirectoryExists ("subdir"), "#A0");
+
+			isf.MoveDirectory ("subdir", "subdir-new");
+			Assert.AreEqual (false, isf.DirectoryExists ("subdir"), "#A1");
+			Assert.AreEqual (true, isf.DirectoryExists ("subdir-new"), "#A2");
+
+			isf.DeleteDirectory ("subdir-new");
+			isf.Close ();
+			isf.Dispose ();
+		}
+
+		[Test]
+		public void MoveFile ()
+		{
+			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
+			// Mare sure to remove them if they exist already
+			if (isf.FileExists ("file"))
+				isf.DeleteFile ("file");
+			if (isf.FileExists ("file-new"))
+				isf.DeleteFile ("file-new");
+
+			isf.CreateFile ("file").Close ();
+			Assert.AreEqual (true, isf.FileExists ("file"), "#A0");
+
+			isf.MoveFile ("file", "file-new");
+			Assert.AreEqual (false, isf.FileExists ("file"), "#A1");
+			Assert.AreEqual (true, isf.FileExists ("file-new"), "#A2");
+
+			isf.DeleteFile ("file-new");
+			isf.Close ();
+			isf.Dispose ();
+		}
 #endif
 	}
 }