dimanche 1 mai 2016

Unit testing web api using Entity Framework

Any better examples or tutorials available on Unit testing projects using Entity framework than this

http://ift.tt/19HUIeZ

In my case API project is using Entity framework file Edmx file and accessing the tables from the edmx file from Repository class. [ Not really like the codefirst or dbfirst approach ]

The structre of repo class looks like

 public class AppBackendRepository
{
    // modify the type of the db field
    private AppDBEntities db_context = new AppDBEntities();

    public List<Student> Get()
    {
        return db_context.Students.ToList();
    }
}



public class StudentController
{

    private static AppBackendRepository repo;
    public  StudentController()
    {

        repo = new AppBackendRepository();
    }

    public  IEnumerable<Student> GetStudents()
    {
        List<Student> students = repo.Get();

        return students;
    }
}

How can i write a proper Unit testing against this way of code architecture

Aucun commentaire:

Enregistrer un commentaire