Hi
The "new" Microsoft.Extensions.Configuration with IConfiguration and IConfigurationSection samed easy enough to mock. But something wierd happends:
var configuration = Substitute.For<IConfiguration>();
var section = Substitute.For<IConfigurationSection>();
configuration.GetSection("Assets:Xzy").Returns(_sections);
_sections.Get<Asset[]>().Returns(assets);
But i get this, that i find very very strainght forward. Hav i gone blind, of have i made a weird mistake?:
Can not return value of type Asset[] for IDisposable.Dispose (expected type Void).
Make sure you called Returns() after calling your substitute (for example: mySub.SomeMethod().Returns(value)),
and that you are not configuring other substitutes within Returns() (for example, avoid this: mySub.SomeMethod().Returns(ConfigOtherSub())).
If you substituted for a class rather than an interface, check that the call to your substitute was on a virtual/abstract member.
Return values cannot be configured for non-virtual/non-abstract members.
Correct use:
mySub.SomeMethod().Returns(returnValue);
Potentially problematic use:
mySub.SomeMethod().Returns(ConfigOtherSub());
Instead try:
var returnValue = ConfigOtherSub();
mySub.SomeMethod().Returns(returnValue);