3
IdleClass idleSend = MockRepository.GenerateMock<IdleClass >();
SpeedClass speedSend = MockRepository.GenerateMock<SpeeClass >();
idleSend.Expect(x => x.IsUnitInSystem(networkID)).Return(true).Repeat.Any();
speedSend.Expect(x => x.IsUnitInSystem(networkID)).Return(true).Repeat.Any();
和原IsUnitInSystem(網絡ID)功能(在IdleClass和SpeedClass一個子類)低於:
public bool IsUnitInSystem(string networkID)
{
DateTime outVal = default(DateTime);
return m_list1.DoesListContainUnit(networkID) ||
m_list2.TryGetValue(networkID, out outVal) ||
m_list3.TryGetValue(networkID, out outVal) ||
m_list4.TryGetValue(networkID, out outVal) ||
m_list5.TryGetValue(networkID, out outVal);
}
我在返回的復活System.NullReferenceException行在IsUnitInSystem函數中。
堆棧跟蹤:
IdleClass.IsUnitInSystem(String networkID)
PendingTest.<ResendClassTest>b__1b(IdleClass x)
RhinoMocksExtension.Expect[T,R](T mock, Function'2 action)
PendingTest.ResendClassTest()
什麼,我不明白是爲什麼,以及如何將程序甚至進入該功能時我已經指定了功能的.Expect功能?
正因爲功能而來的是'Expect'子句中,並不意味着它將無法正常運行。當代碼碰到expect行時,它會進入函數,並且如果m_list1爲null,那麼您將獲得空引用。 –
請確保networkid匹配電話 –
那麼最近的期望是什麼?我想繞過被調用的函數,因爲在我的測試中列表將始終爲空。 –