unit testing - Parameter count mismatch on stub with lambda expression using Moq -


i 'parameter count mismatch' targetparametercountexception when want test tenant repository:

the interface:

public interface itenantrepository {     iqueryable<tenant> get(expression<func<tenant, bool>> filter = null,     func<iqueryable<tenant>, iorderedqueryable<tenant>> orderby = null,     string includeproperties = null); } 

the test code:

var tenantrepository = new mock<itenantrepository>();  tenantrepository     .setup(p => p.get(it.isany<expression<func<tenant, bool>>>(),         it.isany<func<iqueryable<tenant>,iorderedqueryable<tenant>>>() ,         it.isany<string>()))     .returns(new func<expression<func<tenant, bool>>,        iqueryable<tenant>>(expr => tenants.where(expr.compile()).asqueryable()));  tenant testtenant = tenantrepository.object.get(       t => t.tenantid == tenant2.tenantid,       null,       null).firstordefault(); 

the error occurs on last line.

found solution correct parameters:

tenantrepository.setup(p => p.get(it.isany<expression<func<tenant, bool>>>(),                                   it.isany<func<iqueryable<tenant>, iorderedqueryable<tenant>>>(),                                   it.isany<string>()))                 .returns(                          (expression<func<tenant, bool>> expr,                            func<iqueryable<tenant>, iorderedqueryable<tenant>> orderby,                           string includeproperties) => tenants.where(expr.compile()).asqueryable()); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -