2009-12-04 1 views
0

저는 Rhino Mocks를 처음 사용하고 단위 테스트를 위해 모의 격리 프레임 워크를 사용합니다. 다음 테스트를 작성했습니다. 모의 IDataProvider 객체가 객체 컬렉션을 반환하도록 기대를 설정했습니다. 제공된 컬렉션에는 하나의 객체가 있습니다.Rhino 모의 기대가 콜렉션을 올바르게 반환하지 않음

테스트를 실행할 때 IDataProvider를 호출하면 하나의 개체가있는 목록을 반환 할 때 빈 목록이 반환됩니다.

어떤 아이디어가 잘못 되었나요?

여기 내 테스트입니다 : (여기에 어떤 나쁜 관행을 용 서하십시오 ... 감사를 배우려고 노력하고있는 임 언급 주시기 바랍니다!.) 시험 방법의

[TestMethod()] 
public void FetchDataSeries_NeedsUpdate_SuccessfulDataSeriesRetrievedFromDataProvider() { 
    List<IDataSeries> dataSeries = new List<IDataSeries>(); 
    dataSeries.Add(new DataSeries("test")); 
    DrillDownLevel level = DrillDownLevel.YEAR; 
    int? year = 2008; 

    var dataProvider = _MockRepository.CreateMock<IDataProvider>(); 
    dataProvider.Expect(dp => dp.GetDataSeries(String.Empty, level, year, null ,null, null)).Return(dataSeries); 
    _DataSourceContext.DataProvider = dataProvider; 

    CollectionAssert.AreEqual(dataSeries, _DataSourceContext.FetchDataSeries(level, year, null, null, null)); 
    dataProvider.VerifyAllExpectations(); 
} 

관련 부분 : (DataProvider에. GetDataSeries는 ...이 스텁 목록을 반환해야합니다.) 빈 목록을 반환 전화

 public override List<IDataSeries> FetchDataSeries(DrillDownLevel? drillDownLevel, int? year, int? month, DateTime? week, int? day) { 

    List<IDataSeries> dataSeries = new List<IDataSeries>(); 

    // Cache data for maximum cache period 
    // if data has been cached for longer than the maxium cache period OR the updateInterval has elapsed UNLESS LastUpdateAttempt was less than minimum update interval 
    if (NeedsUpdate(LastUpdate, LastUpdateAttempt)) { 

     // Attempt to get new data 
     LoggingService.InfoFormat("DataSourceContext: {0}: Attempting to get new data:", Name); 
     dataSeries = DataProvider.GetDataSeries(DataQuery, drillDownLevel, year, month, week, day); 
    } 

    return dataSeries; 
    } 
+0

아마도 당신이 테스트중인 코드에서 버그를 발견했다? FetchDataSeries 코드도 게시 할 수 있습니까? –

+0

IDataProvider.GetDataSeries가 오버로드 된 메서드입니까? 아니면 그 이름을 가진 메서드가 하나입니까? 구현에서 메소드에 전달되는 DataQuery 매개 변수는 무엇입니까? –

답변

2

나는 우리가 제공하는 코드를 말할 수 있다고 생각하지 않습니다,하지만 당신은 확인 시험에서 당신의 방법은 같은 PARAMS와 GetDataSeries를 호출된다? 나는 모의 문자열에서 string.empty 인 첫 번째 매개 변수에 대해 특히 궁금합니다. IgnoreParameters() 또는 Is.Any() 값 중 하나를 사용하는 경우 범위를 좁히고 이것이 문제인지 확인할 수 있습니다.

어쩌면 이것을 시도해보고 올바르게 반환되는지 확인한 다음 문제가 있다면 되돌릴 수 있습니다.

dataProvider.Expect(dp => dp.GetDataSeries(String.Empty, level, year, null ,null, null)).IgnoreParameters().Return(dataSeries); 
당신은 ReplayAll에게 전화를 놓치고
+0

예, 나는 params를 diff라고 생각했지만, 검사에서 기대했던 것과 똑같지 만, IgnoreParameters는 그것을 배제하기 위해 더 좋을 것입니다 ... 감사합니다! – theringostarrs