What is the best practice for unit testing these kind of methods?
public VerificationResultCode Translate(int value)
{
VerificationResultCode result;
if (Enum.IsDefined(typeof(VerificationResultCode), (int)value))
result = (VerificationResultCode)((int)value);
else
throw new UnknownResultReturnFromGatewayException();
return result;
}
VerificationResultCode is Enum Type like:
public enum VerificationResultCode
{
BankingNetworkError = 100,
NotEqual =101,
InputFormatError = 102,
MerchantAuthenticationFailed = 103,
...
}
Should we write a single test method for each of Enum Members or just write one test method with lots of Assertions?
The code is almost too trivial to unit test. You should unit test the behavior that depends on the
VerificationResultCodewhich will also test theTranslatefunction. A bigger question is why do you need a public translation function instead of encapsulating it in objects?