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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With