I'm trying to unit test a controller and I created a fake class that Implements an Interface.
public class UnitTest1
{
GrantProgramsController _controller;
IBLGrantProgram _grant;
readonly ILogger<GrantProgramsController> _logger;
public UnitTest1()
{
_grant = new BLGrantProgramFake();
_logger = new Logger<GrantProgramsController>(new NullLoggerFactory());
_controller = new GrantProgramsController(_grant, _logger);
}
//tests for get method
[Fact]
public void Get_whencalled_returnsokresult()
{
// Act
var okResult = _controller.GetGrantProgram();
// Assert
Assert.IsType<OkObjectResult>(okResult.Result);
}
----------
But, I'm trying to use Moq framework and mock the interface instead of creating a fake implementation for the interface.
public UnitTest1()
{
// _grant = new BLGrantProgramFake();
_grant = new Mock<BLGrantProgram>();
_logger = new Logger<GrantProgramsController>(new NullLoggerFactory());
_controller = new GrantProgramsController(_grant, _logger);
}
but error pops up for mocking. can somebody point out whether if this is not the way. I'm new to this. Thanks in advance.