new to unit testing & mocking trying to use verify

125 views
Skip to first unread message

gswartz

unread,
Dec 2, 2012, 4:29:41 PM12/2/12
to moq...@googlegroups.com
I could have sworn I hit post on this topic but it's not appearing in the list for me so here it is again.  If a moderator sees a similar topic by me, feel free to remove one.  Sorry.

I'm not sure why the following won't compile.  

var mockCookieHandler = new Mock<ICookieHandler>();
mockCookieHandler.Verify(x => x.SaveCookie(It.IsAny<Dictionary<string, string>>(), It.IsAny<string>(), It.IsAny<DateTime>()), Times.Once);

These are the two errors I get for the Verify line.

Error 1 The best overloaded method match for 'Moq.Mock<FPO.Domain.Helpers.Web.ICookieHandler>.Verify(System.Linq.Expressions.Expression<System.Action<FPO.Domain.Helpers.Web.ICookieHandler>>, string)' has some invalid arguments
Error 2 Argument 2: cannot convert from 'method group' to 'string'

This is the signature of the CookieHandler class I'm trying to call. 

public void SaveCookie(Dictionary<string, string> values, string cookieName, DateTime? persistUntilDate)

Any ideas how I can make this work?  Thanks.

Mike Paterson

unread,
Dec 17, 2012, 1:27:31 PM12/17/12
to moq...@googlegroups.com
You need Times.Once(), not Times.Once.

Robert

unread,
Dec 18, 2012, 4:27:10 PM12/18/12
to moq...@googlegroups.com
Times.Once is a method, not a property

mockCookieHandler.Verify(x => x.SaveCookie(It.IsAny<Dictionary<string, string>>(), It.IsAny<string>(), It.IsAny<DateTime>()), Times.Once());


Reply all
Reply to author
Forward
0 new messages