c# - Moq ReturnsAsync() with parameters -


i'm trying mock repository's method that

public async task<whitelistitem> getbytypevalue(whitelisttype type, string value) 

using moq returnsasync, this:

static list<whitelistitem> whitelist = new list<whitelistitem>();  var whitelistrepositorymock = new mock<iwhitelistrepository>();  whitelistrepositorymock.setup(w => w.getbytypevalue(it.isany<whitelisttype>(), it.isany<string>()))                                     .returnsasync((whitelisttype type, string value) =>                                     {                                         return (from  item in whitelist                                                 item.type == type && item.value == value                                                 select item).firstordefault();                                     }); 

but i'm getting error in line "... returnsasync((whitelisttype type...):

cannot convert lambda expression type 'model.whitelistitem' because not delegate type

whitelisttype enum that:

public enum whitelisttype     {         username,         postalcode     } 

i searched hours , didn't found answer problem.

any clues?

returnsasync not have lambda version unlike returns one.

fix: use returns task.fromresult`

.returns((whitelisttype type, string value) =>      {          return task.fromresult(            (from  item in whitelist                item.type == type && item.value == value                select item).firstordefault()            );   }); 

Comments