Using Moq to Lock an Interface

Possible duplicate:
How to mock a method that returns int with MOQ

Here is my interface:

public interface ICalenderService { DateTime Adjust(DateTime dateToAdjust, BusinessDayConvention convention, List<HolidayCity> holidayCities); } 

I did some research, and it looks like you can easily mock this reality, but I want it to be disabled using Moq, so that I can pass the stub to my other class conductors and that the stub returns all DateTime I want to use its method Adjust .

What is the easiest way to do this?

Edit: I know that I can create my own stub in my project, but I would like to write less code, and I think that Moq can let me do this, I just don't know what the syntax looks like.

+8
c # unit-testing moq stub
source share
1 answer

Configure the stub as follows:

 var calendarServiceStub = new Mock<ICalenderService>(); calendarServiceStub .Setup(c => c.Adjust(It.IsAny<DateTime>(), It.IsAny<BusinessDayConvention>(), It.IsAny<List<HolidayCity>>())) .Returns(theDateTimeResultYouWant); 

Pass calendarServiceStub.Object another class constructor.

+14
source share

All Articles