views:

177

answers:

1

I am using Web Forms MVP to write an DotNetNuke user control. When the 'SubmitContactUs' event is raised in my unit test the presenter attempts to set the 'Message' property on the Modal. However the View.Modal is null in the presenter.

Shouldn't the Web Forms MVP framework automatically build a new View.Model object in the presenter? It could be that the 'Arrange' portion of my test is missing something that the presenter needs. Any help would be appreciated.

Here is my test:

using System;
using AthleticHost.ContactUs.Core.Presenters;
using AthleticHost.ContactUs.Core.Views;
using Xunit;
using Moq;

namespace AthleticHost.ContactUs.Tests
{
    public class ContactUsPresenterTests
    {
        [Fact]
        public void ContactUsPresenter_Sets_Message_OnSubmit()
        {
            // Arrange
            var view = new Mock<IContactUsView>();
            var presenter = new ContactUsPresenter(view.Object);
            // Act
            view.Raise(v => v.Load += null, new EventArgs());
            view.Raise(v => v.SubmitContactUs += null, 
                new SubmitContactUsEventArgs("Chester", "Tester", 
                    "[email protected]", "http://www.test.com", 
                    "This is a test of the emergancy broadcast system..."));  
            presenter.ReleaseView();

            // Assert
            Assert.Contains("Chester Tester", view.Object.Model.Message);
        }
    }
}
+2  A: 

Just a guess - but maybe you need to call the "SetupAllProperties()" method on the mocked view before the presenter would normally set that Model property?

   view.SetupAllProperties();
Eric
Thank you! I added that line just below where the mock was being created (var view = new Mock<IContactUsView>();) and it worked great.
jacksonakj
This tells the mock object to start tracking property values. Otherwise it will forget values that are set. Documentation here: http://code.google.com/p/moq/wiki/QuickStart#Properties Someone else with the same problem: http://tinyurl.com/3y9x2gj
Helephant