nunit - NullRefernceException when calling Setup -
i'm trying simple setup on mocked object, nullrefernceexception coming setup line:
what mistake doing here?
your setup incorrect because confusing moq .tostring() in it.isany<string>().tostring().
because of moq cannot generate correct matcher , throws exception.
it easy fix this, remove .tostring():
[test] public void test() { mockdatabase = new mock<idatabase>(); dataset ds = new dataset(); mockdatabase.setup(m => m.dbquery(it.isany<string>())).returns(ds); var sut = new businessclass(mockdatabase.object); sut.somemethod(); } 
Comments
Post a Comment