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

Cannot cast inside the Action<T> parameter of Verify method #1438

Open
BlueHydrangea2908 opened this issue Nov 4, 2023 · 2 comments
Open
Labels

Comments

@BlueHydrangea2908
Copy link

BlueHydrangea2908 commented Nov 4, 2023

I met an exception when trying to run the test that have the following code. When I try to make an expression that using a cast, this exception was throw by Moq: "System.ArgumentException : Unsupported expression: (IObserver)player". Why Moq don't allow to cast in this situation? Or I'm writing the test code in wrong way?

collectionOfMockForPlayer[1]
    .Verify((IPlayer player) => ((IObserver<IMove>)player).OnError(It.IsAny<MatchManager.IllegalMoveException>()), Times.Once());

Back this issue
Back this issue

Copy link

Due to lack of recent activity, this issue has been labeled as 'stale'.
It will be closed if no further activity occurs within 30 more days.
Any new comment will remove the label.

@github-actions github-actions bot added the stale label Aug 24, 2024
@github-actions github-actions bot removed the stale label Sep 3, 2024
@kzu
Copy link
Member

kzu commented Sep 3, 2024

Verify is used to match against invocations on the mock. Casting the object to another type does not involve any invocations on it (by default, unless you're trying to test an override of an implicit or explicit cast). Is that your scenario?

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

No branches or pull requests

2 participants