entity framework 5 - EF Code First, Unique Contraints, and Testing -
we implementing our unique constraint executing sql straight in seed method
context.database.executesqlcommand( "begin seek alter table mytable add together constraint uc_code unique (col1, col2, col3) end seek begin grab end catch");
however, can't write tests this.
i mock repository, , insert same record twice, but...of course, no error thrown, because database isn't called (and shouldn't be), how write test ensures error thrown when duplicate record inserted?
unit test needs tun code want test. want test ef+db reaction constraint violations. so, need run tests on real (test) database, can create in origin of test.
unit-testing entity-framework-5 code-first unique-constraint
No comments:
Post a Comment