79610912

Date: 2025-05-07 15:35:01
Score: 0.5
Natty:
Report link

How about MockMe? It doesn't support mocking static members (yet), but it does support mocking concrete types without the artificial activity of introducing an interface or making members virtual (furthermore without the need of adding any InternalsVisibleTo):

static void Main(string[] args)
{
    var fakeDriver = Mock.Me(default(BlueToothDriver));
    fakeDriver.Setup.ReadString().Returns("world!");

    var device = new BlueToothDevice(fakeDriver.MockedObject);
    device.Hello();
}

internal class BlueToothDevice(BlueToothDriver driver)
{
    public void Hello() => Console.WriteLine("Hello {0}", driver.ReadString());
}

// e.g. external library
internal class BlueToothDriver
{
    public string ReadString() => "doomsday!";
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How
  • Low reputation (0.5):
Posted by: marchewek