Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue mocking Vb.Net class with overloaded property in base class #1153

Closed
myurashchyk opened this issue Apr 8, 2021 · 1 comment · Fixed by #1155
Closed

Issue mocking Vb.Net class with overloaded property in base class #1153

myurashchyk opened this issue Apr 8, 2021 · 1 comment · Fixed by #1155
Labels
Milestone

Comments

@myurashchyk
Copy link

myurashchyk commented Apr 8, 2021

vb.Net code:

Public Class MyVBClassBase
   Public Overridable ReadOnly Property Prop() As Boolean
        Get
            Return True
       End Get
    End Property
    Public Overridable ReadOnly Property Prop(ByVal userID As Guid) As Boolean
        Get
            Return False
        End Get
    End Property
End Class

Public Class MyVBClass
    Inherits MyVBClassBase
End Class

C# code:

            var my = new Mock<MyVBClass>();
            my.Setup(m => m.Prop).Returns(true);

throws exception
System.InvalidOperationException
HResult=0x80131509
Message=Sequence contains more than one matching element
Source=System.Core
StackTrace:
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source, Func2 predicate)
at Moq.ExpressionExtensions.GetReboundProperty(MemberExpression expression) in C:\projects\moq4\src\Moq\ExpressionExtensions.cs:line 365
at Moq.ExpressionExtensions.g__Split|5_0(Expression e, Expression& r, InvocationShape& p, Boolean assignment, Boolean allowNonOverridableLastProperty) in C:\projects\moq4\src\Moq\ExpressionExtensions.cs:line 310
at Moq.ExpressionExtensions.Split(LambdaExpression expression, Boolean allowNonOverridableLastProperty) in C:\projects\moq4\src\Moq\ExpressionExtensions.cs:line 149
at Moq.Mock.Setup(Mock mock, LambdaExpression expression, Condition condition) in C:\projects\moq4\src\Moq\Mock.cs:line 505
at Moq.Mock1.Setup[TResult](Expression1 expression) in C:\projects\moq4\src\Moq\Mock`1.cs:line 455
at ConsoleApp1.Program.Main(String[] args) in C:\SandBox\MoqTests\ConsoleApp1\Program.cs:line 14

This exception was originally thrown at this call stack:
System.Linq.Enumerable.SingleOrDefault(System.Collections.Generic.IEnumerable, System.Func<TSource, bool>)
Moq.ExpressionExtensions.GetReboundProperty(System.Linq.Expressions.MemberExpression) in ExpressionExtensions.cs
Moq.ExpressionExtensions.Split.__Split|5_0(System.Linq.Expressions.Expression, out System.Linq.Expressions.Expression, out Moq.InvocationShape, bool, bool) in ExpressionExtensions.cs
Moq.ExpressionExtensions.Split(System.Linq.Expressions.LambdaExpression, bool) in ExpressionExtensions.cs
Moq.Mock.Setup(Moq.Mock, System.Linq.Expressions.LambdaExpression, Moq.Condition) in Mock.cs
Moq.Mock.Setup(System.Linq.Expressions.Expression<System.Func<T, TResult>>) in Mock`1.cs

code

            var my = new Mock<MyVBClassBase>();
            my.Setup(m => m.Prop).Returns(true);            

does not throw exception

@stakx
Copy link
Contributor

stakx commented Apr 8, 2021

Thanks @myurashchyk for reporting! I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants