I’m trying to write unit tests for some legacy C# code using moq. There are several endpoints where we expect a Guid to be passed in as a string and then return an object corresponding to that Guid from the DB. However these endpoints also have code where if the string is empty then it uses the Guid from a private member variable and returns that default object instead. The problem is this private member variable is populated from the DB when the service is initialized, so I need a way to override the value in my Mock service with a known value so I can pass an empty string to the end point and verify it returns that known value.
Dan Haddix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.