5
我想在模擬界面中引發一個事件。我可以在C#中獲得這個,但是由於一些痛苦的原因,無法在VB.Net中使用它。如果有人能幫助我解決這種情況,我會很感激。希望我在概念上沒有錯過船,我所缺少的是一些語法。這類似於我的工作代碼:如何使用Moq提高事件?
Public Interface ISendable
Event SendMessage(message As String)
End Interface
''**********
Public Interface IPrintable
Sub PrintAnnouncement(announcement As String)
End Interface
'******
Public Class BulletinBoard
Private mPrintable As IPrintable
Public Sub New(sendable As ISendable, printable As IPrintable)
AddHandler sendable.SendMessage, AddressOf GetItOut
mPrintable = printable
End Sub
Public Sub GetItOut(message As String)
'Do some stuff I can verify happened with Moq
mPrintable.PrintAnnouncement(message)
End Sub
End Class
我希望得到一個測試,看起來是這樣運行的:
Imports NUnit.Framework
Imports Moq
<TestFixture()> _
Public Class SendMessageTests
<Test()> _
Public Sub canRaiseEvent()
Dim announcement As String = "What the?"
Dim sendable As New Mock(Of ISendable)()
Dim printable As New Mock(Of IPrintable)()
Dim bb As New BulletinBoard(sendable.Object, printable.Object)
'What is the syntax for raising sendable's event?
'sendable.Raise(....?)
printable.Verify(Sub(d) d.PrintAnnouncement(announcement), Times.Once())
End Sub
End Class
誰能幫助我完成或更正線在我的測試類中開始「sendable.Raise ...」?也許我需要做更多的設置,但Moq網站似乎並沒有表明這是事實。
在此先感謝。
非常好,nemesv - 就是我以後的樣子。謝謝你這麼快回答。 – RobC 2012-01-31 21:55:55