new to mocking - question about verify

625 views
Skip to first unread message

gswartz

unread,
Dec 2, 2012, 2:11:57 PM12/2/12
to moq...@googlegroups.com
I'm fairly new to mocking and unit testing, so sorry if this is a simple one.  I'm trying to write a unit test to make sure my login controller is working.  Part of the login controller's method logic is to call the cookiehandler's save method which is below.  

public void SaveCookie(Dictionary<string, string> values, string cookieName, DateTime? persistUntilDate){
//...logic here
}

So in my unit test I have this which is not compiling and I'm not sure why.

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

I get the following error when trying to compile which points at the Verify line....

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

Andy McMullan

unread,
Dec 3, 2012, 6:30:26 AM12/3/12
to moq...@googlegroups.com
Try Times.Once() instead of Times.Once
> --
> Post: moq...@googlegroups.com
> Unsubscribe: moqdisc-u...@googlegroups.com

gswartz

unread,
Dec 3, 2012, 5:54:10 PM12/3/12
to moq...@googlegroups.com, an...@andymcm.com
Oh my goodness... I can't believe it was that simple.  Thanks so much!
Reply all
Reply to author
Forward
0 new messages