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

前端 未结 2 361
清酒与你
清酒与你 2021-01-07 04:49

I am getting a NotSupportedException error message on my Unit Test using Moq

System.NotSupportedException: Invalid setup on a non-virtual (overridable

相关标签:
2条回答
  • 2021-01-07 05:33

    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.

    0 讨论(0)
  • 2021-01-07 05:38

    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; } 
    
    0 讨论(0)
提交回复
热议问题