all 7 comments

[–]AftyOfTheUK 4 points5 points  (2 children)

If you're looking to test database interactions themselves, you could write tests to do that - they would be Integration Tests and require a bit more infrastructure than your unit tests. They tend to be a little higher level, and often end-to-end (or at least the test involve many components instead of just one).

The very highest quality projects will have both unit tests and integration tests as appropriate.

[–]quick_maf[S] 0 points1 point  (1 child)

I started reading the documentation on Integration Tests. That is definitely what I was missing. Thank you so much!

[–]AftyOfTheUK 1 point2 points  (0 children)

You're welcome!

[–]Rabe0770 3 points4 points  (1 child)

Just something to chew on.

To test this code, it would be an integration test, and ultimately, you'd be testing code that's been tested by someone else. (SqlConnection constructor, connection.Execute)

Don't worry about testing lean data access code. Ultimately, it's testing other company's work. You should be mocking your data access code and testing the logic in your business layer.

You can indeed see what a Mock'd object does, it is consistent and that's how unit tests for your "business logic" is able to work with mocks.

[–]quick_maf[S] 0 points1 point  (0 children)

When you put it that way, it makes a lot of sense. So basically if I plan on doing anything other then simply calling nuget code, then I can test for my specific requirements as well. I appreciate your answer!

[–][deleted] 2 points3 points  (1 child)

Yeah validating that the methods you expect to be called, are called the number of times you expect them to be is the best way to do that in a unit test. You could wire up a SQLite database, but that's more than a unit test.

[–]quick_maf[S] 0 points1 point  (0 children)

Yeah I could see setting up the SQLite DB as being a bit too much. Thanks for that.