Mocking in C# Unit Tests - How To Test Data Access Code and More

Mocking in C# Unit Tests - How To Test Data Access Code and More

303.380 Lượt nghe
Mocking in C# Unit Tests - How To Test Data Access Code and More
Unit tests are great, but how do you test your data access? You sure don't want to actually delete records when you are testing the delete method, yet you definitely want to be sure the method is configured properly. This is the type of problem that stops a lot of developers from creating unit tests. In this video, I am going to show you how to overcome these obstacles in order to write tests that handle working with external dependencies like databases. Full courses: https://www.iamtimcorey.com/ Source Code: https://leadmagnets.app/?Resource=MockingInUnitTests Patreon: https://patreon.com/IAmTimCorey Newsletter signup: https://signup.iamtimcorey.com/ Sponsors: Tuhafeni Angula (Patreon Subscriber) 0:00 - Intro 1:05 - Getting started: demo application code and setup 10:20 - Problems with testing methods that manipulates with external stuff (database edits, e-mail senders etc) 12:39 - Mocking explained 15:44 - Writing tests with mocking 18:05 - Adding references for testing with MOCK 20:51 - Using statement 22:12 - AutoMock.GetLoose() vs AutoMock.GetStrict(); 23:30 - Using AutoMock: Writing the Unit Test with mocking 35:06 - Refactoring method that's under a UnitTest 36:03 - Checking data: comparing two objects 40:19 - Testing method that returns void 48:16 - Testing SQl call modification 52:47 - Recap 53:30 - Advice for beginners 55:15 - What not to test and why 58:24 - Summary 59:27 - Learning steps 1:01:42 - Concluding remarks