I have a dependency that I would like to mock.
public abstract class MyDependency
{
protected Dictionary<string, object> _outputs = new Dictionary<string, object>();
public Dictionary<string, object> Outputs
{
get
{
return _outputs;
}
}
}
I need the public property Outputs to return a known value for the purpose of my unit test. I know that we cannot mock fields or non-virtual members. So, I could go and create my own mocked MyDependency that sets the backing field _outputs:
public class MockMyDependency : MyDependency
{
public MockMyDependency()
{
_outputs = new Dictionary<string, object>
{
{ "key", "value" }
};
}
}
However, is it possible to use Moq to do this without explicitly creating my own derived mock class?
SetupGet()work on abstract classes? - 48klocsabstractorvirtual. Unfortunately, I am not able to modify theMyDependencyclass. - Stephen Booher