Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BaseServices<T> : IBaseService<T> where T : BaseEntity, new()
- {
- public List<T> AllItem = new List<T>();
- public bool Delete(int id)
- {
- bool b = false;
- foreach (var a in AllItem)
- {
- if (a.Id == id)
- {
- AllItem.Remove(a);
- b = true;
- }
- }
- return b;
- }
- public T Get(int id)
- {
- T b = null;
- foreach (var a in AllItem)
- {
- if (a.Id == id)
- {
- b = a;
- return b;
- }
- }
- return b;
- }
- public object GetAll()
- {
- object b = null;
- foreach (var a in AllItem)
- {
- b = a;
- return b;
- }
- return b;
- }
- public bool Save(T entity)
- {
- entity = new T();
- AllItem.Add(entity);
- return true;
- }
- }
- List<AccountModel> Accounts = new List<AccountModel>();
- private BaseServices<AccountModel> AccountBS = new BaseServices<AccountModel>();
- Random rnd = new Random();
- public void Repletion()
- {
- for (int index = 0; index < 100; ++index)
- {
- AccountBS.AllItem[index] = new AccountModel();
- AccountBS.AllItem[index].Id = index;
- }
- }
- [TestMethod]
- public void GetTest()
- {
- int SomeId = rnd.Next(100);
- AccountModel result = AccountBS.Get(SomeId);
- Assert.IsNotNull(result);
- }
- private BaseServices<AccountModel> AccountBS = new BaseServices<AccountModel>();
- Random rnd = new Random();
- [TestInitialize]
- public void Repletion()
- {
- for (int index = 0; index < 100; ++index)
- {
- AccountBS.AllItem.Add(new AccountModel { Id = index });
- }
- }
- [TestMethod]
- public void GetTest()
- {
- int SomeId = rnd.Next(100);
- AccountModel result = AccountBS.Get(SomeId);
- Assert.IsNotNull(result);
- }
Add Comment
Please, Sign In to add comment