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

VerifyAdd does not work #1099

Closed
apazureck opened this issue Nov 10, 2020 · 2 comments
Closed

VerifyAdd does not work #1099

apazureck opened this issue Nov 10, 2020 · 2 comments
Milestone

Comments

@apazureck
Copy link

apazureck commented Nov 10, 2020

Hi,

First of all thanks for this great framework, having a lot of fun using it!

I stumbled upon a problem with verifying add. I currently use the nuget version 4.14.7

<PackageReference Include="Moq" Version="4.14.7" />

The target framework is .net core 3.1

I tried following test:

public class MyTestClass
{
    [Fact]
    public void TestMoq() 
    {
        
            Mock<MoqTestInterface> ti = new Mock<MoqTestInterface>();

            object o = null;

            ti.Object.TestEvent += obj => o = obj;

            ti.VerifyAdd(t => t.TestEvent += It.IsAny<TestDelegate>(), Times.Once());
        }
    }

    public delegate void TestDelegate(object input);

    public interface MoqTestInterface
    {
        event TestDelegate TestEvent;
    }

I would expect this to pass, because it was subscribed once, but my Test tells me it was not called.

What am I doing wrong?

Cheers!

@stakx stakx added this to the 4.15.0 milestone Nov 10, 2020
@stakx
Copy link
Contributor

stakx commented Nov 10, 2020

You're doing nothing wrong, it's just that for back-compatibility reasons, VerifyAdd required at least one prior call to SetupAdd / SetupRemove on the same mock. (See #1058.) This requirement has recently been lifted by #1082 and your use case should work in the upcoming release (4.15.0).

@stakx stakx closed this as completed Nov 10, 2020
@apazureck
Copy link
Author

Thanks for the quick reply. Worked like a charm. Ok, now I get why me/google did not find anything on that topic.

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

No branches or pull requests

2 participants