System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member

佐手、 提交于 2019-12-04 16:31:57

Assuming you're using EF of at least V6 and based on this example (look at the Blogs element) which is doing a very similar thing to you. I'd guess that your problem is that your dataAccess, whatever it is doesn't declare Stocks as virtual.

So it should look something like this:

public virtual DbSet<Stock> Stocks { get; set; } 

The property or function you're trying to setup needs to be declared as

public virtual

otherwise Moq can't create an inherited class, which overrides this function or propterty, which is nessecary, when you want to setup it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!