I am trying to mock(Moq lib) an abstract class (In this example, X class). Inside this class, it is a property which has been assigned as a [ForeignKey("xId")]
. The classes are as follows, and I try to mock this X class.
But I get an error
"System.NotSupportedException: 'Invalid setup on a non-virtual (overridable in VB) member: mock => mock.SubX'"
.
Anyone has any idea what is the best way to mock such property?
public abstract class X
{
[ForeignKey("xId")]
public SubX SubX {get; set;}
}
public class SubX
{
[Key]
public int Id {get; set;}
}
var mockedX = Mock.Of<X>(a => a.SubX.Id == 10);