내 개념이 잘못되었는지 알려주십시오. 나는 2 개의 과목을 가지고있다. Country
및 State
. 상태에는 CountryId
속성이 있습니다.NUnit을 사용하여 항목 목록 테스트
Service.cs
public LazyList<State> GetStatesInCountry(int countryId)
{
return new LazyList<State>(geographicsRepository.GetStates().Where(s => s.CountryId == countryId));
}
IRepository.cs
public interface IGeographicRepository
{
IQueryable<Country> GetCountries();
Country SaveCountry(Country country);
IQueryable<State> GetStates();
State SaveState(State state);
}
MyTest.cs 내가 필요
private IQueryable<State> getStates()
{
List<State> states = new List<State>();
states.Add(new State(1, 1, "Manchester"));//params are: StateId, CountryId and StateName
states.Add(new State(2, 1, "St. Elizabeth"));
states.Add(new State(2, 2, "St. Lucy"));
return states.AsQueryable();
}
[Test]
public void Can_Get_List_Of_States_In_Country()
{
const int countryId = 1;
//Setup
geographicsRepository.Setup(x => x.GetStates()).Returns(getStates());
//Call
var states = geoService.GetStatesInCountry(countryId);
//Assert
Assert.IsInstanceOf<LazyList<State>>(states);
//How do I write an Assert here to check that the states returned has CountryId = countryId?
geographicsRepository.VerifyAll();
}
을 다음과 같이
나는 서비스 및 저장소를 가지고 정보를 확인하는 반환 된 주정부. 루프를 작성하고 어설 션을 넣어야합니까?
유효하지 않은 LINQ입니다. Assert가 boolean 값을 리턴해야한다고 알려줍니다. –
미안하지만 네가 맞다면 미친 것처럼 지적해야한다. –