加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Moq C#内置

发布时间:2020-12-15 08:36:27 所属栏目:百科 来源:网络整理
导读:我正在尝试模拟SearchResultCollection类.但是,当我尝试拦截对PropertiesLoaded getter的调用时,我的测试会抛出异常: System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member: x = x.PropertiesLoaded 我的代码: MockS
我正在尝试模拟SearchResultCollection类.但是,当我尝试拦截对PropertiesLoaded getter的调用时,我的测试会抛出异常:
System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member: x => x.PropertiesLoaded

我的代码:

Mock<SearchResultCollection> searchResultMock = new Mock<SearchResultCollection>();

// Set up collection that will be returned
string[] tempData = { "one","two" };
searchResultMock.SetupGet(x => x.PropertiesLoaded).Returns(tempData);

有没有人成功嘲笑过这样的课程?有问题的财产只有一个吸气剂,而不是虚拟的.

//
    // Summary:
    //     Gets the System.DirectoryServices.DirectorySearcher properties that were
    //     specified before the search was executed.
    //
    // Returns:
    //     An array of type System.String that contains the properties that were specified
    //     in the System.DirectoryServices.DirectorySearcher.PropertiesToLoad property
    //     collection before the search was executed.
    public string[] PropertiesLoaded { get; }

解决方法

我怕你不能.

就像你说的那样,财产不是虚拟的.另一个选择是模拟界面,但我检查了这个类没有一个(根据MSDN文档).

还有一些其他隔离框架可以做到这一点.
Microsoft Moles能够做到这一点,TypeMock也是如此.

微软摩尔:http://research.microsoft.com/en-us/projects/moles/

TypeMock:http://www.typemock.com/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读