Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. using System.Reflection;
  2. using Ploeh.AutoFixture.Kernel;
  3.  
  4. namespace AutofixtureDemo
  5. {
  6. public class ContinuousAutoIdSpecimenBuilder : ISpecimenBuilder
  7. {
  8. private int _nextId;
  9.  
  10. public ContinuousAutoIdSpecimenBuilder()
  11. : this(1)
  12. {
  13. }
  14.  
  15. public ContinuousAutoIdSpecimenBuilder(int start)
  16. {
  17. _nextId = start;
  18. }
  19.  
  20. public object Create(object request, ISpecimenContext context)
  21. {
  22. var pi = request as PropertyInfo;
  23. if (pi != null && pi.Name.Equals("Id") && pi.PropertyType == typeof(int))
  24. {
  25. return _nextId++;
  26. }
  27.  
  28. return new NoSpecimen(request);
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement