编写单元测试时,新增一个控制器的抽象类。如下定义:

1 [TestClass]
2 public abstract class TestControllerBase<T> : TestBase where T : Controller

编写一个HomeController的单元测试:

1 [TestClass]
2 public class TestHomeController : TestControllerBase<HomeController>

编译通过,但Test的Output窗口提示:System.TypeLoadException was unhandled Message="GenericArguments[0], "TestControllerBase`1[T]' violates the constraint of type parameter 'T'."。后来发现HomeController引用的System.Web.Mvc.dll版本号为3.0.0.0,而单元测试项目却是4.0.0.0。

相关文章:

  • 2021-08-01
  • 2021-11-08
  • 2021-06-11
  • 2021-11-04
  • 2022-12-23
  • 2022-01-22
  • 2021-10-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-01-29
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案