public void Forbidden() { // Arrange var context = new Mock <ControllerContext>(); context.Setup(x => x.HttpContext.Response.StatusCode).Verifiable(); using (var controller = new ErrorsController()) { controller.ControllerContext = context.Object; // Act var result = controller.Forbidden() as ViewResult; // Assert Assert.IsNotNull(result); context.VerifySet(x => x.HttpContext.Response.StatusCode = 403); } }