0

I'm creating some test using ms test for an already written routine that use entity framework, and I would like to use the [DataSource] attribute to generate a test routine for a set of data in the database.

My problem is that I can just select a Table and load the single fields in the test, but I would like to fetch directly a set ob ef entities and process directly in the test routine, in a way much more similar to the way the code to test is wrote.

Exist some kind of [EFDatasource] that let me express a Ef query as datasource and use the entity in the test?

thanks, luca

Luca Morelli
  • 2,530
  • 3
  • 28
  • 45

1 Answers1

0

You should just use a context instance (or service/repository, what have you) in your unit test method and get the entities from it. You can supply the connection string in a config file in the unit test project. This way the test methods will be totally relieved from any connection worries. They just instantiate objects and work with them.

Some will probably comment that this is not unit testing but integration testing and that you should mock the EF context, but that is virtually impossible. Testing EF should be done with... EF.

Community
  • 1
  • 1
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291