【发布时间】:2011-05-27 18:11:19
【问题描述】:
如何设置我的起订量以返回一些值并让测试服务选择正确的值?
IRepository:
public interface IGeographicRepository
{
IQueryable<Country> GetCountries();
}
服务:
public Country GetCountry(int countryId)
{
return geographicsRepository.GetCountries()
.Where(c => c.CountryId == countryId).SingleOrDefault();
}
测试:
[Test]
public void Can_Get_Correct_Country()
{
//Setup
geographicsRepository.Setup(x => x.GetCountries()).Returns()
//No idea what to do here.
//Call
var country = geoService.GetCountry(1);
//Should return object Country with property CountryName="Jamaica"
//Assert
Assert.IsInstanceOf<Country>(country);
Assert.AreEqual("Jamaica", country.CountryName);
Assert.AreEqual(1, country.CountryId);
geographicsRepository.VerifyAll();
}
我基本上卡在设置上。
【问题讨论】:
标签: unit-testing nunit moq