I'm not sure if I should ask this here but here we go, while unit testing a private static method that has as parameter a short I'm getting a MissingMethodException only when this parameter is 0.
I'm using VS 2010 SP1 targeting the Framework 4 (full), here is the bare minimum code to reproduce this error (we are upgrading a VB6 code so don't be rude):
[DataContract]
public enum NotificationResult
{
[EnumMember]
Success,
[EnumMember]
StoredError,
[EnumMember]
InvalidId,
[EnumMember]
OperationError,
}
public sealed class NotificationContext
{
private static NotificationResult GetExecuteResult(short result)
{
NotificationResult executeResult;
switch (result)
{
case 0:
executeResult = NotificationResult.Success;
break;
case 1:
executeResult = NotificationResult.StoredError;
break;
case 2:
executeResult = NotificationResult.InvalidId;
break;
default:
executeResult = NotificationResult.OperationError;
break;
}
return executeResult;
}
}
Here is how I'm testing the code:
PrivateType privateHelperType = new PrivateType(typeof(NotificationContext));
var actual = (NotificationResult)privateHelperType.InvokeStatic(
"GetExecuteResult", (short)1);
var actual2 = (NotificationResult)privateHelperType.InvokeStatic(
"GetExecuteResult", (short)0); //here is where i get the exception
In the first invocation i get the expected result, in the second invocation I get the exception (I added the cast to short thinking that maybe the exception was because it was not finding a method with an int as a parameter).
Is anybody able to reproduce the behavior?, am I doing something wrong?
Thanks for your help.