1 / 27

Unit Testing ASP.Net MVC

Unit Testing ASP.Net MVC. Craig Berntson Mojo Software Worx. Thanks to our Sponsors! . To connect to wireless 1. Choose Uguest in the wireless list 2. Open a browser. This will open a Uof U website 3. Choose Login . Ego stuff. Organizer, Utah Code Camp

zihna
Download Presentation

Unit Testing ASP.Net MVC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit Testing ASP.Net MVC Craig BerntsonMojo Software Worx

  2. Thanks to our Sponsors! To connect to wireless 1. Choose Uguest in the wireless list 2. Open a browser. This will open a Uof U website 3. Choose Login

  3. Ego stuff • Organizer, Utah Code Camp • Author, “Continuous Integration in .Net” • Conference & event speaker • INETA Community Speaker • ComponentOne Community Influencer • Columnist, DNC Magazine • 17 time Microsoft MVP • Chief Software GardenerMojo Software WorxSalt Lake City

  4. Problem with… • if • switch • for • foreach • while • do…while

  5. Worse than you think • In 1976, G.J. Meyers described a 100-line program that had 1018 unique paths. • In 1979 he described a much simpler program. It was just a loop and a few IF statements. In most languages, you could write it in 20 lines of code. This program has 100 trillion paths Testing Computer Software, CemKaner

  6. How do you test this?

  7. Agenda • What we won’t talk about • TDD • Javascript testing • Production ready code • What we’ll talk about • Setup tests • Remove database • Keep it simple

  8. Demo: Sample Application

  9. Unit test framework • MSTest • NUnit • xUnit • Others

  10. Unit test runner • MSTest • NUnit • Resharper • NCrunch • Others

  11. Demo: Our first test

  12. Default Data access • Difficult to test • There is no IDbContext • DbContext tightly bound to EF (EntityFramework.dll)

  13. Removing database access • Repositories • Mocks • Dependency Injection

  14. Repositories • Easy to test • IRepository • Extrapolate away from Context

  15. Mocks • Allows us to fake the database

  16. Testing vs. runtime

  17. Class2 • Class1 How we normally instantiate new Class2()

  18. ClassA • Class1 • ClassA : IClass2 Dependency injection IClass2()

  19. Dependency injection • Allows for loose coupling • Inversion of control (IOC) • IOC Container

  20. Demo: Removing Database access

  21. Selectlist • ViewBag • ViewModel • Automapper

  22. Demo: SELECTLIST

  23. Ajax & json • AJAX calls into the controller • JSON returns result

  24. Demo: ajax & json

  25. Next steps? • My blog • Art of Unit Testing • Udemy.com • Katas • TDD

  26. Review • Arrange – Act – Assert • In memory • Repositories • Mocks • Dependency Injection • Automapper

  27. Questions? • craig@craigberntson.com • @craigber • www.craigberntson.com/blog

More Related