I tried to make an unit test for this method which is pretty simple only add an object into the data base and if it works well returns true
Public Shared Function CrearCliente(ByVal cliente As Cliente) As Boolean
Try
db.Cliente.Add(cliente)
db.SaveChanges()
Return True
Catch ex As Exception
Throw New Exception("ocurrio un error guardando al cliente")
End Try
End Function
Now here’s my test
<TestMethod()>
Public Sub CrearClienteTest()
Dim mock = New Moq.Mock(Of Cliente)
Dim actual As Boolean
mock.Setup(Function(x) x.Nombre).Returns("blah")
'mock.Setup(Function(x) x.Apellido()
actual = Class1.CrearCliente(mock.Object)
Assert.AreEqual(True, actual)
End Sub
Pretty easy my question is why when Debugged the test throws this error
Invalid setup on a non-virtual (overridable in VB) member: x => x.Nombre
What could be wrong? do i need another configuration?
As the error states, Moq requires that the member you mock be
Overridable.