Modern Web Development
WebForms -> MVC -> Angular
Modern Web Development
WebForms -> MVC -> Angular
developingUX.com
speakermix.com/calebjenkins
@calebjenkins
#ctcc14
developingUX.com
speakermix.com/calebjenkins
@calebjenkins
#ctcc14
why
Testable
Repeatable
Maintainable Reliable-able
Scalable
Extensible
Deliverable
Workable
Development
Object Orientation
SOLID
Patterns
Secure Coding
Engineering
Automated Tests
Source Control
Automated Builds
Process
Agile, Lean, XP
Team Dynamics
Continuous Learning
write better code
12
what are the 4 big parts of unit tests?
Test Framework Test Runner
Code Tests
13
Test Framework Test Runner
Code Tests
14
your application
what you want to test
Test Framework Test Runner
Code Tests
15
your test code
the code that tests the
code that you wrote or are
going to write
Test Framework Test Runner
Code Tests
16
attributes and asserts
the framework provides
the attributes and asserts
so we know what the tests
are doing.
Examples: nUnit jUnit
cppUnit
Test Framework Test Runner
Code Tests
17
runs the tests
often associated with the
test framework; is
distinctly separate.
sometime integrated in
IDE, CI Server or stand
alone exe
Test Runner
18
Code
TestFramework
Tests
Tests
Tests
Tests
Tests
Test Runners
19
nUnit Test Runner
Test Runners
20
nUnit Test Runner
Visual Studio (VS Test)
Test Runners
21
nUnit Test Runner
Visual Studio (VS Test)
CodeRush / ReSharper
Test Runners
22
nUnit Test Runner
Visual Studio (VS Test)
CodeRush / ReSharper
Continuous Integration (Team City)
the problem with edges
UI DataBusiness
Edges are
Hard to Test
Testing edges
can be like
testing to see
if you’re good
at cliff jumping
That’s not me
..or you’re
stuff on a rock.
You’re either an
expert and it works…
UI DataBusiness
Edges are
Hard to Test
UI
Data
Data
Logic
UI
Logic
Business
Edges are still
Hard to Test
by separating UI/Data edges from
UI/Data logic we’re increasing the testable area
UI
Data
Data
Logic
UI
Logic
Business
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
UI
Data
Data
Logic
UI
Logic
Business
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
32
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 WinApp & 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)
Definitions
Reflects
With MVP
the Presenter “knows” about every field.
MobileNumber
BirthDay
In a MVVM
the Presenter “knows” about the
ViewModel
the View “binds” to the ViewModel
ViewModel can…
composite application models
contain behaviors
simplify application UI with
wpf/Silverlight/JavaScript binding
40
MVC
MVP
M-V-VM
41
MVC
MVP
M-V-VM
angularJS.org
handelbarsJS.com
knockoutJS.com
knockoutMVC.com ToDoMVC.com
Reflects
Resources & Frameworks
BDD
http://neelnarayan.blogspot.com/2010/07/bdd-is-more-than-tdd-done-right.html
more than TDD done right
http://dannorth.net/introducing-bdd/
introducing BDD
http://lucisferre.net/2011/02/05/behavior-driven-test-driven-domain-driven-design/
behavior driven, test driven, domain driven
nBehave, nSpec, SpecFlow, StoryQ,
mSpec, StorEvil
Handle your
dependencies
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
Data Access
Data Logic
Integration Service Proxy
App Domain Domain Validation
UI Logic
UI
How do you test this
with these
dependencies
Data Access
Data Logic
Integration Service Proxy
App Domain Domain Validation
UI Logic
UI
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
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
http://developingUX.com/DI/
- 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!”
Mocking in .NET
Microsoft.Fakes
Bringing DI together
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
WebForms -> MVP
WebForms -> MVC (Razor)
/Wall/Default.aspx
/Wall/Default.aspx.cs
/Wall/index.cshtml
Controllers/WallController.cs
/Wall/Default.aspx.cs /Controllers/WallController.cs
/Masterpage.master
/Wall/Default.aspx
/shared/_Layout.cshtml
/views/index.cshtml
/Masterpage.master.cs
WebForms -> MVC (Razor)
/Wall/Default.aspx.cs /Controllers/WallController.cs
/Masterpage.master
/Wall/Default.aspx
/shared/_Layout.cshtml
/views/index.cshtml
/Masterpage.master.cs /Controllers/BaseController.cs
WebForms -> MVC (Razor)
/Masterpage.master
<asp:ContentPlaceHolder ID="MainCol" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID=“LeftCol" runat="server">
</asp:ContentPlaceHolder>
/Wall/Default.aspx
<asp:Content ID="Content2"
ContentPlaceHolderID=“MainCol" runat="server">…
<asp:Content ID="Content3"
ContentPlaceHolderID="LeftCol" runat="server">….
/views/shared/_Layout.cshtml
@RenderBody()
@RenderSection("LeftCol", false)
/views/Wall/index.cshtml
@section LeftCol {
}
WebForms -> MVC (Razor)
MVC -> Angular
AngularJS
/Controllers/WallController.cs
https://github.com/webformsmvp/webformsmvp
http://www.flickr.com/photos/dieselbug2007/370557683/
http://www.flickr.com/photos/fudj/122371431/
http://www.flickr.com/photos/yardsale/4524101944/
http://www.flickr.com/photos/38738277@N04/3652658961/
http://www.flickr.com/photos/utslibrary/6776175796/
http://www.flickr.com/photos/48725518@N03/4478990651/
Copyright © Merriswheel – Used without permission
http://www.flickr.com/photos/mworrell/266913194/
https://www.flickr.com/photos/ddebold/5900039667
developingUX.com
speakermix.com/calebjenkins
@calebjenkins

Modern ASP.NET Webskills

Editor's Notes

  • #58 Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.
  • #59 Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.
  • #60 Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.
  • #61 Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.
  • #62 Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.
  • #63 Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.
  • #64 Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.