I'm attempting to get closer to 100% code coverage, and I'm interested in mocking OpenFileDialog. From some research, it appears that a good answer is to create an IFileDialogService, like this code from Open File Dialog MVVM:
public interface IOpenFileService
{
string FileName { get; }
bool OpenFileDialog()
// Many other methods and properties of OpenFileDialog here...
}
However, that means that I have to implement all of the properties and methods of OpenFileDialog and simply have them be a pass-through to call the properties and methods of the real OpenFileDialog.
I was hoping to do something like having a MockContainer and a RealContainer, and each would return their version of OpenFileDialog:
public class MockContainer
{
IOpenFileDialog FileDialog { get { return new MockOpenFileDialog(); } }
}
public class RealContainer
{
IOpenFileDialog FileDialog { get { return new OpenFileDialog(); } }
}
However, I can't do that because they don't implement a common interface. If I was able to go with this approach, I wouldn't need to create pass-through methods in the IOpenFileService for everything needed with an OpenFileDialog. Each container would just return a dialog that the caller could use.
Is there a way I can make that approach work, or is the IOpenFileService really the way to do it?
Note: I know about mocking frameworks. I wanted to implement something quickly today, and didn't want to take the time to learn a mocking framework yet. I figured I could mock it myself fairly easily.