c# - Mocking out a method that takes optional parameters that default to null -
i writing unit test against function hits elasticsearch through nest. unit test's setup looks this:
var mockresponse = new mock<ibulkresponse>(); var mockclient = new mock<ielasticclient>(); mockclient.setup(x => x.indexmanyasync<store>(it.isany<ienumerable<store>>(), it.isany<string>(), it.isany<string>())).returns(task<ibulkresponse>.run(() => mockresponse.object)); the indexmanyasync function takes has function signature of task<ibulkresponse> indexmanyasync<t>(ienumerable<t> object, string index = null, string type = null).
as can see, tried set mock ielasticclient mock out method above, following exception:
an exception of type 'system.notsupportedexception' occurred in moq.dll not handled in user code additional information: expression references method not belong mocked object: x => x.indexmanyasync<store>(it.isany<ienumerable`1>(), it.isany<string>(), it.isany<string>()) it's not clear me going on here. why unable mock method takes optional parameters?
it appears particular overload of indexmanyasync is extension method:
public static task<ibulkresponse> indexmanyasync<t>(this ielasticclient client, ienumerable<t> objects, string index = null, string type = null) t : class { // <snip> }
Comments
Post a Comment