Guest User

Untitled

a guest
Jul 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. public class BaseServices<T> : IBaseService<T> where T : BaseEntity, new()
  2. {
  3. public List<T> AllItem = new List<T>();
  4.  
  5. public bool Delete(int id)
  6. {
  7. bool b = false;
  8.  
  9. foreach (var a in AllItem)
  10. {
  11. if (a.Id == id)
  12. {
  13. AllItem.Remove(a);
  14.  
  15. b = true;
  16. }
  17. }
  18.  
  19. return b;
  20. }
  21.  
  22. public T Get(int id)
  23. {
  24. T b = null;
  25.  
  26. foreach (var a in AllItem)
  27. {
  28. if (a.Id == id)
  29. {
  30. b = a;
  31. return b;
  32. }
  33. }
  34.  
  35. return b;
  36. }
  37.  
  38. public object GetAll()
  39. {
  40. object b = null;
  41.  
  42. foreach (var a in AllItem)
  43. {
  44. b = a;
  45. return b;
  46. }
  47.  
  48. return b;
  49. }
  50.  
  51. public bool Save(T entity)
  52. {
  53. entity = new T();
  54.  
  55. AllItem.Add(entity);
  56.  
  57. return true;
  58. }
  59. }
  60.  
  61. List<AccountModel> Accounts = new List<AccountModel>();
  62.  
  63. private BaseServices<AccountModel> AccountBS = new BaseServices<AccountModel>();
  64.  
  65. Random rnd = new Random();
  66.  
  67. public void Repletion()
  68. {
  69. for (int index = 0; index < 100; ++index)
  70. {
  71. AccountBS.AllItem[index] = new AccountModel();
  72.  
  73. AccountBS.AllItem[index].Id = index;
  74.  
  75. }
  76.  
  77. }
  78.  
  79. [TestMethod]
  80. public void GetTest()
  81. {
  82. int SomeId = rnd.Next(100);
  83.  
  84. AccountModel result = AccountBS.Get(SomeId);
  85.  
  86. Assert.IsNotNull(result);
  87. }
  88.  
  89. private BaseServices<AccountModel> AccountBS = new BaseServices<AccountModel>();
  90. Random rnd = new Random();
  91.  
  92. [TestInitialize]
  93. public void Repletion()
  94. {
  95. for (int index = 0; index < 100; ++index)
  96. {
  97. AccountBS.AllItem.Add(new AccountModel { Id = index });
  98. }
  99. }
  100.  
  101. [TestMethod]
  102. public void GetTest()
  103. {
  104. int SomeId = rnd.Next(100);
  105.  
  106. AccountModel result = AccountBS.Get(SomeId);
  107.  
  108. Assert.IsNotNull(result);
  109. }
Add Comment
Please, Sign In to add comment