moq - Making AutoMoq return Fixture-created values for methods -


i'd explore wether can save time setting moq-mocks created automoq should default return fixture-created values method return values.

this beneficial when doing test following:

[testmethod] public void client_search_sendsrestrequest()     var client = fixture.create<client>();      // removed implementing mentioned functionality     mock.of(jsongenerator).setup(j => j.search(it.isany<string>())).returns(create("jsonbody")));      client.search(fixture.create("query"));      mock.of(client.restclient).verify(c => c.execute(it.isany<restrequest>()));     mock.of(client.restclient).verify(c => c.execute(it.is<restrequest>(r => record(r.body) == record(client.jsongenerator.search(query))))); } 

note generated values must cached inside (?) proxies, want same value "frozen" in order check. also, setting mock setup should override created value.

so, how can modify automoq mocks this?

a simple test verifying works be:

[testmethod] public void mockmethodsshouldreturncreatedvalues() {     guid.parse(new fixture().create<itest>().test()); }  public interface itest {     string test(); } 

definitely possible, use autoconfiguredmoqcustomization instead of automoqcustomization. mocks use fixture generate returns values methods, properties , indexers (*).

properties evaluated eagerly, whereas indexers/methods' return values evaluated , cached when invoked first time.

(*) there 2 exceptions rule - customization cannot automatically setup generic methods or methods ref parameters, explained here. you'll have set manually, of .returnsusingfixture method.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -