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

后端 未结 4 612
遥遥无期
遥遥无期 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条回答
  •  猫巷女王i
    2020-12-01 10:50

    "So....what i did is the only way?"

    No not the only way - you are much better off implementing an interface and mocking that. Then your actual methods can be virtual or not as you choose.

提交回复
热议问题