Tải bản đầy đủ (.pdf) (507 trang)

PROFESSIONAL ASP.NET MVC 4 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (25.96 MB, 507 trang )

ffirs.indd iiffirs.indd ii 9/11/2012 3:00:11 PM9/11/2012 3:00:11 PM
PROFESSIONAL ASP.NET MVC 4
FOREWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvii
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
CHAPTER 1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
CHAPTER 2 Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
CHAPTER 3 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
CHAPTER 4 Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71
CHAPTER 5 Forms and HTML Helpers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
CHAPTER 6 Data Annotations and Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
CHAPTER 7 Membership, Authorization, and Security . . . . . . . . . . . . . . . . . . . . . . . . .137
CHAPTER 8 Ajax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
CHAPTER 9 Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
CHAPTER 10 NuGet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
CHAPTER 11 ASP.NET Web API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
CHAPTER 12 Dependency Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
CHAPTER 13 Unit Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
CHAPTER 14 Extending MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
CHAPTER 15 Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
CHAPTER 16 Real-World ASP.NET MVC: Building the NuGet.org Website . . . . . . . . 423
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
ffirs.indd iffirs.indd i 9/11/2012 3:00:11 PM9/11/2012 3:00:11 PM
ffirs.indd iiffirs.indd ii 9/11/2012 3:00:11 PM9/11/2012 3:00:11 PM
PROFESSIONAL
ASP.NET MVC 4
ffirs.indd iiiffirs.indd iii 9/11/2012 3:00:11 PM9/11/2012 3:00:11 PM
ffirs.indd ivffirs.indd iv 9/11/2012 3:00:11 PM9/11/2012 3:00:11 PM
PROFESSIONAL
ASP.NET MVC 4
Jon Galloway


Phil Haack
Brad Wilson
K. Scott Allen
ffirs.indd vffirs.indd v 9/11/2012 3:00:11 PM9/11/2012 3:00:11 PM
Professional ASP.NET MVC 4
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-34846-8
ISBN: 978-1-118-42432-2 (ebk)
ISBN: 978-1-118-41675-4 (ebk)
ISBN: 978-1-118-43404-8 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, elec-
tronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the
1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through pay-
ment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978)
750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department,
John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at
/>Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect
to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including without
limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or promotional
materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the
understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional
assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author

shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation
and/or a potential source of further information does not mean that the author or the publisher endorses the information the
organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web
sites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the United
States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard
print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD
or DVD that is not included in the version you purchased, you may download this material at
. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 9781118348468
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other countries,
and may not be used without written permission. All other trademarks are the property of their respective owners. John
Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
ffirs.indd viffirs.indd vi 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
To my wife, Rachel, my daughters, Rosemary, Esther,
and Ellie, and to you for reading this book. Enjoy!
—Jon Galloway
My wife, Akumi, deserves to have her name
on the cover as much as I do, for all her support
made this possible. And thanks to Cody for his
infectious happiness.
—Phil Haack
To Potten on Potomac.
—K. Scott Allen
ffirs.indd viiffirs.indd vii 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
ffirs.indd viiiffirs.indd viii 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
ABOUT THE AUTHORS
JON GALLOWAY works at Microsoft as a Windows Azure Technical Evangelist focused on the ASP

