用FakeItEasy伪造nHibernate会话
||
我想使用FakeItEasy将伪造的nHibernate会话注入到我的存储库中,然后返回测试中预定义的对象列表。有人有这样做的经验吗?
这是示例测试:
[TestFixture]
public class ProductionRepositoryTester
{
private ProductionRepository _productionRepository;
[SetUp]
public void SetupFixture()
{
const string propertyNumber = \"123\";
Tank tank = new Tank { PropertyNumber = propertyNumber };
var session = A.Fake<ISession>();
var sessionFactory = A.Fake<ISessionFactory>();
A.CallTo(session).WithReturnType<IList<Tank>>().Returns(new List<Tank> { tank });
_productionRepository = new ProductionRepository(session, sessionFactory);
}
[Test]
public void ProductionRepositoryCanGetTanks()
{
var tanks = _productionRepository.GetTanks();
Assert.AreNotEqual(0, tanks.Count(), \"Tanks should have been returned.\");
}
}
这是实际ProductionRepository类中的调用:
public IEnumerable<Tank> GetTanks()
{
var tanks = Session.CreateCriteria(typeof(Tank)).List<Tank>();
return tanks;
}
在此先感谢您的任何建议!
没有找到相关结果
已邀请:
1 个回复
梦砍废么
(我希望我记得正确的条件类型,我认为这是ICriteria,但我不确定百分百。)