moq icon indicating copy to clipboard operation
moq copied to clipboard

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

Open BlueHydrangea2908 opened this issue 2 years ago • 2 comments

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<IMove>)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

BlueHydrangea2908 avatar Nov 04 '23 15:11 BlueHydrangea2908

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[bot] avatar Aug 24 '24 20:08 github-actions[bot]

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?

kzu avatar Sep 03 '24 02:09 kzu

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[bot] avatar Apr 06 '25 01:04 github-actions[bot]

This issue will now be closed since it has been labeled 'stale' without activity for 30 days.

github-actions[bot] avatar May 06 '25 01:05 github-actions[bot]