Unit test for Web Forms MVP presenter has a null Model
Posted
by jacksonakj
on Stack Overflow
See other posts from Stack Overflow
or by jacksonakj
Published on 2010-03-05T16:29:48Z
Indexed on
2010/03/08
4:36 UTC
Read the original article
Hit count: 417
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);
}
}
}
© Stack Overflow or respective owner