Articles : Page 1 of 1

  • Unit Testing Secure Controller Actions with Moq

    Unit Testing Secure Controller Actions with Moq

    Aug 10
    15

    One of the hardest things to unit test in MVC is security. Security is tough to test because there is a lot of setup involved in mocking the HttpContext, the Principal and the Identity. For example, in WeBlog I am using the following code in the Edit Post action. Post post = Repository.FirstOrDefault<Post>(x => x.ID == id); if (post == null) return View(NotFound if (!HttpContext.User.CanEditPost(post)) return View(PermissionDenied In order to make sure this code works properly I need to t...



  • 1