Unit test for Web Forms MVP presenter has a null Model
I am using Web Forms MVP to write an DotNetNuke user control. When the 'SubmitContactUs' event is raised in my unit test the presenter attem开发者_JAVA百科pts 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",
"ctester@test.com", "http://www.test.com",
"This is a test of the emergancy broadcast system..."));
presenter.ReleaseView();
// Assert
Assert.Contains("Chester Tester", view.Object.Model.Message);
}
}
}
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();
精彩评论