I would like to inject a fake nHibernate session into my repository using FakeItEasy, then return a list of objects that are predefined within my test. Does anyone have experience doing this?
Here is the example test:
[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.");
}
}
And here is the call within the actual ProductionRepository class:
public IEnumerable<Tank> GetTanks()
{
var tanks = Session.CreateCriteria(typeof(Tank)).List<Tank>();
return tanks;
}
Thanks in advance for any advice!