How to mock Ilogger in nunit?

Raj
Raj
Member
76 Points
23 Posts

I'm using nunit project in .net 6.0 application. How to mock Ilogger in nunit?

Views: 99
Total Answered: 1
Total Marked As Answer: 1
Posted On: 20-Feb-2023 06:34

Share:   fb twitter linkedin
Answers
Priya
Priya
Member
236 Points
53 Posts
         

Try as following:

public class ScheduleTest
{
    private Mock<IApplicationUnitOfWork> _applicationUnitOfWork;
    private Mock<ILogger<ScheduleService>> _logger;
    private IScheduleService _scheduleService;
    
    [SetUp]
    public void Setup()
    {
        _applicationUnitOfWork = new Mock<IApplicationUnitOfWork>();
        _logger = new Mock<ILogger<ScheduleService>>();
        _scheduleService = new ScheduleService(_applicationUnitOfWork.Object, _logger.Object);
    }

    [Test]
    [TestCase(0)]
    public async Task Schedule_Success(int testCase)
    {
        //
    }
}
Posted On: 20-Feb-2023 08:12
thanks.
 - Raj  12-Mar-2023 02:21
 Log In to Chat