c# - System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member -
i getting notsupportedexception error message on unit test using moq
system.notsupportedexception: invalid setup on non-virtual (overridable in vb) member
unit test code:
[testmethod] public void testemailnotsentout() { // ... var dataaccess = new mock<tjicontext>(); var mocksetstock = new mock<dbset<stock>>(); mocksetstock.as<iqueryable<stock>>().setup(m => m.provider).returns(stocklist.provider); mocksetstock.as<iqueryable<stock>>().setup(m => m.expression).returns(stocklist.expression); mocksetstock.as<iqueryable<stock>>().setup(m => m.elementtype).returns(stocklist.elementtype); mocksetstock.as<iqueryable<stock>>().setup(m => m.getenumerator()).returns(stocklist.getenumerator()); dataaccess.setup(m => m.stocks).returns(mocksetstock.object);
a suggestion in this post says mark virtual
, i'm not sure needs marked virtual?
the error occurring @ line:
dataaccess.setup(m => m.stocks).returns(mocksetstock.object);
assuming you're using ef of @ least v6 , based on example (look @ blogs element) doing similar thing you. i'd guess problem dataaccess
, whatever doesn't declare stocks
virtual.
so should this:
public virtual dbset<stock> stocks { get; set; }
Comments
Post a Comment