title: Using NserviceBus.Testing how do you test the published event when the code is not initiated via a message handler
body: <p><strong>Question</strong></p>
  
  <p>If the current method being tested is initiated via some other method than an incoming message (into a handler) how do you test the publishing of events. The problem with NServiceBus.Testing (as far as I see it) is that its very geared towards testing handlers which in turn cause messages/events to be send/published. </p>
  
  <p><strong>Background</strong>:</p>
  
  <p>We have a number of legacy systems, and in the ongoing effort to move to a proper SOA implementation we need to integrate with some legacy DB jobs. These jobs perform actions on the DB every 15 minutes which we want to hook into and publish events when certain conditions occur.</p>
  
  <p>We have a windows service that is running within the NsbHost but that contains no handlers. Instead we are using Quartz to create an internal cron job that runs every minute, polls the DB for records that match a specified pattern, and publishes an event before updating the DB to say we have processed that record. This is how we are integrating old and new systems. </p>
  
  <p>Clearly this is not an ideal situation but given that we are in a transition phase in our SOA implementation its as good as we have right now.</p>
  
  <p><strong>Details and code</strong>:</p>
  
  <p>Our event interface we are publishing looks like this</p>
  
  <pre><code>    public interface IPremiumAdjustmentFinalised
      {
          string PolicyNumber { get; set; }
          decimal Amount { get; set; }
          DateTime FinalisedOn { get; set; }
      }
  </code></pre>
  
  <p>The code to actually publish the event is</p>
  
  <pre><code>    Bus.Publish&lt;IPremiumAdjustmentFinalised&gt;(e =&gt;
      {
          e.Amount = AdjustmentAmount;
          e.PolicyNumber = PolicyNumber;
          e.FinalisedOn = LastModifiedOn;
      });
  </code></pre>
  
  <p>This all works fine and we can test the call was made using MOQ thus:</p>
  
  <pre><code>    eventPublisher.MethodToTest();
      bus.Verify(x =&gt; x.Publish(It.IsAny&lt;Action&lt;IPremiumAdjustmentFinalised&gt;&gt;()), Times.Once);
  </code></pre>
  
  <p>where bus is a new Mock inserted into the constructor.</p>
  
  <p>But I want to test the values within IPremiumAdjustmentFinalised. I'm finding this really difficult I think mainly because its an interface rather than a concrete class.</p>
  
  <p>We have tried using NServiceBus.Testing to try and inspect the generated event but to no avail.</p>
  
  <p>Does anyone know of how to test the values in the event in this given scenario?</p>