我花了几天的时间写测试,然后不得不在最后一分钟添加一个属性来修复我在编写测试时发现的一个问题。由于添加该属性我一直坚持只是试图让模拟框架的功能。犀牛嘲笑为什么我不能嘲笑一个物业?
这是我的代码。
using (_mockRepository.Record())
{
_mockBattleDao.Expect(b => b.GetUnprocessedActions(gameId, round)).Return(roundResolvingItems);
_mockDao.Expect(b => b.GetMidGameCharacterStats(gameId, round)).Return(midGameCharacterStats);
_mockBattleDao.Expect(b => b.GetAmbientCharacterBuffs(_mockTiersHelper, gameId, round)).Return(new List<Buff>());
_mockBattleDao.Expect(b => b.GetActiveTriggerBuffs(_mockTiersHelper, gameId, round)).Return(triggerBuffs);
_mockBattleDao.Expect(b => b.GetActiveAmbientBuffs(_mockTiersHelper, gameId, round)).Return(new List<Buff>());
_mockDao.Expect(b => b.GetGame(gameId)).Return(new Common.Entities.Game { CompletionType = "single party down" });
_mockDao.Expect(b => b.GetAbilityById(1337)).Return(ability).Repeat.Times(3);
_mockDao.Expect(b => b.GetAbilityById(1727)).Return(attackAbility).Repeat.Times(4);
_mockTiersHelper.Expect(b => b.AddStatistic(Arg<StatAndCount>.Is.Anything)).Repeat.Times(3);
SetupResult.For(_mockTiersHelper.Round).Return(round);
}
TiersCalculationContainer container;
using (_mockRepository.Playback())
{
container = engine.ProcessTiers();
}
我知道AAA语法是新的辣味,但我有一个大的测试已完成,但这个,我不想回去重写。
当代码执行到达 “回放” 的关闭 “}” 使用我得到此异常:
ExpectationViolationException
TiersCalculationContainer.get_Round();预期#1,实际#0。
在调试测试属性“圆”被正确读取和retursn我嘲笑它的价值,所以我知道它被称为。
我不能在网上找到有关这方面的消息。似乎有大约100种方法来嘲讽Rhino mock中的一个房产。他们都没有工作,这是非常令人沮丧的。
我也曾尝试嘲讽所有的这些方式以及(及以上)
_mockTiersHelper.Expect(b => b.Round).Return(round);
Expect.Call(_mockTiersHelper.Round).PropertyBehavior();
_mockTiersHelper.Round = round;
我认为这个答案可能是这是一个错误。我抛弃了犀牛并回到了Moq。 10分钟,我起身跑步。现在我的测试通过了。谢谢Moq! – omatase