asp.net mvc - Need help to understand how Moq resolved the actual query -


below test case runs fine.

    [testmethod]     public void getcompanies_wheninvokedwithsearchtext_shouldreturnfilteredcompanies()     {         // arrange         var context = new mock<idatacontext>(mockbehavior.strict);         var companies = new list<company>         {             new company()             {                 address = "london",                 name = "abc inc."             },             new company()             {                 address = "newyork",                 name = "toyota"             },             new company()             {                 address = "ealing broadway",                 name = "amazon"             }         };         context.setup(s => s.query<company>()).returns(companies.asqueryable());         var repository = new companyrepository(context.object);          // act         var expectedcompanies = repository.getcompanies("abc");          // assert         assert.areequal(1, expectedcompanies.count);         assert.areequal("london", expectedcompanies.tolist()[0].address);     } 

my repository code this:

    public icollection<company> getcompanies(string searchtext)     {         guard.argumentnotnull(searchtext, "searchtext");          return _dbcontext.query<company>().where(c => c.name.contains(searchtext) || c.address.contains(searchtext)).tolist();     } 

i not how moq happen apply filter (where) present on actual method did not set in test?

my guess is, when test executes mocked object's query method called filter applied already. discovering clause present dynamically using reflection?

just want understand clearly.

there no magic :) take line

context.setup(s => s.query<company>()).returns(companies.asqueryable()); 

when method query<company>() executed, returns companies.asqueryable(). where executed on this, moq not guessing anything.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -