Mocking classes that aren#39;t interfaces(模拟不是接口的类)
问题描述
我一直在用 C# 编写一些从 providerbase 类继承的提供程序.我发现很难编写使用提供程序的测试,因为大多数模拟框架只允许你模拟一个接口.
I've been writing some providers in c# that inherit from the providerbase class. I've found that it's hard to write tests that use the providers as most mocking frameworks will only allow you to mock an interface.
有什么方法可以模拟对从 providerbase 继承的提供者的调用?
Is there any way to mock a call to a provider that inherits from providerbase?
如果没有,我可以使用一种模式来实现对提供程序的模拟吗?
If not, is there a pattern that I can use to implement mocking of providers?
推荐答案
模拟框架应该能够为你创建一个基于类的模拟对象,只要它有虚拟成员.
Mocking frameworks should be able to create for you a mock object based on a class, as long as it's got virtual members.
您可能还想看看 Typemock
这篇关于模拟不是接口的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:模拟不是接口的类


- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01