C# 浏览器中的Silverlight单元测试模拟<;FileInfo>;
在Silverlight(inbrowser)单元测试中,使用Mock将文件读取到我的ViewModel中,我遇到了一些困难C# 浏览器中的Silverlight单元测试模拟<;FileInfo>;,c#,unit-testing,silverlight-4.0,mocking,C#,Unit Testing,Silverlight 4.0,Mocking,在Silverlight(inbrowser)单元测试中,使用Mock将文件读取到我的ViewModel中,我遇到了一些困难 It gives me an AccessDenied error message. Is there another alternative method for that kind of problem? My UnitTesting is DragAndDrop Image file in Silverlight 4. 例如: Unittessing.cs
It gives me an AccessDenied error message. Is there another alternative method for that kind of problem?
My UnitTesting is DragAndDrop Image file in Silverlight 4.
例如:
Unittessing.cs
var fileInfo=new Mock()//我不能模仿文件信息
var fileInfo=newfileinfo(“test.jpg”)
谢谢Jonny,我做了如下操作,没有工作,这是我的示例代码 新接口类 公共接口IFileInfo{string Name{get;set;}文件流打开(文件模式);} 新包装器类 公共类FileInfoWrapper:IFileInfo{private FileInfo FileInfo;public FileStream OpenRead(){返回this.OpenRead();}公共字符串名称{获取{返回this.Name;}设置{this.Name=value;} } 在我的测试课上 [TestMethod][Asynchronous]public void MultiFileDropTest(){list wrapperList=new list();fileInfo.Setup(fl=>fl.Name)。返回(“testing.jpg”) //文件读取和返回位图代码,工作正常
}}根据您编写的代码,我猜您正在尝试使用moq框架,它使用语法
var fileInfo = new Mock<Interface>();
var fileInfo=new Mock();
您需要提供一个类型,以便框架能够了解预期的行为
在这种情况下,您将无法用FileInfo替换接口,因为FileInfo是一个具体的类。你的选择是:
它以什么方式不起作用?它编译吗?测试是否失败或错误通过?您的测试似乎设置了一些模拟对象,但似乎没有测试任何东西。我仍然停留在该代码的中间,所以我正在寻找一些方法。
...taking the first file from the files collection
FileInfo file = files[0];
if (file != null && IsImageFile(file.Extension))
{
var fileInfo = new Mock<Interface>();