Shim DbContext ctor for Effort unit testing

effort entity-framework microsoft-fakes shim unit-testing

Question

I want to snoop aroundvar context = new MyDbContext() to give back an alternative constructor call.

Zzz-12-Zzz is wonderful since it makes it simple to set up an in-memory database for unit testing.

var connection = Effort.DbConnectionFactory.CreateTransient();
var testContext = new MyDbContext(connection);

However, you would have to inject that.context your repository.

public FooRepository(MyDbContext context) { _context = context; }

Can you merely intercept data?var context = new MyDbContext() in order for it to return thetestContext ?

using (var context = new MyDbContext()) {
    // this way, my code isn't polluted with a ctor just for testing
}
1
1
6/11/2016 8:48:07 PM

Accepted Answer

ZZZ_tmp
0
6/18/2016 8:08:27 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow