Robert
Robert

Reputation: 4406

Unit testing and data returned from the database

I am using EF 6.1 and I will be handling the CUD in CRUD using this pattern. I am trying to decide what the best way to handle R(etrieve) is. Lets say my repository method returns a collection:

 public IEnumerable<MyObject> GetAll()
    {
        return _context.MyObject.OrderBy(x => x.Name);
    }

Should I be creating a test object that looks exactly like what the database will return? if yes, What if the database returns a list of over 200 items?

Should I assert that one or two items exist in the collection and move on?

Is there a better way to handle this situation?

Upvotes: 0

Views: 124

Answers (1)

Ganesh Anil Kalumbe
Ganesh Anil Kalumbe

Reputation: 310

Yes you can mock object of _context and from that get the items

Upvotes: 1

Related Questions