nunit - NullRefernceException when calling Setup -


i'm trying simple setup on mocked object, nullrefernceexception coming setup line:

enter image description here

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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -