I have a controller in my asp.net core 2.1 project which has IOptions<RaygunSettings>
as constructor parameter.
Dependency Injection is added in Startup.cs as shown below.
services.AddRaygun(Configuration);
Everything works fine when you run the web application. But when It didn't work for xunit project.
SampleController.cs
private readonly RaygunClient raygunClient;
public SampleController(IOptions<RaygunSettings> settings)
{
_settings = settings;
raygunClient = new RaygunClient(_settings.Value);
}
private Mock<IOptions<RaygunSettings>> _settings;
SampleControllerTest.cs
public SampleControllerTest()
{
//Arrange
_settings = new Mock<IOptions<RaygunSettings>>();
_controller = new SampleController(_settings.Object);
}
Above code explains how my SampleController and SampleControllerTest constructor looks like.
When I try to run the xunit test at the raygunclient instantiation time I'm getting
Object reference not set to an instance of an object
How to fix this issue in xunit test project for asp.net core 2.1