⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesystemtests.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 3 页
字号:
        fs = File.Create(DATA_DIR + sep_ch + test_file)        Thread.Sleep(60)        Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")        ' Add some information to the file.        fs.Write(info, 0, info.Length)        fs.Close()        modify_time = File.GetLastAccessTime(DATA_DIR + sep_ch + test_file)        test_time = FileSystem.FileDateTime(DATA_DIR + sep_ch + test_file)        Assert.AreEqual(modify_time, test_time, "Modification Time should be the same")        Thread.Sleep(60)        File.Delete(DATA_DIR + sep_ch + test_file)    End Sub#End If    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub FileDateTime_3()        FileSystem.FileDateTime("")    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub FileDateTime_4()        FileSystem.FileDateTime("c:\test_wrong_path\?")    End Sub    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub FileDateTime_5()        Dim test_file As String = "FileDateTime_test3.txt"        FileSystem.FileDateTime(test_file)    End Sub#End Region#Region "FileLen"    <Test()> _    Public Sub FileLen_1()        Dim test_file As String = "FileLen_test1.dat"        Dim file_len As Integer        Dim fs As FileStream        fs = File.Create(DATA_DIR + sep_ch + test_file)        Thread.Sleep(60)        Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")        ' Add some information to the file.        fs.Write(info, 0, info.Length)        fs.Close()        file_len = FileSystem.FileLen(DATA_DIR + sep_ch + test_file)        Assert.AreEqual(30, file_len)        Thread.Sleep(60)        File.Delete(DATA_DIR + sep_ch + test_file)    End Sub    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub FileLen_2()        FileSystem.FileLen("")    End Sub    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub FileLen_3()        Dim test_dir As String = "FileLen_test3.dat"        FileSystem.FileLen(test_dir)    End Sub#End Region#Region "GetAttr"    'TargetJvmNotSupported - File metadata/attributes feature is not supported     <Test(), Category("TargetJvmNotSupported")> _    Public Sub GetAttr_1()        '' check attr to file        Dim test_file As String = "GetAttr_test1.dat"        Dim file_attr, req_attr As FileAttribute        Dim fs As FileStream        req_attr = FileAttributes.Hidden Or FileAttributes.Archive        fs = File.Create(DATA_DIR + sep_ch + test_file)        Thread.Sleep(60)        fs.Close()        File.SetAttributes(DATA_DIR + sep_ch + test_file, req_attr)        file_attr = FileSystem.GetAttr(DATA_DIR + sep_ch + test_file)        Assert.AreEqual(req_attr.ToString(), file_attr.ToString())        Thread.Sleep(60)        File.Delete(DATA_DIR + sep_ch + test_file)    End Sub    'TargetJvmNotSupported - File metadata/attributes feature is not supported     <Test(), Category("TargetJvmNotSupported")> _    Public Sub GetAttr_2()        '' check attr to directory        Dim test_dir As String = "GetAttr_Dirtest2"        Dim file_attr, req_attr As FileAttribute        req_attr = FileAttributes.Hidden Or FileAttributes.Archive Or FileAttributes.Directory        Directory.CreateDirectory(DATA_DIR + sep_ch + test_dir)        File.SetAttributes(DATA_DIR + sep_ch + test_dir, req_attr)        file_attr = FileSystem.GetAttr(DATA_DIR + sep_ch + test_dir)        Assert.AreEqual(req_attr, file_attr)        Thread.Sleep(60)        Directory.Delete(DATA_DIR + sep_ch + test_dir)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub GetAttr_3()        FileSystem.GetAttr("")    End Sub    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub GetAttr_4()        Dim test_dir As String = "GetAttr_test4.dat"        FileSystem.GetAttr(test_dir)    End Sub#End Region#Region "Kill"    <Test()> _    Public Sub Kill_1()        '' kill one file        Dim test_file1 As String = "Kill_1_test1.dat"        Dim fs As FileStream = File.Create(DATA_DIR + sep_ch + test_file1, 1024)        fs.Close()        FileSystem.Kill(DATA_DIR + sep_ch + test_file1)        Thread.Sleep(60)        Assert.AreEqual(False, File.Exists(DATA_DIR + sep_ch + test_file1))    End Sub    <Test()> _    Public Sub Kill_2()        '' kill files with *.dat        Dim test_file1 As String = "Kill_2_test1.dat"        Dim test_file2 As String = "Kill_2_test2.dat"        Dim fs As FileStream = File.Create(DATA_DIR + sep_ch + test_file1, 1024)        Dim fs1 As FileStream = File.Create(DATA_DIR + sep_ch + test_file2, 1024)        fs.Close()        fs1.Close()        FileSystem.Kill(DATA_DIR + sep_ch + "Kill*.dat")        Thread.Sleep(60)        Assert.AreEqual(False, File.Exists(DATA_DIR + sep_ch + test_file1), "kill need to remove also Kill_2_test1.dat")        Assert.AreEqual(False, File.Exists(DATA_DIR + sep_ch + test_file2), "kill need to remove also Kill_2_test2.dat")    End Sub    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub Kill_3()        '' try to kill a directory        Dim test_dir As String = "Kill_Dirtest2"        Directory.CreateDirectory(DATA_DIR + sep_ch + test_dir)        FileSystem.Kill(DATA_DIR + sep_ch + test_dir)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub Kill_4()        FileSystem.Kill("")    End Sub    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub Kill_5()        Dim test_dir As String = "Kill_test4.dat"        FileSystem.Kill(test_dir)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub Kill_6()        '' * in the path        Dim test_dir As String = "Kill_test4.dat"        FileSystem.Kill(DATA_DIR + "*" + sep_ch + test_dir)    End Sub#End Region#Region "MKDir"    <Test()> _    Public Sub MKDir_1()        Dim test_dir As String = "MKDir_test1"        FileSystem.MkDir(DATA_DIR + sep_ch + test_dir)        Dim dirinfo As New DirectoryInfo(DATA_DIR + sep_ch + test_dir)        Assert.AreEqual(True, dirinfo.Exists)        Directory.Delete(DATA_DIR + sep_ch + test_dir)    End Sub    <Test(), ExpectedException(GetType(IOException))> _    Public Sub MKDir_2()        Dim test_dir As String = "MKDir_test2"        Directory.CreateDirectory(DATA_DIR + sep_ch + test_dir)        FileSystem.MkDir(DATA_DIR + sep_ch + test_dir)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub MKDir_3()        FileSystem.MkDir("")    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub MKDir_4()        Dim test_dir As String = "MKdir_t<est3"        FileSystem.MkDir(DATA_DIR + sep_ch + test_dir)    End Sub#End Region#Region "Rename"    <Test()> _    Public Sub Rename_1()        '' rename directory        Dim test_dir As String = "Rename_test1"        Dim test_dir_new As String = "Rename_test1_new"        Directory.CreateDirectory(DATA_DIR + sep_ch + test_dir)        FileSystem.Rename(DATA_DIR + sep_ch + test_dir, DATA_DIR + sep_ch + test_dir_new)        Dim dirinfo_new As New DirectoryInfo(DATA_DIR + sep_ch + test_dir_new)        Assert.AreEqual(True, dirinfo_new.Exists)        Thread.Sleep(60)        Directory.Delete(DATA_DIR + sep_ch + test_dir_new)    End Sub    <Test()> _    Public Sub Rename_2()        '' rename file        Dim test_file As String = "Rename_test2.txt"        Dim test_file_new As String = "Rename_test2_new.dat"        Dim fs As FileStream = File.Create(DATA_DIR + sep_ch + test_file, 1024)        fs.Close()        FileSystem.Rename(DATA_DIR + sep_ch + test_file, DATA_DIR + sep_ch + test_file_new)        Dim fileinfo_new As New FileInfo(DATA_DIR + sep_ch + test_file_new)        Assert.AreEqual(True, fileinfo_new.Exists)        File.Delete(DATA_DIR + sep_ch + test_file_new)    End Sub#If NET_VER >= 2.0 Then    <Test(), ExpectedException(GetType(IOException))> _    Public Sub Rename_3()#Else    <Test(), ExpectedException(GetType(FileNotFoundException))> _    Public Sub Rename_3()#End If        Dim test_dir As String = "Rename_test3"        Dim tmp_dir As String = "Try_Dir"        Directory.CreateDirectory(DATA_DIR + sep_ch + test_dir)        Directory.CreateDirectory(DATA_DIR + sep_ch + tmp_dir)        FileSystem.Rename(DATA_DIR + sep_ch + test_dir, DATA_DIR + sep_ch + tmp_dir)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub Rename_4()        FileSystem.Rename("", "Test")    End Sub#If NET_2_0 Then    <Test(), ExpectedException(GetType(FileNotFoundException))> _     Public Sub Rename_5()        Dim test_dir As String = "Rename_test5"        FileSystem.Rename("fff", test_dir)    End Sub#Else       <Test(), ExpectedException(GetType(ArgumentException))> _        Public Sub Rename_5()            Dim test_dir As String = "Rename_test5"            FileSystem.Rename("fff", test_dir)        End Sub#End If    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub Rename_6()        Dim test_file As String = "Rename_t<est6"        Dim test_file2 As String = "Rename_test6"        Dim fs As FileStream = File.Create(DATA_DIR + sep_ch + test_file, 1024)        Dim fs1 As FileStream = File.Create(DATA_DIR + sep_ch + test_file2, 1024)        fs.Close()        fs1.Close()        FileSystem.Rename(DATA_DIR + sep_ch + test_file, DATA_DIR + sep_ch + test_file2)    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub Rename_7()        Dim test_file As String = "Rename_test7.dat"        Dim fs As FileStream = File.Create(DATA_DIR + sep_ch + test_file, 1024)        FileSystem.Rename(test_file, "")    End Sub    <Test(), ExpectedException(GetType(ArgumentException))> _    Public Sub Rename_8()        '' move a file to unavailable directory         Dim test_file As String = "Rename_test8.txt"        Dim test_file_new As String = "Rename_test8_new.dat"        Dim fs As FileStream = File.Create(DATA_DIR + sep_ch + test_file, 1024)        fs.Close()        FileSystem.Rename(DATA_DIR + sep_ch + test_file, DATA_DIR + sep_ch + "not_there" + sep_ch + test_file_new)        Dim fileinfo_new As New FileInfo(DATA_DIR + sep_ch + test_file_new)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -