c# - Silverlight in browser UnitTesting Mock<FileInfo> -
i'm facing difficulties in silverlight (inbrowser) unittesting using mock read file viewmodel.
gives me accessdenied error message. there alternative method kind of problem? unittesting draganddrop image file in silverlight 4.
eg: unittesing.cs
var fileinfo = new mock(); //i can't mock fileinfo
var fileinfo = new fileinfo("test.jpg");
thanks jonny, did follow , not working , here sample code snipped.
new interface class
public interface ifileinfo { string name {get;set ;} filestream open(filemode mode); }
new wrapper class
public class fileinfowrapper : ifileinfo { private fileinfo fileinfo; public filestream openread() { return this.openread(); } public string name { { return this.name; } set { this.name = value; } }
}
in test class
[testmethod] [asynchronous] public void multifiledroptest() { list wrapperlist = new list(); fileinfo.setup(fl => fl.name).returns("testing.jpg");
fileinfo.setup<stream>(fl => fl.openread()).returns(filestream.object); wrapperlist .add(fileinfo.object); wrapperlist .add(fileinfo.object); idataobject.setup(p => p.getdata(dataformats.filedrop)).returns(wrapperlist .toarray());
}
// function (viewmodel) public bitmapimage singleimagedroptest(idataobject idata) { ............. var files = (fileinfo[])dataobject.getdata(dataformats.filedrop);
...taking first file files collection fileinfo file = files[0]; if (file != null && isimagefile(file.extension)) {
//file read , return bitmap code working fine } }
from code you've written i'm guessing you're trying use moq framework, uses syntax
var fileinfo = new mock<interface>();
you need supply type, framework has clue of behaviour expect.
in case, won't able substitute interface fileinfo, since fileinfo concrete class. alternatives are:
find abstract class or interface fileinfo class implements, has methods need use, , when using variable on view, declare type
(more likely) make class wraps fileinfo class, , interface implements, includes method(s) need, , declare variable on view interface type.
Comments
Post a Comment