Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moq VerifySet(Action) replacing obsolete expression compilation error

Tags:

c#

moq

Referring to this question:

Moq how to replace obsolete expression

I have the following:

[Test]
public void OnSearchRequest_ViewFiresEvent_EventIsHandled()
{
    // Arrange
    Mock<IViewUsers> view = new Mock<IViewUsers>();
    Users users = new Users(view.Object);

    // Act
    view.Raise(v => v.SearchForUsers += null, this, new SearchEventArgs());

    // Assert
    view.VerifySet(v=> v.SearchResult = It.IsAny<List<IUser>>());

}

originally I had:

        // Assert
        view.VerifySet(v => v.SearchResult);

But was getting the warning:

'Moq.MockExtensions.VerifySet(Moq.Mock, System.Linq.Expressions.Expression>)' is obsolete: 'Replaced by VerifySet(Action)'

So I found the question referenced above, and changed it to match, but now I'm STILL getting that warning, and on top of that, a hard error on "v.SearchResult" within the call to VerifySet :

An expression tree may not contain an assignment operator.

I can't see that I'm formatting this improperly - so why isn't it recognizing this as an action as the other question implies it should?

like image 415
The Evil Greebo Avatar asked Mar 14 '12 15:03

The Evil Greebo


1 Answers

I found something relatively close to what you are asking about. Moq how to replace obsolete expression I don't know if this helps because I only ever used mock.Setup and mock.Verify.

Also as mentioned before try using lambda expressions within your It.IsAny to pinpoint smaller things this way . If a verify fails you know exactly where it failed. Especially if you are expecting a value at a certain position for example.

like image 141
ManuCote Avatar answered Oct 17 '22 07:10

ManuCote