Why does the property I want to mock need to be virtual?

后端 未结 4 587
遥遥无期
遥遥无期 2020-12-01 10:10

I\'m doing some unit testing, and mocking some properties using Moq.

Now, this is a Controller test (ASP.NET MVC 3). My Controllers

4条回答
  •  自闭症患者
    2020-12-01 11:03

    Moq and other similar mocking frameworks can only mock interfaces, abstract methods/properties (on abstract classes) or virtual methods/properties on concrete classes.

    This is because it generates a proxy that will implement the interface or create a derived class that overrides those overrideable methods in order to intercept calls.

提交回复
热议问题