.NET platform. He wrote the MVC Music Store tutorial, helped organize mvcConf and aspConf
(free online conferences for the ASP.NET community), and speaks at conferences and Web Camps
worldwide. He also has worked in a wide range of web development shops, from scrappy startups
to large fi nancial companies. He’s part of the Herding Code podcast
(),
blogs at
and twitters as @jongalloway. He lives in San
Diego with his wife, three daughters, and a bunch of avocado trees.
PHIL HAACK works at GitHub, striving to make Git and GitHub better for developers on Windows.
Prior to joining GitHub, Phil was a Senior Program Manager with the ASP.NET team whose areas
of responsibility included ASP.NET MVC and NuGet. As a code junkie, Phil loves to craft software.
Not only does he enjoy writing software, he enjoys writing about software and software manage-
ment on his blog,
/>BRAD WILSON works for Microsoft as a Senior Software Developer on the Azure Application
Platform and Tools team on the ASP.NET MVC and Web API projects. Prior to ASP.NET, Brad
also worked on the CodePlex and the Patterns and Practices teams at Microsoft, and has acted as a
developer, consultant, architect, team lead, and CTO at various software companies for nearly 20
years. He’s the co-author of the xUnit.net open source developer testing framework, maintains a
blog focused primarily on ASP.NET topics at
and tweets as
@bradwilson. Brad lives in beautiful Redmond, Washington.
K. SCOTT ALLEN is the founder of OdeToCode LLC and a software consultant. Scott has 20 years of
commercial software development experience across a wide range of technologies. He has delivered
software products for embedded devices, Windows desktop, web, and mobile platforms. He has
developed web services for Fortune 50 companies and fi rmware for startups. Scott is also a speaker
at international conferences and delivers classroom training and mentoring to companies around the
world.
ffirs.indd ixffirs.indd ix 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
ABOUT THE TECHNICAL EDITOR
EILON LIPTON joined the ASP.NET team as a developer at Microsoft in 2002. On this team, he has

worked on areas ranging from data source controls to localization to the UpdatePanel control. That
team is now part of the Azure Application Platform Team, where Eilon is the principal development
manager for ASP.NET MVC, ASP.NET Web API, and Entity Framework. Eilon is also a speaker on
a variety of ASP.NET-related topics at conferences worldwide. He graduated from Boston University
with a dual degree in Math and Computer Science. In his spare time Eilon spends time in his garage
workshop building what he considers to be well-designed furniture. If you know anyone who needs
a coffee table that’s three feet tall and has a slight slope to it, send him an e-mail.
ffirs.indd xffirs.indd x 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
ACQUISITIONS EDITOR
Mary James
PROJECT EDITOR
John Sleeva
TECHNICAL EDITOR
Eilon Lipton
PRODUCTION EDITOR
Daniel Scribner
COPY EDITOR
Caroline Johnson
EDITORIAL MANAGER
Mary Beth Wakefi eld
FREELANCER EDITORIAL MANAGER
Rosemarie Graham
ASSOCIATE DIRECTOR OF MARKETING
David Mayhew
MARKETING MANAGER
Ashley Zurcher
BUSINESS MANAGER
Amy Knies
PRODUCTION MANAGER
Tim Tate

VICE PRESIDENT AND EXECUTIVE GROUP
PUBLISHER
Richard Swadley
VICE PRESIDENT AND EXECUTIVE
PUBLISHER
Neil Edde
ASSOCIATE PUBLISHER
Jim Minatel
PROJECT COORDINATOR, COVER
Katie Crocker
PROOFREADER
Louise Watson, Word One
INDEXER
Ron Strauss
COVER DESIGNER
LeAndra Young
COVER IMAGE
© David Madison / Getty Images
CREDITS
ffirs.indd xiffirs.indd xi 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
ffirs.indd xiiffirs.indd xii 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
ACKNOWLEDGMENTS
THANKS TO FAMILY AND FRIENDS who graciously acted as if

Jon without sleep

is someone you’d
want to spend time with. Thanks to the whole ASP.NET team for making work fun since 2002,
and especially to Brad Wilson and Phil Haack for answering tons of random questions. Thanks to
Warren G. Harding for normalcy. Thanks to Philippians 4:4–9 for continually reminding me which

way is up.
— Jon Galloway
THANKS GO TO MY LOVELY WIFE, Akumi, for her support, which went above and beyond all expec-
tations and made this possible. I’d like to also give a shout out to my son, Cody, for his sage advice,
delivered as only a two-year-old can deliver it. I’m sure he’ll be embarrassed 10 years from now that
I used such an anachronism (

shout out

) in my acknowledgment to him. Thanks go to my daugh-
ter, Mia, as her smile lights up the room like unicorns.
— Phil Haack
ffirs.indd xiiiffirs.indd xiii 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
ffirs.indd xivffirs.indd xiv 9/11/2012 3:00:13 PM9/11/2012 3:00:13 PM
CONTENTS
FOREWORD xxvii
INTRODUCTION xxix
CHAPTER 1: GETTING STARTED 1
A Quick Introduction to ASP.NET MVC 1
How ASP.NET MVC Fits in with ASP.NET 2
The MVC Pattern 2
MVC as Applied to Web Frameworks 3
The Road to MVC 4 3
ASP.NET MVC 1 Overview 4
ASP.NET MVC 2 Overview 4
ASP.NET MVC 3 Overview 5
MVC 4 Overview 10
ASP.NET Web API 10
Enhancements to Default Project Templates 11
Mobile Project Template using jQuery Mobile 13

