I'm probably below average on Unit Testing skills, but been asked to write a unit test for something I fixed. Basically, a method now allows a null value to be passed in, and I need to validate that it gets switched to the correct value, if null.(Please note, method code reduced to remove supurfluous code - it actually does more than return true...)
public IDictionary<string, JToken> MethodINeedToTest(
long? userId,
long? orgId
)
{
userId ??= DataServicesHelper.SystemUserKey;
var myResults = APrivateMethod(userId.Value, orgId, false);
return true;
}
I was hoping to just verify that APrivateMethod
was called with the value from DataServicesHelper.SystemUserKey
. However, the method is private. So with Moq, I cannot do a verify on a private method (I believe).
Is there anyway to validate that when userId
is passed in as null, the method is called with DataServicesHelper.SystemUserKey
? (Other test is to validate that it gets called with userId when it's not null).
Or is the code just not testable?
question from:
https://stackoverflow.com/questions/65910827/moq-and-validating-a-private-method-ios-called-with-correct-parameters 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…