I am getting a NotSupportedException error message on my Unit Test using Moq
System.NotSupportedException: Invalid setup on a 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 to mark it as virtual
, but I'm not sure what needs to be marked as virtual?
The error is occurring at this line:
dataAccess.Setup(m => m.Stocks).Returns(mockSetStock.Object);