Display Modes 14
Bundling and Minifi cation 14
Included Open Source Libraries 15
Miscellaneous Features 15
Open Source Release 17
Creating an MVC 4 Application 17
Software Requirements for ASP.NET MVC 4 17
Installing ASP.NET MVC 4 18
Installing the MVC 4 Development Components 18
Installing MVC 4 on a Server 18
Creating an ASP.NET MVC 4 Application 19
The New ASP.NET MVC 4 Dialog 20
Application Templates 20
View Engines 22
Testing 22
The MVC Application Structure 24
ASP.NET MVC and Conventions 27
Convention over Confi guration 28
Conventions Simplify Communication 29
Summary 29
ftoc.indd xvftoc.indd xv 9/11/2012 2:59:44 PM9/11/2012 2:59:44 PM
xvi
CONTENTS
CHAPTER 2: CONTROLLERS 31
The Controller’s Role 31
A Sample Application: The MVC Music Store 34
Controller Basics 36
A Simple Example: The Home Controller 37
Writing Your First Controller 40
Creating the New Controller 40

Writing Your Action Methods 42
A Few Quick Observations 43
Parameters in Controller Actions 43
Summary 46
CHAPTER 3: VIEWS 47
The Purpose of Views 48
Specifying a View 49
ViewData and ViewBag 51
Strongly Typed Views 52
View Models 54
Adding a View 54
Understanding the Add View Dialog Options 55
The Razor View Engine 57
What Is Razor? 57
Code Expressions 59
HTML Encoding 61
Code Blocks 62
Razor Syntax Samples 63
Implicit Code Expression 63
Explicit Code Expression 63
Unencoded Code Expression 64
Code Block 64
Combining Text and Markup 64
Mixing Code and Plain Text 65
Escaping the Code Delimiter 65
Server-Side Comment 65
Calling a Generic Method 66
Layouts 66
ViewStart 69
Specifying a Partial View 69

Summary 70
ftoc.indd xviftoc.indd xvi 9/11/2012 2:59:44 PM9/11/2012 2:59:44 PM
xvii
CONTENTS
CHAPTER 4: MODELS 71
Modeling the Music Store 72
Sca olding a Store Manager 74
What Is Sca olding? 74
Empty Controller 75
Controller with Empty Read/Write Actions 75
API Controller with Empty Read/Write Actions 75
Controller with Read/Write Actions and Views, Using Entity Framework 75
Sca olding and the Entity Framework 76
Code First Conventions 77
The DbContext Class 77
Executing the Sca olding Template 78
The Data Context 79
The StoreManagerController 79
The Views 81
Executing the Sca olded Code 82
Creating Databases with the Entity Framework 82
Using Database Initializers 83
Seeding a Database 84
Editing an Album 86
Building a Resource to Edit an Album 86
Models and View Models Redux 88
The Edit View 88
Responding to the Edit POST Request 89
The Edit Happy Path 90
The Edit Sad Path 90

Model Binding 91
The DefaultModelBinder 91
Explicit Model Binding 92
Summary 94
CHAPTER 5: FORMS AND HTML HELPERS 95
Using Forms 95
The Action and the Method 96
To GET or to POST? 97
Searching for Music with a Search Form 97
Searching for Music by Calculating the Action Attribute Value 99
HTML Helpers 100
Automatic Encoding 100
ftoc.indd xviiftoc.indd xvii 9/11/2012 2:59:45 PM9/11/2012 2:59:45 PM
xviii
CONTENTS
Making Helpers Do Your Bidding 101
Inside HTML Helpers 102
Setting Up the Album Edit Form 102
Html.BeginForm 102
Html.ValidationSummary 103
Adding Inputs 103
Html.TextBox and Html.TextArea 104
Html.Label 105
Html.DropDownList and Html.ListBox 105
Html.ValidationMessage 107
Helpers, Models, and View Data 107
Strongly Typed Helpers 109
Helpers and Model Metadata 110
Templated Helpers 111
Helpers and ModelState 112

