在C#中模拟文件IO静态类 [英] Mock File IO static class in c#

查看:227
本文介绍了在C#中模拟文件IO静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的单元测试,我需要模拟在System.IO命名空间文件静态类。我使用Rhinomock
,什么是实现这一目标的最佳途径,

I am new to Unit Testing, and I need to mock the File static class in System.IO namespace. I am using Rhinomock, what is the best way to accomplish this,

可以说,我需要模拟File.Exists,File.Delete ...

Lets say I need to mock the File.Exists,File.Delete ...

推荐答案

您不能嘲笑犀牛模拟静态方法。请参见这个问题获取更多信息。您可以创建一个外观类来封装文件系统调用,你会使用,然后创建一个模拟版本。

You can't mock static methods with Rhino mock. See this question for more info. You could create a facade class to wrap the file system calls you will use and then create a mock version of that.

这篇关于在C#中模拟文件IO静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