Tests are specifications of your code. Lets think what scenario of SurveyListModel
behavior you are trying to specify by this test. In this case logic is very straight-forward:
SurveyListModel should return surveys from repository for specified date
So, if you'll stop and think, then you should not verify dates of returned surveys. SurveyListModel responsibilities does not involve modifying repository response in any way. It should do following - pass date parameter to one specific method of repository, and just return repository response to caller. Nothing else. That's what you should verify.
var repositoryMock = new Mock<ISurveyListRepository>();
string date = DateTime.Today.ToShortDateString();
repositoryMock.Setup(r => r.GetSurveyList(date)).Returns(CreateTestSurveys());
var model = new SurveyListModel(repositoryMock.Object);
var surveys = model.GetSurveyList(date);
repositoryMock.VerifyAll();
CollectionAssert.AreEqual(CreateTestSurveys(), surveys);
This test verifies that
- survey list called correct method of repository (if method was not called, verification will fail)
- correct date was passed (if SurveyListModel will pass different date to repository, setup will not be executed)
- survey list returned exactly same surveys which it got from repository (if SurveListModel will return different surveys, or modify repository response in any way, then assertion should fail).
You should understand, that it really does not matter what repository returns in this scenario. It could be surveys with any dates, or empty list as above. You should just verify that exactly same collection was returned by SUT.
NOTE: Use DateTime
to pass date values.