Mocking the IConfigurationSection using NSubstitute

Viewed 178

I'm trying to mock the IConfiguration as well as the IConfigurationSection using NSubstitute. I have a custom configuration file that I use to configure HTTP clients on startup. The problem is when I try to mock, I cannot make it return my custom class ClientConfiguration using a .Returns(). I get this error:

NSubstitute.Exceptions.CouldNotSetReturnDueToTypeMismatchException: 'Can not return value of type ClientConfiguration for IDisposable.Dispose (expected type void)'

Code:

var configSection = Substitute.For<IConfigurationSection>();
var configuration = Substitute.For<IConfiguration>();

configSetion.Get<ClientConfiguration>().Returns(new ClientConfiguration());

configuration.GetSection(Arg.Any<string>()).Returns(configSection);
0 Answers
Related