Буду признателен за помощь в предоставлении правильных типов параметров для метода Молей. Цель состоит в том, чтобы издать публичный экземпляр. Я не технарь.
Вот моя попытка. (Комментарии показывают определение «SetMolePublicInstance ()» из браузера объектов):
[ __DoNotInstrument]
public static class Deq
{
public static void Replace<T>(
//SetMolePublicInstance( System.Delegate _stub, System.Type receiverType, _
// object _receiver, string name, params System.Type[] parameterTypes)
Func <T> stub, // need help for the correct parameter types
Func <Object > receiverType,
Func <T> objectReceiver,
string methodName,
Func <T> parameterTypes)
{
//SetMolePublicInstance( System.Delegate _stub, System.Type receiverType, _
// object _receiver, string name, params System.Type[] parameterTypes)
MoleRuntime .SetMolePublicInstance(stub, receiverType, objectReceiver, methodName, parameterTypes;
// the previous line produces the error: "The best overloaded method match for ... has some invalid arguments"
}
}
Вот мой текущий тестовый код. Я не могу завершить этот код до тех пор, пока не выясню, какие существуют различные типы параметров в методе Replace () выше:
[ Test]
public void StaticMethodUnitTestWithDeq()
{
using (MolesContext .Create())
{
Class1 objectReceiver = new Class1();
Deq .Replace(
() => "New value" , // stub
() => Class1 , // receiverType
() => objectReceiver, // objectReceiver
() => "TestString" , // methodName
() => null ); // parameterTypes
//Assert.AreEqual(new DateTime(2000, 1, 1), Class1.DateTime.Now);
}
}
Вот код для Class1:
public class Class1
{
public string TestString() { return "Original value" ; }
}
Edit:
Используя различные комбинации «ноль», я обнаружил, что принимается следующее утверждение:
MoleRuntime.SetMolePublicInstance(stub, null, objectReceiver, methodName, null);
Таким образом, это означает, что неправильные типы относятся ко второму параметру "receiveType" и последнему параметру "parameterTypes".