Testing WebForms w/ Model-View-Presenter Erik Peterson
What is MVP? A design pattern, similar to Model-View- Controller, which allows for separation of concerns Allows for testability via the Presenter
MVP vs MVC The MVC way (code-behind): In the beginning, we had code-behind, and it was good In the beginning, we had code-behind, and it was good Business logic wound up closely tied to the UI Business logic wound up closely tied to the UI The new ASP.NET MVC Framework Gets rid of the.NET heavy-weight webform model Gets rid of the.NET heavy-weight webform model
MVP vs MVC The MVP way: Model is the same Model is the same View is the.aspx and code-behind View is the.aspx and code-behind Controller is the Presenter Controller is the Presenter Still have the webform model Still have the webform model
Model Where the data lives Defines structure and relation of data in your system Defines structure and relation of data in your system
View Handles the UI Contains the controls (server, HTML, etc) Contains the controls (server, HTML, etc) Handles data rendering, layout, etc Handles data rendering, layout, etc Implements interface to allow communication with the Presenter Implements interface to allow communication with the Presenter
Presenter Where the business logic lives Interacts with model to retrieve relevant data Interacts with model to retrieve relevant data Passes data to the view, retrieves necessary info from the view Passes data to the view, retrieves necessary info from the view Can use dependency injection for testability Can use dependency injection for testability
Model Presenter View MVP From Up High
Our Demo We want to view a list of players on our football team We want to be able to add a player to our team We want to be able to remove a player from our team
Where do we begin? Retrieving players, load them to the view Front end vs. Back end And now, to the code!
Questions? Blog: