Build Robust Web Apps in the Real WakeUpAndCode.com * aka ASP.NET 5 before RC1
Background > Getting Started > Writing and Running Tests > Dependency Injection & Mocking What’s Next?
> Nothing new to learn > Error-prone > Expensive > Slower
> Less human error > Faster! > Decreasing costs > Learning curve
Legacy New/ Improved Design Patterns S.O.L.I.D.TDDRefactorRestructure SRP OCP LSP ISP DIP
Unit TestsIntegration TestsUI Tests
public test class [Fact] for public methods without parameters [Theory] and [InlineData] for methods with parameters
Build Solution Run Tests in Test Explorer
Verify actual result against expected result Note “var” keyword
Verify that expected view equal to returned view
Temporarily ignore tests with an optional message.
Correct Views? Redirect to URL? Correct Models? HTTP Code? Mock Depen- dencies! Model Populated?
Dependency Injection Inversion of Control
In Startup: Add namespace and dependencies In Application Code: Constructor Injection Setter Injection
Mocks Pre-programmed with expected results, doesn’t actually connect to DB, behavior verification. Fakes Working examples, but not production-ready (e..g in-memory database) Stubs Provides canned answers
Smoke Tests New Features Edge Cases
Cost of Adding Unit Tests Cost of Not Having Unit Tests Bugs Features Expenses
Views & ViewModels Controllers Service Layer Repository Layer Entity Framework (ORM) SQL Server (database)
60 to 80% coverage ok?
Databases File Systems Network Resources Web Requests & Responses
Background > Getting Started > Writing and Running Tests > Dependency Injection & Mocking What’s Next?
Twitter: