BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Navigation Makes ASP.NET WebForms More Testable

| by Roopesh Shenoy Follow 0 Followers on Jun 18, 2012. Estimated reading time: 1 minute |

Navigation is a library that makes ASP.NET Web Forms more testable by moving the CRUD logic out of the codebehind files. Graham Mendick’s article “Unit Testing in the Navigation..” explores some of the features and how unit tests can be written.

What does this library do? It allows

  • Controls to be bound to controller methods in separate classes
  • Navigational binding

all inside your aspx page mark-up. For e.g., the markup for binding a FormView to its controller methods would look something like this -

<asp:FormView ID="Question" runat="server" DataSourceID="QuestionDataSource" DefaultMode="Edit">
<EditItemTemplate>
</EditItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="QuestionDataSource" runat="server" SelectMethod="GetQuestion" UpdateMethod="UpdateQuestion" TypeName="Survey.SurveyController" DataObjectTypeName="Survey.Question" />

where the GetQuestion and UpdateQuestion are controller methods implemented in an external class named SurveyController – they cannot directly access the controls, but the data is passed to them by the Navigation Library. Survey.Question refers to a ViewModel that is used in this example for transferring the data.

Why does this simplify unit testing? Because now, the business logic is in a separate POCO class with no web-specific behaviour. And this can be tested more easily. See the article for more details. 

As we have already covered on InfoQ, WebForms 4.5 gets model binders out-of-the-box – however this library allows the controller methods to be put in a separate class instead of the code-behind file which seems better for testability and reusability. If interested, you can download the Navigation NerdDinner walkthrough

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT