Im new to MOQ and I am a little confused with the setup method. The example below shows one method that i need to test. The method under test returns the latest time from two dates, so I create two datetime objects and pass them to my function. The part where I'm confused is the returns call. This ignores the logic in my method and returns what I tell it to. For example if i say returns(date2) then the assert passes regardless of the logic. Am I doing something wrong?
public virtual DateTime LatestTime(DateTime t1, DateTime t2)
{
if (t1.CompareTo(t2) > 0)
return t1;
return t2;
}
[Test]
[Category("Catalogue service")]
public void TestLatestTimeReturnsCorrectResult()
{
//Arrange
DateTime date1 = new DateTime(2014, 07, 25, 13, 30, 01);
DateTime date2 = new DateTime(2014, 07, 25, 13, 30, 00);
MockCatalogueService.Setup(x => x.LatestTime(date1, date2)).Returns(date2);
//Act
DateTime retDate = MockCatalogueService.Object.LatestTime(date1, date2);
//Assert
Assert.That(retDate == date2);
}