我的测试用例在assert.fail()
失败了,我不知道它到底出了什么问题以及失败的地方。有任何想法让这个测试用例通过
以下是测试用例
<Test()> _
Public Sub SendFtpFailureEmailShouldPassWithProcessingInfosAndSendEmail()
Dim em As EmailNotification = New EmailNotification()
Try
Dim pfis As ProcessingFileInfos = New ProcessingFileInfos(New FileInfo(AppSettingsReader.SchemaLocation), "Ftp")
Dim pfi1 As ProcessingFileInfo = New ProcessingFileInfo(New FileInfo("Test1.xml"))
pfi1.ContainsErrors = True
pfi1.Message = "File Failed"
pfi1.FileProcessStatus = "F"
pfi1.Channel = "Ftp"
pfis.Add(pfi1)
Dim pfi2 As ProcessingFileInfo = New ProcessingFileInfo(New FileInfo("Test2.xml"))
pfi2.ContainsErrors = True
pfi2.Message = "File Failed on Bad Data"
pfi2.FileProcessStatus = "F"
pfi2.Channel = "Ftp"
pfis.Add(pfi2)
Dim result As String = em.CreateFtpFailureEmail(pfis)
Assert.IsNotEmpty(result, "result is invalid")
Dim emailDetails As Email = New Email() With {.Body = result, _
.FromEmail = AppSettingsReader.TPLFromEmail, _
.FromEmailName = AppSettingsReader.TPLFromEmailName, _
.SmtpHost = AppSettingsReader.SmtpHost, _
.Subject = "FTP Failure Report", _
.ToEmail = "runu.ali@cdsglobal.co.uk"}
em.SendEmail(emailDetails)
Catch ex As Exception
Assert.Fail(ex.Message)
End Try
End Sub
发送以下邮件代码:
Public Sub SendEmail(ByVal emailObj As Email)
Try
If emailObj Is Nothing Then
Throw New ArgumentNullException("emailObj", "emailObj cannot be null or empty")
End If
Dim em As New Net.Mail.MailMessage()
em.From = New MailAddress(emailObj.FromEmail, emailObj.FromEmailName)
em.To.Add(New MailAddress(emailObj.ToEmail))
em.Subject = emailObj.Subject
em.Body = emailObj.Body
em.IsBodyHtml = True
Dim SmTP As SmtpClient = New SmtpClient()
SmTP.Host = emailObj.SmtpHost
SmTP.Send(em)
Catch ex As SmtpException
Throw
Catch ex As FormatException
Throw
End Try
End Sub