Ich habe diese Klasse:Test-private statische Methode wirft Missing
public class MyClass
{
private static int GetMonthsDateDiff(DateTime d1, DateTime d2)
{
// implementatio
}
}
Jetzt bin der Umsetzung I Unit-Test für sie. Da das Verfahren ist privat, ich folgenden Code haben:
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
Eine Ausnahme vom Typ ‚System.MissingMethodException‘ in mscorlib.dll aufgetreten, wurde aber in Benutzercode Zusätzliche Informationen nicht behandelt: Versuchte einen fehlenden Zugriff auf Mitglied.
Was mache ich falsch? Die Methode existiert ..
Und 'invokestatic()' statt 'Invoke()' es zu nennen. –