Other Input Helpers 112
Html.Hidden 112
Html.Password 112
Html.RadioButton 113
Html.CheckBox 113
Rendering Helpers 113
Html.ActionLink and Html.RouteLink 114
URL Helpers 114
Html.Partial and Html.RenderPartial 115
Html.Action and Html.RenderAction 116
Passing Values to RenderAction 117
Cooperating with the ActionName Attribute 117
Summary 118
CHAPTER 6: DATA ANNOTATIONS AND VALIDATION 119
Annotating Orders for Validation 120
Using Validation Annotations 122
Required 122
StringLength 122
RegularExpression 123
Range 123
Validation Attributes from System.Web.Mvc 124
Custom Error Messages and Localization 125
Looking behind the Annotation Curtain 125
Validation and Model Binding 126
Validation and Model State 126
ftoc.indd xviiiftoc.indd xviii 9/11/2012 2:59:45 PM9/11/2012 2:59:45 PM
xix
CONTENTS
Controller Actions and Validation Errors 127
Custom Validation Logic 128

Custom Annotations 129
IValidatableObject 132
Display and Edit Annotations 133
Display 133
Sca oldColumn 134
DisplayFormat 134
ReadOnly 134
DataType 135
UIHint 135
HiddenInput 135
Summary 135
CHAPTER 7: MEMBERSHIP, AUTHORIZATION, AND SECURITY 137
Using the Authorize Attribute to Require Login 139
Securing Controller Actions 140
How the AuthorizeAttribute Works with Forms Authentication
and the AccountController 143
Windows Authentication in the Intranet Application Template 145
Securing Entire Controllers 146
Securing Your Entire Application Using a Global Authorization Filter 147
Using the Authorize Attribute to Require Role Membership 148
Extending Roles and Membership 149
External Login via OAuth and OpenID 150
Registering External Login Providers 150
Confi guring OpenID Providers 152
Confi guring OAuth Providers 155
Security Implications of External Logins 155
Trusted External Login Providers 155
Require SSL for Login 156
Understanding the Security Vectors in a Web Application 157
Threat: Cross-Site Scripting 157

Threat Summary 157
Passive Injection 157
Active Injection 160
Preventing XSS 162
Threat: Cross-Site Request Forgery 167
Threat Summary 167
Preventing CSRF Attacks 169
Threat: Cookie Stealing 171
ftoc.indd xixftoc.indd xix 9/11/2012 2:59:45 PM9/11/2012 2:59:45 PM
xx
CONTENTS
Threat Summary 171
Preventing Cookie Theft with HttpOnly 172
Threat: Over-Posting 172
Threat Summary 173
Preventing Over-Posting with the Bind Attribute 174
Threat: Open Redirection 175
Threat Summary 175
Protecting Your ASP.NET MVC 1 and MVC 2 Applications 179
Taking Additional Actions When an Open Redirect Attempt Is Detected 182
Open Redirection Summary 183
Proper Error Reporting and the Stack Trace 183
Using Confi guration Transforms 184
Using Retail Deployment Confi guration in Production 185
Using a Dedicated Error Logging System 185
Security Recap and Helpful Resources 185
Summary 187
CHAPTER 8: AJAX 189
jQuery 190
jQuery Features 190

The jQuery Function 190
jQuery Selectors 192
jQuery Events 192
jQuery and Ajax 193
Unobtrusive JavaScript 193
Using jQuery 194
Custom Scripts 195
Placing Scripts in Sections 195
The Rest of the Scripts 196
Ajax Helpers 196
Ajax ActionLinks 197
HTML 5 Attributes 199
Ajax Forms 200
Client Validation 202
jQuery Validation 202
Custom Validation 203
IClientValidatable 204
Custom Validation Script Code 205
Beyond Helpers 207
jQuery UI 208
Autocomplete with jQuery UI 209
ftoc.indd xxftoc.indd xx 9/11/2012 2:59:45 PM9/11/2012 2:59:45 PM
xxi
CONTENTS
Adding the Behavior 210
Building the Data Source 210
JSON and Client-Side Templates 212
Adding Templates 212
Modifying the Search Form 213
Getting JSON 214

jQuery.ajax for Maximum Flexibility 216
Improving Ajax Performance 217
Using Content Delivery Networks 217
Script Optimizations 217
Bundling and Minifi cation 218
Summary 219
CHAPTER 9: ROUTING 221
Uniform Resource Locators 222
Introduction to Routing 223
Comparing Routing to URL Rewriting 223
Defi ning Routes 224
Route URLs 224
Route Values 226
Route Defaults 227
Route Constraints 230
Named Routes 231
MVC Areas 233
Area Route Registration 233
Area Route Confl icts 234
Catch-All Parameter 234
Multiple URL Parameters in a Segment 235
StopRoutingHandler and IgnoreRoute 236
Debugging Routes 237
Under the Hood: How Routes Generate URLs 239
High-Level View of URL Generation 239
A Detailed Look at URL Generation 240
Ambient Route Values 242
Overfl ow Parameters 244
More Examples of URL Generation with the Route Class 244
Under the Hood: How Routes Tie Your URL to an Action 245

The High-Level Request Routing Pipeline 246
RouteData 246
Custom Route Constraints 246
Using Routing with Web Forms 247
Summary 248
ftoc.indd xxiftoc.indd xxi 9/11/2012 2:59:45 PM9/11/2012 2:59:45 PM
xxii
CONTENTS
CHAPTER 10: NUGET 249
Introduction to NuGet 249
Installing NuGet 250
Adding a Library as a Package 252
Finding Packages 252
Installing a Package 254
Updating a Package 256
Recent Packages 257
Package Restore 257
Using the Package Manager Console 259
Creating Packages 262
Packaging a Project 262
Packaging a Folder 263
NuSpec File 263
Metadata 264
Dependencies 266
Specifying Files to Include 267
Tools 268
Framework and Profi le Targeting 271
Prerelease Packages 272
Publishing Packages 272
Publishing to NuGet.org 273

Using NuGet.exe 274
Using the Package Explorer 275
Summary 278
CHAPTER 11: ASP.NET WEB API 279
Defi ning ASP.NET Web API 280
Getting Started with Web API 280
Writing an API Controller 281
Examining the Sample ValuesController 282
Async by Design: IHttpController 283
Incoming Action Parameters 284
Action Return Values, Errors, and Asynchrony 284
Confi guring Web API 285
Confi guration in Web-Hosted Web API 286
Confi guration in Self-Hosted Web API 286
Confi guration in Third-Party Hosts 287
Adding Routes to Your Web API 287
Binding Parameters 288
ftoc.indd xxiiftoc.indd xxii 9/11/2012 2:59:45 PM9/11/2012 2:59:45 PM
xxiii
CONTENTS
Filtering Requests 290
Enabling Dependency Injection 291
Exploring APIs Programmatically 292
Tracing the Application 293
Web API Example: ProductsController 293
Summary 296
CHAPTER 12: DEPENDENCY INJECTION 297
Software Design Patterns 297
Design Pattern: Inversion of Control 298
Design Pattern: Service Locator 300

Strongly Typed Service Locator 300
Weakly Typed Service Locator 301
The Pros and Cons of Service Locators 304
Design Pattern: Dependency Injection 304
Constructor Injection 304
Property Injection 305
Dependency Injection Containers 306
Dependency Resolution in MVC 307
Singly Registered Services in MVC 308
Multiply Registered Services in MVC 309
Arbitrary Objects in MVC 311
Creating Controllers 311
Creating Views 312
Dependency Resolution in Web API 313
Singly Registered Services in Web API 314
Multiply Registered Services in Web API 315
Arbitrary Objects in Web API 316
Dependency Resolvers in MVC vs. Web API 316
Summary 316
CHAPTER 13: UNIT TESTING 317
The Meaning of Unit Testing and Test-Driven Development 318
Defi ning Unit Testing 318
Testing Small Pieces of Code 318
Testing in Isolation 318
Testing Only Public Endpoints 319
Automated Results 319
Unit Testing as a Quality Activity 319
Defi ning Test-Driven Development 320
The Red/Green Cycle 320
ftoc.indd xxiiiftoc.indd xxiii 9/11/2012 2:59:45 PM9/11/2012 2:59:45 PM

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×