Integration Testing Entity Framework CRD operations -
i'm struggling integration tests when using entity framework.
i seed database test data in test project, wondering how manange test create, update , delete operations.
basicly have test data e.g. contains 5 customer entries... can write unit tests data based on these 5 entries. (e.g. return collection containing 5 items).
but if have test deletes 1 customer, means getall test expect 5 customers, return 4 (if test executed after delete test) , fails.
how work around issue? give order tests or reseed database before every test (but sounds bad?)...
thanks !
an effective way use transaction scope. wraps sql calls , rolls changes if scope disposed without calling complete method. basic test this.
public class transactionaltestsbase { private transactionscope _scope; [testinitialize] public void initialize() { _scope = new transactionscope(); } [testcleanup] public void testcleanup() { _scope.dispose(); } [testmethod] public void crudaction() { var repo = new yourrepo(); var client = ; // make client repo.deleteclient(client); assert.areequal(4,repo.getclients().count()); } }
ideally inherit base test class not write tests in it.
there new heat in beta still think in future. have @ effort
Comments
Post a Comment