-
-
Notifications
You must be signed in to change notification settings - Fork 811
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
Callbase not working on latest 4.8 version #557
Comments
Hi @rotem925 and thanks for reporting. Could you please provide a short code example that demonstrates the issue you're having? |
Hi @stakx public class Program
{
static void Main(string[] args)
{
var mock = new Mock<MyClass>().As<IMyClass>();
mock.CallBase = true;
Assert.NotNull(mock.Object.DoSomething()); //this assertion does not pass!!
}
public interface IMyClass
{
object DoSomething();
}
public class MyClass:IMyClass
{
public object DoSomething()
{
return new object();
}
}
} |
@rotem925 - Thanks a lot for the repro code. It looks like this is a regression introduced by 5837c53: -if (invocation.Method.DeclaringType == typeof(object) || // interface proxy
- mock.ImplementsInterface(invocation.Method.DeclaringType) && !invocation.Method.LooksLikeEventAttach() && !invocation.Method.LooksLikeEventDetach() && mock.CallBase && !mock.MockedType.GetTypeInfo().IsInterface || // class proxy with explicitly implemented interfaces. The method's declaring type is the interface and the method couldn't be abstract
- invocation.Method.DeclaringType.GetTypeInfo().IsClass && !invocation.Method.IsAbstract && mock.CallBase // class proxy
- )
+if (mock.CallBase && !invocation.Method.IsAbstract) That cryptic multi-line condition had to go for a variety of reasons; one being that it was near incomprehensible. Replacing it with something much simpler was admittedly a bit of a gamble, but I ended up doing it because there was no test failure hinting at any functional change. Sorry about that. It should be easily fixed, though. Expect a fixed release soon. |
That was fast! |
@rotem925 - The fix for this is included in Moq 4.8.1 which has just been made available on NuGet. |
@stakx Thanks for the update! |
Hi,
I've upgraded to 4.8.
When setting CallBase=true on new Mock(), and debugging, it seems that the call base does not get called.
Was there any change that could affect this or is there any bug? I didn't see any breaking changes that affect this in the changelog.
Thanks,
Rotem
The text was updated successfully, but these errors were encountered: