mam tej klasy:testu prywatnego metoda statyczna rzuca MissingMethodException
public class MyClass
{
private static int GetMonthsDateDiff(DateTime d1, DateTime d2)
{
// implementatio
}
}
Teraz jestem wykonawczych testów jednostkowych dla niego. Ponieważ metoda jest prywatny, mam następujący kod:
MyClass myClass = new MyClass();
PrivateObject testObj = new PrivateObject(myClass);
DateTime fromDate = new DateTime(2015, 1, 1);
DateTime toDate = new DateTime(2015, 3, 17);
object[] args = new object[2] { fromDate, toDate };
int res = (int)testObj.Invoke("GetMonthsDateDiff", args); //<- exception
Wyjątek typu „System.MissingMethodException” wystąpił w pliku mscorlib.dll ale nie było obsługiwane w kodzie użytkownika Informacje dodatkowe: próbował uzyskać dostęp brakujący członek.
Co robię źle? Metoda istnieje ..
i 'InvokeStatic()' 'zamiast Invoke()' to nazwać. –