dimanche 28 février 2016

Running Unit Test on ASP.Net MVC5 with DbContext

I currently using Unit Testing on my projects but it seems I have trouble on getting the data on my site DBContext, I assume that I need to run the web project then run the test but I dont think Visual Studio permits that.

So I tried opening 2 instances of Visual Studio but it still did not work.

This is my code:

    private ApplicationDbContext db = new ApplicationDbContext();
    [TestMethod]
    public void IsDbNull()
    { 
        var dblist = db.StudentInformation.ToList(); 
        Assert.IsNotNull(dblist);
    }

A simple assert to check if the project can read my database, I tried debuging and dblist doesn't have any items on it.

I saw some codes that uses fake database by putting it as CSV but as much I dont want to go that method since I want to test the real data itself.

I also saw "Run Tests" on GitHub but it only supports VS 2012

Aucun commentaire:

Enregistrer un commentaire