Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I raise an event using Moq?
    primarykey
    data
    text
    <p>I'm trying to raise an event in a mocked interface. I can get this in C#, but for some pain-in-the-butt reason can't get it working in VB.Net. If someone could help me out with this situation, I'd appreciate it. Hopefully I haven't missed the boat conceptually and all I'm missing is some syntax. This is similar to the code I'm working with:</p> <pre><code>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 </code></pre> <p>I was hoping to get a test that looked something like this running:</p> <pre><code>Imports NUnit.Framework Imports Moq &lt;TestFixture()&gt; _ Public Class SendMessageTests &lt;Test()&gt; _ 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 </code></pre> <p>Can anyone help me to complete or correct the line in my test class that begins "sendable.Raise..."? Maybe there is more setup I need to do, but the Moq site didn't seem to indicate this is the case.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload