• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
MSDN - ASP.NET MVC
 

MSDN - ASP.NET MVC

on

  • 18,921 views

Introduction to the ASP.NET MVC framework. (Belgium MSDN session)

Introduction to the ASP.NET MVC framework. (Belgium MSDN session)

Statistics

Views

Total Views
18,921
Views on SlideShare
17,748
Embed Views
1,173

Actions

Likes
1
Downloads
376
Comments
0

10 Embeds 1,173

http://blog.maartenballiauw.be 1098
http://www.slideshare.net 34
http://www.blog.maartenballiauw.be 9
http://www.techgig.com 8
http://cartrackr.codeplex.com 6
http://sos-dev 6
http://webcache.googleusercontent.com 5
http://www.codeplex.com 3
http://www.realdolmenblogs.com 3
http://reader.youdao.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

MSDN - ASP.NET MVC MSDN - ASP.NET MVC Presentation Transcript

  • ASP.NET MVC (model-view-controller) Maarten Balliauw – RealDolmen http://blog.maartenballiauw.be
  • Who am I?
    • Maarten Balliauw
    • Antwerp, Belgium
    • www.realdolmen.com
    • Focus on web
      • ASP.NET, ASP.NET MVC, PHP, Azure, VSTS, …
    • http://blog.maartenballiauw.be
    • http://twitter.com/maartenballiauw
  • Agenda
    • Overview of ASP.NET
    • ASP.NET MVC
    • Building an application
    • Unit testing
    • Should I choose Webforms or MVC?
    • Q&A
  • ASP.NET…
    • “ one web application framework to rule them all”
    • Always seen as one whole…
    ASP.NET Caching Modules Handlers Intrinsics Pages Controls Globalization Profile Master Pages Membership Roles Etc.
  • Look at it differently!
    • Core infrastructure
    • Different presentation options
    Presentation Runtime ASP.NET Dynamic Data ASP.NET WebForms ASP.NET MVC ASP.NET Core
  • ASP.NET MVC
    • A new presentation option for ASP.NET
    • Simpler way to program ASP.NET
    • Easily testable and TDD friendly
    • More control over your <html/>
    • More control over your URLs
    • Not for everyone! (car vs. motorcycle)
    • Not a replacement for webforms!
    • Supports existing ASP.NET features
  • Things you will lose…
    • Viewstate
    • Postbacks
    • Tricky interview questions about nuances of the page lifecycle 
  • MVC? Model-View-Controller! Separation of concerns! Controller (Input) Model (Logic) View (Presentation)
  • What does an MVC request look like? Controller Handles input (HTTP requests) View Visually represents the model ViewData Request View Controller Response
  • DEMO File > New…
  • Framework Goals
    • Easy and frictionless testability
    • Full control over your <html/>
    • Full control over your URLs
    • Leverage existing ASP.NET features
    • Conventions and guidance
  • Clean URLs
    • Would you use:
    • /Products.aspx?CategoryID={3F2504E0-4F89-11D3-9A0C-0305E82C3301}
    • Or:
    • /Products/Books
    My Favorite
  • Extensibility
    • These come into play…
    • … and are all replacable!
    Controller Builder Controller Factory Controller View Engine View Controller Action Invoker Action Result Action Filters Model Binders
  • DEMO
    • Building an ASP.NET MVC application
  • Testing
    • Has anyone tried testing webforms?
    • Without IIS being fired up?
    • Each component tested individually?
    • Did you require vacation afterwards?
  • Infrastructure designed for testing
    • These are all easily mockable!
      • HttpContextBase, HttpResponseBase, HttpRequestBase
    • Extensibility
      • IController
      • IControllerFactory
      • IRouteHandler
      • IViewEngine, IView
  • Testing controller actions
    • No requirement to test within ASP.NET runtime!
      • Can mock parts of runtime you want to fake
      • Using Moq, Rhino, TypeMock, …
        • http://code.google.com/p/moq/
    [TestMethod] public void ShowPostsDisplayPostView() { BlogController controller = new BlogController(…); var result = controller.ShowPost(2) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.ViewData[ &quot; Message &quot; ], &quot; Hello &quot; ); }
  • Testing controller actions using Moq
    • More on Mocking? Visit VISUG on May 7, 2009 – www.visug.be)
    [TestMethod] public void TestInvalidCredentials() { LoginController controller = new LoginController(); var mock = new Mock<System.Web.Security.MembershipProvider>(); mock.Expect(m => m.ValidateUser(&quot;&quot;, &quot;&quot;)).Returns(false); controller.MembershipProviderInstance = mock.Object; var result = controller.Authenticate(&quot;&quot;, &quot;&quot;) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.ViewName, &quot;Index&quot;); Assert.AreEqual(controller.ViewData[&quot;ErrorMessage&quot;], &quot;Invalid credentials! Please verify your username and password.&quot;); }
  • Testing frameworks
    • Any framework is supported!
      • Visual Studio Test
      • NUnit
      • XUnit
      • MBUnit
  • DEMO
    • Unit testing
  • Choosing between Webforms and MVC
    • ASP.NET Webforms
    • Winforms-alike event model
    • Familiar controls
    • Familiar = rapid application development
    • Functionality per page
    • Uses viewstate for state management
    • Less control over rendered HTML
    • ASP.NET MVC
    • Less complex: separation of concerns
    • Easier parallel development
    • TDD support
    • No viewstate, …
    • Full control over behavior and HTML
    • Makes you think
  • So what do I choose?
    • Go with the flow!
    • Remember: mixing of worlds is possible!
      • Mixing with ASP.NET Webforms
      • Mixing with dynamic data
  • Takeaways
    • A new option for ASP.NET
      • Not a replacement for Webforms!
    • More control over your <html/> and URLs
    • Strong, frictionless testability
  • Resources
    • “ ASP.NET MVC 1.0 Quickly” http://tinyurl.com/mvcquickly
    • My blog http://blog.maartenballiauw.be/category/MVC.aspx
    • Microsoft http://www.asp.net/mvc http://wiki.asp.net/page.aspx/286/aspnet-mvc-framework/
    • http://blog.wekeroad.com/blog/i-spose-ill-just-say-it-you-should-learn-mvc/
    • Community projects http://mvccontrib.codeplex.com http://mvcsitemap.codeplex.com
  • Questions and Answers
    • http://blog.maartenballiauw.be
    • [email_address]
  • © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.