Web Forms MVP Presenter 的单元测试具有空模型
我正在使用 Web Forms MVP 编写 DotNetNuke 用户控件。当在我的单元测试中引发“SubmitContactUs”事件时,演示者尝试在模态上设置“Message”属性。但是,演示者中的 View.Modal 为空。
Web Forms MVP 框架不应该自动在演示器中构建一个新的 View.Model 对象吗?可能是我的测试的“安排”部分缺少演示者需要的东西。任何帮助将不胜感激。
这是我的测试:
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);
}
}
}
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是猜测 - 但也许您需要在演示者通常设置该 Model 属性之前在模拟视图上调用“SetupAllProperties()”方法?
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?