Because the method is generic, a single delegate cannot suffice. One delegate cannot be both Func<string>
and Func<int>
. The method you're seeing allows you to pass in the delegate for a specific type, which is probably stored in a dictionary internally (from my attempts to replicate Fakes' stub behavior).
So, just pass in the delegate you'd normally assign to the property into the GetSettingOf1
method. This is really just a way to allow a generic method to have a stub implementation for any number of types rather than just one.
Example:
var configManager = new StubIConfigManager();
configManager.GetSettingOf1(() => "TestString");
configManager.GetSettingOf1(() => 23);
var stringResult = configManager.GetSetting<string>();
var intResult = configManager.GetSetting<int>();
Assert.AreEqual("TestString", stringResult);
Assert.AreEqual(23, intResult);
Clearly this example is not a test you should write, because Fakes works, but it should get the point across.