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
这篇关于模拟不是接口的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:模拟不是接口的类


基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01