Note that there are some explanatory texts on larger screens.

plurals
  1. POVerifying event registration using Moq
    primarykey
    data
    text
    <p>I'm developing an asp.net (classic) application trying to implement the MVP pattern <a href="http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx" rel="nofollow noreferrer">using this example</a>. In trying to unit test my presenter and using the following pattern, the psuedocode for which looks like so</p> <pre><code>//base view interface public interface IView { event EventHandler Init; event EventHandler Load; bool IsPostBack { get; } void DataBind(); bool IsValid { get;} } //presenter psuedo code public class SomePresenter { public SomePresenter(ISomeDomainService service, IView someView) { ... //HOW DO WE TEST/VERIFY THAT THIS REGISTRATION OCCURS? someView.Init += OnInit; someView.Load += OnLoad; } } ... //consuming code that exercises the above code, that needs to be tested var presenter = new SomePresenter(someDomainService, someView); </code></pre> <p>How do I verify that the presenter is doing what is expected i.e. registering for the Init and Load events? While this is easily done in the <a href="http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx" rel="nofollow noreferrer">Phil Haack's example</a> using Rhino mocks...</p> <pre><code>[Test] public void VerifyAttachesToViewEvents() { viewMock.Load += null; LastCall.IgnoreArguments(); viewMock.PostSaved += null; LastCall.IgnoreArguments(); mocks.ReplayAll(); new PostEditController(viewMock, this.dataServiceMock); mocks.VerifyAll(); } </code></pre> <p>... how can we do this using MOQ?</p>
    singulars
    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.
 

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