Why return null when the method of object a generic class?

There is a generalized class that describes a repository. Here is the code
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;
}
 }</t></t></t></t>


And there's a test
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);
}
 }</accountmodel></accountmodel></accountmodel></accountmodel>

Somehow, result = null.Please tell me.
June 3rd 19 at 19:33
2 answers
June 3rd 19 at 19:35
Solution
The list is empty. The default value is null. So he returns it.
You forgot to bring Repletion to initialize the database.
June 3rd 19 at 19:37
Solution
You don't see all the code, but from what I see most likely - does not start Repletion. And if it doesn't, then the Get method do not return, as AllItem will be empty. Add in the test one more scan to obtain the element - the fact that AccountBS.AllItem not an empty array

Find more questions by tags C#ASP.NET