Tag: asp.net core mvc 2.0

如何unit testingViewComponent.Invoke()?

在ViewComponent对象中, HttpContext和User是只读属性。 如何对这样的组件进行unit testing? 我正在使用MSTest Freamwork。 以下属性用于我的代码中 曲奇饼 会议 用户(System.Security.Principal) public ViewViewComponentResult Invoke() { var vm = new SummaryViewModel(); if (User.Identity is ClaimsIdentity identity && identity.IsAuthenticated) { vm.IsAuthenticated = true; vm.UserName = identity.Claims.FirstOrDefault(c => c.Type == “UserName”).Value; vm.PhotoUrl = identity.Claims.FirstOrDefault(c => c.Type == “FacePicture”).Value; } return View(vm); } [TestMethod] public void UserSummaryVcTest() { var component […]