Web Forms MVP Presenter 的单元测试具有空模型

发布于 2024-08-23 14:10:36 字数 1330 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小梨窩很甜 2024-08-30 14:10:36

只是猜测 - 但也许您需要在演示者通常设置该 Model 属性之前在模拟视图上调用“SetupAllProperties()”方法?

   view.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?

   view.SetupAllProperties();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文