Questions tagged «ilogger»

13
如何在ASP.NET Core中使用ILogger进行单元测试
这是我的控制器: public class BlogController : Controller { private IDAO<Blog> _blogDAO; private readonly ILogger<BlogController> _logger; public BlogController(ILogger<BlogController> logger, IDAO<Blog> blogDAO) { this._blogDAO = blogDAO; this._logger = logger; } public IActionResult Index() { var blogs = this._blogDAO.GetMany(); this._logger.LogInformation("Index page say hello", new object[0]); return View(blogs); } } 如您所见,我有2个依赖项,a IDAO和aILogger 这是我的测试类,我使用xUnit进行测试,使用Moq创建模拟和存根,我可以DAO轻松进行模拟,但是由于ILogger我不知道要做什么,所以我只传递了null并注释掉了登录控制器的调用运行测试时。有什么方法可以测试,但仍然以某种方式保持记录器? public class …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.