📄 networktests.vb
字号:
Dim testname As String = "DownloadFileTest2" Dim nw As New Network() If Not ConnectedToInternet() Then Assert.Ignore("No internet connection, so skipping download tests") Return End If Assert.Ignore("These tests are not implemented fully yet anyway") Dim smallrealFile As String = "http://www.google.com" Dim bigrealfile As String = "http://www.mono-project.com/" Dim imaginaryFile As String = "http://www.changemeifiexist.nowhere/nofile" Dim destination As String = Path.Combine(BASEDIR, "destination") Dim localsmallrealfile As String = Path.Combine(BASEDIR, "localsmallrealfile") Dim localbigrealfile As String = Path.Combine(BASEDIR, "localbigrealfile") Dim pwd As String Dim user As String Dim showUI As Boolean Dim timeout As Integer Dim onCancel As Microsoft.VisualBasic.FileIO.UICancelOption Dim credentials As Net.NetworkCredential Dim smalluri, biguri, imaginaryuri As Uri Dim i As Integer Dim overwrite As Boolean Using client As New Net.WebClient() client.DownloadFile(smallrealFile, localsmallrealfile) client.DownloadFile(bigrealfile, localbigrealfile) End Using smalluri = New Uri(smallrealFile) biguri = New Uri(bigrealfile) imaginaryuri = New Uri(imaginaryFile) '----------------------------- i += 1 IO.File.Delete(destination) nw.DownloadFile(smalluri, destination) Helper.CompareFile(destination, localsmallrealfile, testname & "-01") IO.File.Delete(destination) nw.DownloadFile(biguri, destination) Helper.CompareFile(destination, localbigrealfile, testname & "-02") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination) Assert.Fail(testname & "-03 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-04") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty IO.File.Delete(destination) nw.DownloadFile(smalluri, destination, pwd, user) Helper.CompareFile(destination, localsmallrealfile, testname & "-" & i & "1") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = "pwd" user = "user" IO.File.Delete(destination) nw.DownloadFile(smalluri, destination, pwd, user) Helper.CompareFile(destination, localsmallrealfile, testname & "-" & i & "1") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user) Assert.Fail(testname & "-" & i & "03 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = False IO.File.Delete(destination) nw.DownloadFile(smalluri, destination, pwd, user, showUI, timeout, overwrite) Helper.CompareFile(destination, localsmallrealfile, testname & "-" & i & "1") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = True IO.File.Delete(destination) nw.DownloadFile(smalluri, destination, pwd, user, showUI, timeout, overwrite) Helper.CompareFile(destination, localsmallrealfile, testname & "-" & i & "1") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = True nw.DownloadFile(smalluri, destination, pwd, user, showUI, timeout, overwrite) Helper.CompareFile(destination, localsmallrealfile, testname & "-" & i & "1") nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = True onCancel = Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing IO.File.Delete(destination) nw.DownloadFile(smalluri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Helper.CompareFile(destination, localsmallrealfile, testname & "-" & i & "1") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = True onCancel = Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException MsgBox("Please cancel the next download.") IO.File.Delete(destination) Try nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Assert.Fail(testname & "-" & i & "1" & "?") Catch ex As OperationCanceledException Assert.AreEqual("?", ex.Message, testname & "-" & i & "2") End Try Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = True onCancel = Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing MsgBox("Please cancel the next download.") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = False onCancel = Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException credentials = New Net.NetworkCredential(user, pwd) IO.File.Delete(destination) nw.DownloadFile(smalluri, destination, credentials, showUI, timeout, overwrite) Helper.CompareFile(destination, localsmallrealfile, testname & "-" & i & "1") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = False onCancel = Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException credentials = New Net.NetworkCredential(user, pwd) MsgBox("Please cancel the next download.") IO.File.Delete(destination) Try nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Assert.Fail(testname & "-" & i & "1" & "?") Catch ex As OperationCanceledException Assert.AreEqual("?", ex.Message, testname & "-" & i & "2") End Try Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try '----------------------------- i += 1 pwd = String.Empty user = String.Empty showUI = True timeout = 100000 overwrite = False onCancel = Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing credentials = New Net.NetworkCredential(user, pwd) MsgBox("Please cancel the next download.") IO.File.Delete(destination) nw.DownloadFile(biguri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Helper.CompareFile(destination, localbigrealfile, testname & "-" & i & "2") Try IO.File.Delete(destination) nw.DownloadFile(imaginaryuri, destination, pwd, user, showUI, timeout, overwrite, onCancel) Assert.Fail(testname & "-" & i & "3 " & "?") Catch ex As Exception Assert.AreEqual("?", ex.Message, testname & "-" & i & "4") End Try End Sub <Category("Slow")> _ <Test()> _ <Category("UI")> _ Public Sub UploadFileTest1() Dim testname As String = "UploadFileTest1" Dim nw As New Network() If Not ConnectedToInternet() Then Assert.Ignore("No internet connection, so skipping upload tests") Return End If Assert.Ignore("Need some server to where to upload for this to work") End Sub Private Sub MsgBox(ByVal Message As String, Optional ByVal Style As Microsoft.VisualBasic.MsgBoxStyle = Microsoft.VisualBasic.MsgBoxStyle.OkOnly Or Microsoft.VisualBasic.MsgBoxStyle.Information) Microsoft.VisualBasic.Interaction.MsgBox(Message, Style Or Microsoft.VisualBasic.MsgBoxStyle.SystemModal) End Sub End ClassEnd Namespace#End If#End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -