public void CopyFileTest() { using (IStorage storage = new StorageTest()) { var basePath = storage.BasePath + "CopyFileTest/"; Directory.CreateDirectory(basePath); File.WriteAllText(basePath + "file1.txt", "TESTING\n123"); storage.CopyFile("CopyFileTest/file1.txt", "CopyFileTest/Copy/copied_file1.txt"); storage.CopyFile("CopyFileTest/file1.txt", "CopyFileTest/copied_file2.txt"); Assert.IsTrue(Directory.Exists(basePath + "Copy/")); Assert.IsTrue(File.Exists(basePath + "file1.txt")); Assert.IsTrue(File.Exists(basePath + "Copy/copied_file1.txt")); Assert.IsTrue(File.Exists(basePath + "copied_file2.txt")); string file1Content = File.ReadAllText((basePath + "file1.txt"), System.Text.Encoding.UTF8); string copiedFile1Content = File.ReadAllText((basePath + "Copy/copied_file1.txt"), System.Text.Encoding.UTF8); string copiedFile2Content = File.ReadAllText((basePath + "copied_file2.txt"), System.Text.Encoding.UTF8); Assert.AreEqual(file1Content, copiedFile1Content); Assert.AreEqual(file1Content, copiedFile2Content); } }
public static void TestClassInitialize(TestContext testContext) { TestHelper.InitializeTests(); using (IStorage storage = new StorageTest()) { var basePath = storage.BasePath; if(Directory.Exists(basePath)) Directory.Delete(basePath,true); } }
public void CopyDirectoryTest() { using (IStorage storage = new StorageTest()) { var basePath = storage.BasePath + "CopyDirectoryTest/"; Directory.CreateDirectory(basePath + "CopyDirectoryTestFolder1/f2/f3"); var file1 = File.Create(basePath + "CopyDirectoryTestFolder1/f2/f3/file1.txt"); file1.Close(); var file2 = File.Create(basePath + "CopyDirectoryTestFolder1/f2/file2.bin"); file2.Close(); storage.CopyDirectory("CopyDirectoryTest/CopyDirectoryTestFolder1", "CopyDirectoryTest/CopyDirectoryTestFolder1_copy"); Assert.IsTrue(Directory.Exists(basePath + "CopyDirectoryTestFolder1_copy")); Assert.IsTrue(Directory.Exists(basePath + "CopyDirectoryTestFolder1_copy/f2")); Assert.IsTrue(Directory.Exists(basePath + "CopyDirectoryTestFolder1_copy/f2/f3")); Assert.IsTrue(File.Exists(basePath + "CopyDirectoryTestFolder1_copy/f2/file2.bin")); Assert.IsTrue(File.Exists(basePath + "CopyDirectoryTestFolder1_copy/f2/f3/file1.txt")); } }
public void DeleteDirectoryTest() { using (IStorage storage = new StorageTest()) { var basePath = storage.BasePath + "DeleteDirectoryTest/"; Directory.CreateDirectory(basePath); Directory.CreateDirectory(basePath + "Folder1/F2/F3"); var file1 = File.Create(basePath + "Folder1/F2/F3/file1.txt"); file1.Close(); var file2 = File.Create(basePath + "Folder1/F2/F3/file2.bin"); file2.Close(); storage.DeleteDirectory("DeleteDirectoryTest/Folder1/F2"); Assert.IsTrue(Directory.Exists(basePath + "Folder1")); Assert.IsFalse(Directory.Exists(basePath + "Folder1/F2")); } }
public void ReadWriteTextFileTest() { using (IStorage storage = new StorageTest()) { var basePath = storage.BasePath + "ReadWriteTextFileTest/"; Directory.CreateDirectory(basePath); storage.WriteTextFile("ReadWriteTextFileTest/test.txt", "test123"); Assert.AreEqual(storage.ReadTextFile("ReadWriteTextFileTest/test.txt"), "test123"); } }
public void OpenFileTest() { using (IStorage storage = new StorageTest()) { var basePath = storage.BasePath + "OpenFileTest/"; Directory.CreateDirectory(basePath); var file1 = File.Create(basePath + "file1.txt"); file1.Close(); Stream fileStream1 = storage.OpenFile("OpenFileTest/file1.txt", StorageFileMode.OpenOrCreate, StorageFileAccess.ReadWrite); Assert.IsTrue(fileStream1.CanRead); Assert.IsTrue(fileStream1.CanWrite); fileStream1.Close(); Stream fileStream2 = storage.OpenFile("OpenFileTest/file2.txt", StorageFileMode.OpenOrCreate, StorageFileAccess.Read); Assert.IsTrue(fileStream2.CanRead); Assert.IsFalse(fileStream2.CanWrite); fileStream2.Close(); Stream fileStream3 = storage.OpenFile("OpenFileTest/file2.txt", StorageFileMode.OpenOrCreate, StorageFileAccess.Write); Assert.IsFalse(fileStream3.CanRead); Assert.IsTrue(fileStream3.CanWrite); fileStream3.Close(); } }
public void LoadImageTest() { using (IStorage storage = new StorageTest()) { var basePath = "LoadImageTest/"; var sampleProjectsPath = BasePathHelper.GetSampleProjectsPath(); Directory.CreateDirectory(storage.BasePath + basePath); Stream stream = ResourceLoader.GetResourceStream(ResourceScope.TestCommon, sampleProjectsPath + "test.catroid"); CatrobatZip.UnzipCatrobatPackageIntoIsolatedStorage(stream, basePath); stream.Close(); var image = storage.LoadImage("LoadImageTest/screenshot.png"); Assert.AreNotEqual(image, null); } }