question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Guidance for unit testing when FromSql<> is used.

See original GitHub issue

We have unit tests that use the InMemory provider.

However, a few of our objects under test are calling the FromSql() method to materialise objects from stroed procedures.

When using the InMemoryProvider this obviously doesn’t work.

One solution i can think of is for the object under test to use the Repository pattern - so we can swap EF7 out entirely at test time, for an InMemory repository. However I think it would be good if the InMemory provider had a way to handle FromSql at test time, so you could map an abitrary set of results when needed?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
dazinatorcommented, Dec 8, 2016

I don’t think this really solves the issue though… we use InMemoryProvider during testing, because we want to eliminate the need for having an external database asset to manage. This means we can run unit tests on any machine quite easily, with minimal setup.

Using sqllite provider at test time isn’t an option if the subject under test is calling FromSql<> and passing in a variant of sql like for example, Postgres. (Because you use Postgres in production) or executing a sproc.

So the only reliable way to get this to work is to not use the InMemory provider, and use the full blown relational provider - which brings us back to square one - managing the external database at test time.

If there was some mechanism to mock or map FromSql<> and still use the InMemory provider I think that is what we would like to do.

0reactions
camainccommented, Jun 27, 2018

Thanks for responding. I deleted my comment because I realized it was a stupid question. I did just what you suggested as soon as I deleted the comment.

Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guidance for unit testing when FromSql<> is used. #7212
We have unit tests that use the InMemory provider. However, a few of our objects under test are calling the FromSql() method to...
Read more >
Entity Framework Core FromSql mock test cases
Don't mock FromSql and DbContext in general. Write and execute tests against actual database. Mocking will provide zero value and waste the time ......
Read more >
Testing against your Production Database System - EF Core
Note that testing against a different database than what is used in production (e.g. Sqlite) is not covered here, since the different database ......
Read more >
Integration Testing with Entity Framework Core and SQL ...
Entity Framework Core makes it easy to write tests that execute against an in-memory store. Using an in-memory store is convenient since we ......
Read more >
SQL Server Unit Testing in Visual Studio
Visual Studio with SQL Server Data Tools can be used to perform unit testing against stored procedures to test expected output and behavior....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found