c# - Testing Linq Queries EF and the Repository Pattern -



c# - Testing Linq Queries EF and the Repository Pattern -

trust me, i've read many articles , questions here on so. haven't found satisfactory answer. take matt robert's tutorial on repository pattern , unit testing example:

i don't it.. both repositories contain exact same query logic? appears so, , if how useful pattern? mean whenever alter query in false repository, have alter query logic in actual repository - sounds pita , recipe problems.

i maintain query in one method , test method. later occurred me, this:

//student can db or false list public person getstudent(ienumerable<student> students,int studentid) { homecoming students.firstordefault(s =>s.personid ==studentid); } //unit test assert.isnull(getstudent(fakestudentlist, -1)) //actual code var pupil = getstudent(entities.students,-1)

is there pattern mimics above? if so, it? or in fact how repository pattern works? if so, why sense repository pattern duplicates code?

and also, effort.. @ terrifying example :s?

there's not much go on, think have flaw in repository pattern.

you should not pass in pupil collection getstudent(). getstudent should part of class internally knows pupil list - whether it's file, list, database, whatever.

so "fake" repository may have same logic, or may homecoming hard-coded dummy student. if you're faking repository assume because you're testing else needs repository, shouldn't care how got student.

also article reference mentions 1 repository, i'm not sure why you're needing duplicating it.

c# entity-framework unit-testing repository-pattern

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -