The world is moving towards ASP.NET MVC.. but what about your legacy WebForms development. What are the things you can do today to make your WebForms more testable, reliable and even increase the SEO and usability of your WebForms. This talk will walk through applying the Model View Presenter pattern to your ASP.NET WebForm applications and introduce you to some additional enhancements that Microsoft has made to WebForms recently to make your site and life that much better!
This presentation was given at the Tulsa Tech Fest 2014 - in Tulsa, OK - http://developingux.com/TulsaTech2014/
14. Test Framework Test Runner
Code Tests
16
your application
what you want to test
your test code
the code that tests the
code that you wrote or are
going to write
attributes and asserts
the framework provides
the attributes and asserts
so we know what the tests
are doing.
Examples: nUnit jUnit
cppUnit
runs the tests
often associated with the
test framework; is
distinctly separate.
sometime integrated in
IDE, CI Server or stand
alone exe
22. UI DataData
Logic
UI
Logic
Business
Edges are
Hard to Test
Edges are still
Hard to Test
by separating UI/Data edges from
UI/Data logic we’re increasing the testable area
we’ve also made it easier to implement
various UI and Data platforms
without affecting the application logic
23. 25
Model View Controller (MVC)
•All input is routed to a controller
•Example Web Scenarios
•ASP.NET MVC Framework
Model View Presenter (MVP)
• View initiates Presenter
• UI Logic is contained in Presenter
• Example WinForms & ASP.NET Webform apps
Model View ViewModel (MVVM)
• ViewModel is a view specific model
• VM is can mash up application models
• UI logic contained in ViewModel
• Example Rich Data binding Scenarios
(WPF / Silverlight / XAML / JS)
42. Dependencies
“The single greatest thing that you can do to
make your code more testable and healthy is to
start taking a Dependency Injection approach to
writing software”
- Real World .NET, C# and Silverlight
Wrox Press 2012
Caleb Jenkins
45. Test Runner
Test Code
Integration Service Proxy
App Domain Domain Validation
UI Logic
Dependency Injection + Interfaces
Faked dependencies to increase unit isolation
Leverage mocking frameworks makes life better
46. Note:
Dependency Injection
will turn you in to a complete
coding Ninja, however the
full scope of DI with any of
the many DI frameworks is
beyond the scope of this talk
48. - Real World .NET, C# and Silverlight
Wrox Press 2012
Caleb Jenkins
Mocking Framework
“A mocking framework allows you to create fake classes on the fly in-
line with your test code. That is a bit of a simplification, mocking
frameworks use a combination of emits, reflection and generics to
create run-time instance implementations of .NET Interfaces – whew,
that’s a mouthful - it’s a whole lot easier to say that they create fake
classes on the fly!”
66. Test Code … 3 A’s
75
Arrange– Set up the scenario and the initial input values. Often
in a common [TestFixtureSetup] or [Setup] method
Act - Action that creates the outcome that is being tests, usually
calling some method in your code to test the result.
Assert – Is a boolean statement to your testing framework to
declare the expected outcome. Results in Pass or Fail
Arrange Act Assert
67. Data Access
Data Logic
Integration Service Proxy
App Domain Domain Validation
UI Logic
UI
Building better Lego’s
Tests are small
Tests are fast
Tests focus on one thing
69. Test Runner
Simple Tests (return values) with no dependencies…
App Domain Domain Validation
UI Logic
Test Code
Unit Tests focus on a Unit
Test a unit in isolation from other units
Control input => Testable output
70. as a <role>,
I will <function>
so that <value>
Defining Behavior
Discussion
71. what if our “tests”
given <class> to test
when <setup> scenario
then <test> outcome
matched our
language?
Discussion