c# - Can not resolve symbol of mocked object -
so learn more unit tests , mocking created following simple interface want mock , test in unit test:
namespace testprojekt { public interface icsvfile { string filename { get; } int getfilesize(); } }
and test using nunit , moq
namespace nunittests { using moq; using nunit.framework; using testprojekt; [testfixture] public class unittests1 { private const string filename = "0030001744_14224429_valuereport_20140527000012_1104.csv"; private const int filesize = 155; [test] public void exampletest() { var file = new mock<icsvfile>(); file.setup(m => m.getfilesize()).returns(filesize); file.setupget(m => m.filename).returns(filename); assert.areequal(filename, file.filename); assert.areequal(filesize, file.getfilesize); } } }
i made based on tutorial found online , quite interesting. problem is, visual studio cant resolve method , property or else setup
on mocked object.
all dlls referenced correctly. must super thing cant figure out. in advance!
i guess encountered compile error. reason used properties directly instance of mock<icsvfile>
type. instead, should use file.object.filename
. object
property represents mocked instance of icsvfile
.
modify code following.
assert.areequal(filename, file.object.filename); assert.areequal(filesize, file.object.getfilesize);
Comments
Post a Comment