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

标签 .net moq mvp xunit.net

我正在使用 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", 
                    "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="741700110700110634001107005a171b19" rel="noreferrer noopener nofollow">[email protected]</a>", "http://www.test.com", 
                    "This is a test of the emergancy broadcast system..."));  
            presenter.ReleaseView();

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

最佳答案

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

   view.SetupAllProperties();

关于.net - Web Forms MVP Presenter 的单元测试具有空模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2388273/

相关文章:

c# - XMLSerializer 序列化日期错误 : Is not a valid AllXsd

c# - Mvc UserControl 使用 HtmlHelper 与 HelperResult 和 MvcHtmlString

c# - 从反射抛出的 TargetInvocationException 是否可以有 null InnerException

c# - 使用 Moq 实例引发 EventHandler<TEventArgs> 事件

java - 将 MVP 模式应用于 JDialogs

wpf - Model-View-Presenter 和 Modal 对话框.... 如何?

c# - C# 中不兼容的匿名函数签名?

c# - 使用起订量,System.InvalidCastException : Unable to cast object of type 'CaSTLe.Proxies.ObjectProxy' to type

vb.net - 如何使用最小起订量发起事件?

asp.net - 使用模型 View 演示者设计模式的安全性和角色授权