Guest User

Untitled

a guest
Jun 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public interface IRepository
  2. {
  3. }
  4.  
  5. public interface IRepository<T>
  6.  
  7. {
  8. public IEnumerable<T> Find(Criteria criteria)
  9. }
  10.  
  11. public class SomeObject
  12. {
  13. IRepository<SomeObject> repository;
  14.  
  15. public SomeObject(){}
  16.  
  17. public IRepository<SomeObject> repository { get; set; }
  18.  
  19. IEnumerable<SomeObject> FindAll()
  20. {
  21. //let's assume new Criteria() will return all results
  22. return respository.Find(new Criteria());
  23. }
  24. }
  25.  
  26. [TestFixture]
  27. public class SomeObjectTests
  28. {
  29. [Test]
  30. public void TestSomeObjectFindAll()
  31. {
  32. IRepository<SomeObject> stubRepository = MockRepsitory.GenerateStub<IRepsitory<SomeObject>>();
  33.  
  34. stubRepository.Expect(r => r.Find(new Criteria())
  35. .Return(new List<SomeObject>{
  36. new SomeObject(),
  37. new SomeObject(),
  38. new SomeObject());
  39.  
  40. var testObject = new SomeObject { Repository = stubRepository };
  41. IList<SomeObject> findAllResult = testObject.FindAll();
  42.  
  43. //returned list contains 3 elements, as expected above
  44. Assert.AreEqual(3, findAllResult.Count)
  45. }
  46. }
Add Comment
Please, Sign In to add comment