【问题标题】:Why can't I mock out a view property in MVP using NSubstitute为什么我不能使用 NSubstitute 在 MVP 中模拟视图属性
【发布时间】:2012-04-13 13:21:19
【问题描述】:

我正在尝试在 MVP 应用程序中对我的演示者进行单元测试。这是我尝试使用 NSubstitude 模拟的视图界面:

public interface ICategoriesView : IBaseViewInterface
{
    string CategoryName { get; }
    long CategorId { get; }
    long CategoryParent { get; }
    IEnumerable<EntityObject> CategoryDataSource { set; }
}

这是我的单元测试类。我正在使用 NUnit 框架:

[TestFixture]
public class CategoriesTests
{
    [Test(Description="this is used for testing the behavior of presenter if we pass empty name.")]
    public void Add_EmptyName_Fails()
    {
        var _view = NSubstitute.Substitute.For<ICategoriesView>();
        //now here i'm supposed to get something like _view.CategoryId.Returns(2) but i don't!
        //the error message says that _view.CategoryId doesn't have an extension method 
        //named Returns. and it's true since intellisence doesn't list it after period
    }
}

我在视图界面中添加了 set modifer,但它不起作用。那怎么了?

【问题讨论】:

  • 这只是ICategoriesView 中的拼写错误:CategorId,而不是CategoryId

标签: asp.net unit-testing testing mvp nsubstitute


【解决方案1】:

实际上我忘记在我的测试类顶部添加一个 using NSubstitude。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多