Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IRepository
- {
- }
- public interface IRepository<T>
- {
- public IEnumerable<T> Find(Criteria criteria)
- }
- public class SomeObject
- {
- IRepository<SomeObject> repository;
- public SomeObject(){}
- public IRepository<SomeObject> repository { get; set; }
- IEnumerable<SomeObject> FindAll()
- {
- //let's assume new Criteria() will return all results
- return respository.Find(new Criteria());
- }
- }
- [TestFixture]
- public class SomeObjectTests
- {
- [Test]
- public void TestSomeObjectFindAll()
- {
- IRepository<SomeObject> stubRepository = MockRepsitory.GenerateStub<IRepsitory<SomeObject>>();
- stubRepository.Expect(r => r.Find(new Criteria())
- .Return(new List<SomeObject>{
- new SomeObject(),
- new SomeObject(),
- new SomeObject());
- var testObject = new SomeObject { Repository = stubRepository };
- IList<SomeObject> findAllResult = testObject.FindAll();
- //returned list contains 3 elements, as expected above
- Assert.AreEqual(3, findAllResult.Count)
- }
- }
Add Comment
Please, Sign In to add comment