I have a legacy class something along the lines of this:
Public Class MyOverloadExample
Public Overridable ReadOnly Property SomeDescription() As String
Get
Return "No Parameter"
End Get
End Property
Public ReadOnly Property SomeDescription(ByVal p1 As Integer) As String
Get
Return "Used Parameter"
End Get
End Property
End Class
I want to SetupGet
on the first SomeDescription
Property with no parameters. I tried this:
Dim mock = New Mock(Of MyOverloadExample)
mock.SetupGet(Function(i) i.SomeDescription()).Returns("Mocked the No Parameter Property")
But it fails with this exception:
threw exception:
System.Reflection.AmbiguousMatchException: Ambiguous match found.
at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetProperty(String name, BindingFlags bindingAttr)
at Moq.ExpressionExtensions.ToPropertyInfo(LambdaExpression expression) in C:\projects\moq4\src\Moq\ExpressionExtensions.cs:line 47
at Moq.Mock.SetupGetPexProtected[T,TProperty](Mock`1 mock, Expression`1 expression, Condition condition) in C:\projects\moq4\src\Moq\Mock.cs:line 511
at Moq.PexProtector.Invoke[T1,T2,T3,TResult](Func`4 function, T1 arg1, T2 arg2, T3 arg3) in C:\projects\moq4\src\Moq\PexProtector.cs:line 38
at Moq.Mock.SetupGet[T,TProperty](Mock`1 mock, Expression`1 expression, Condition condition) in C:\projects\moq4\src\Moq\Mock.cs:line 496
at Moq.Mock`1.SetupGet[TProperty](Expression`1 expression) in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 332
I tried without the empty () but get the same exception:
mock.SetupGet(Function(i) i.SomeDescription).Returns("Mocked the No Parameter Property")
Is there some lambda/moq magic I'm missing or is this just not possible with Moq?