jeudi 15 février 2018

Microsoft Shim throws Ambiguous match exception when encounters methods with the same name in a class

I am trying to fake/mock db access for my unit tests.I chose Microsoft Fakes to accomplish that job.My main class has some same functions with different signatures like below.

public string GetValue(string key)
public T GetValue<T>(string key)

I added a fake assembly.It works fine with other methods(which has unique names in the class)however,when I try to fake/mock GetValue method I receive following error.

 using (ShimsContext.Create())
            {
   Fakes.ShimFrmParamsBiz<FakeDbContext>.AllInstances.GetValueString = (x, y) => { return "Test"; };
}

Ambiguous match exception

Because It is legacy code,it is not possible to change method name right now.Any idea ? Thanks advance





Aucun commentaire:

Enregistrer un commentaire