Can anyone help me on  why this test fail? I got error like:
Test method TestwwwrootWAP.sendEmailTest.SendTest threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException:
IsendEmail.IsValid("[email protected]"); Expected #1, Actual #0.

Trace Stack:
Rhino.Mocks.RhinoMocksExtensions.AssertWasCalled[T](T mock, Action`1
action, Action`1 setupConstraints)
Rhino.Mocks.RhinoMocksExtensions.AssertWasCalled[T](T mock, Func`2
action)

This is the test code:
 Public Sub SendTest()

        'arrange
        Dim sender As IsendEmail = MockRepository.GenerateMock(Of
IsendEmail)()
        Dim toEmail As String = "[email protected]"
        Dim fromEmail As String = "[email protected]"
        Dim subject As String = "using mock"
        Dim msg As String = "test the behavior"
        'act
        Dim target As EmailHelper = New EmailHelper(sender)
        sender.Stub(Function(x) x.IsValid(toEmail)).[Return](True)
        sender.Stub(Function(x) x.IsValid(fromEmail)).[Return](True)
        Dim actual As Boolean = target.Send(toEmail, fromEmail,
subject, msg)

        'assert
        sender.AssertWasCalled(Function(x) x.IsValid(toEmail))
        sender.AssertWasCalled(Function(x) x.IsValid(fromEmail))
        Assert.AreEqual(True, actual)

    End Sub
Here is the under test class:

Imports Microsoft.VisualBasic
Imports System.Net.Mail
Imports System.Text.RegularExpressions

Public Class EmailHelper
    Implements IsendEmail

    Private smtpClient As IsendEmail

    Public Sub New(ByRef smtpClient As IsendEmail)
        Me.smtpClient = smtpClient
    End Sub


    Public Function Send(ByVal ToEmail As String, ByVal FromEmail As
String, ByVal StrSubject As String, ByVal StrMsg As String) As Boolean
Implements IsendEmail.Send
        Dim result As Boolean = True
        Try
            If IsValid(ToEmail) And IsValid(FromEmail) Then

                Me.smtpClient.Send(ToEmail, FromEmail, StrSubject,
StrMsg)

                result = True

            End If
            Return result
        Catch ex As Exception
            Throw ex
        End Try

    End Function



    Public Function IsValid(ByVal emailAddress As String) As Boolean
Implements IsendEmail.IsValid
        Return Regex.IsMatch(emailAddress, "^([0-9a-zA-Z]([-\.
\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$")
    End Function

End Class
and interface is:
Imports System.Net.Mail

Public Interface IsendEmail
    Function Send(ByVal ToEmail As String, ByVal FromEmail As String,
ByVal StrSubject As String, ByVal StrMsg As String) As Boolean
    Function IsValid(ByVal email As String) As Boolean
End Interface
Thank you
Li Aishen

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to