Index

Symbols

^= operator, 487

=> (goes to) operator, 655

A

About() method, 20-21

AcceptAjax attribute, 473-476

AcceptVerbs attribute (actions), 65-69

access, testing

with fake generic repository, 155-157

with mock repository, 150-155

overview, 149-150

Account controller, users and roles, 367-369

action filters

definition of, 207

FeaturedProductActionFilter, 316-318

log action filter, 237-240

overview, 236

Action() HTML helper, 161-162

ActionLink() HTML helper, 160-161

ActionMethodSelector attribute (actions), 72-75

ActionName attribute (actions), 70-71

ActionResults, returning

ContentResult, 57-59

FileResult, 63-65

JsonResult, 59-62

overview, 51-52

RedirectResult, 55-57

types of ActionResults, 51-52

ViewResult, 52-55

actions

AcceptVerbs attribute, 65-69

action filters

definition of, 207

FeaturedProductActionFilter, 316-318

log action filter, 237-240

overview, 236

ActionMethodSelector attribute, 72-75

ActionName attribute, 70-71

ActionResults, returning

overview, 51-52

types of ActionResults, 51-52

invoking, 51

testing, 78-81

unknown actions, handling, 76-78

Add Controller dialog, 47-48

Add menu commands

Controller, 47

New Item, 26

New Test, 661

Add New Item dialog, 26

Add New Test dialog, 514, 660-661

Add Reference command (Project menu), 274

Add Reference dialog box, 274

Add View dialog, 37-45, 84, 83

AddAttribute() method, 180

AddCssClass() method, 176

AddModelError() method, 244

AddStyleAttribute() method, 180

ADO.NET Entity Designer, 123

Agile Principles, Patterns, and Practices in C# (Martin and Martin), 10

Ajax

AcceptAjax attribute, 473-476

AjaxOptions class

LoadingElementId property, 436

OnBegin property, 439

OnComplete property, 439

debugging routes, 428-429

helpers, 462

Ajax.ActionLink() helper, 454, 462, 468. See also asynchronous content retrieval

Ajax.BeginForm() helper, 430. See also posting forms asynchronously

Ajax.BlogPager() helper, 618-619

required libraries, 427-428

and jQuery, 491-498

MicrosoftAjax.js library, including in pages, 427-428

MicrosoftMvcAjax.js library, including, 427-428

overview, 426-427

posting forms asynchronously

displaying progress, 435-442

downlevel browser support, 452-455

sample application, 430-435

updating content after posting, 443-447

validation, 447-452

retrieving content asynchronously

creating delete links, 462-467

downlevel browser support, 468-473

highlighting selected link, 459-462

sample application, 454-459

supporting in UnleashedBlog application

Ajax.BlogPager() helper, 618-619

BlogEntries partial, 616-617

Index_Ajax() method, 614-615

Index_AjaxReturnsPartialViewResult() method, 614

modified Index view, 615-616

overview, 612-613

ajax() method, 491

Ajax.ActionLink() helper, 454, 462, 468. See also asynchronous content retrieval

Ajax.BeginForm() helper, 430. See also posting forms asynchronously

AjaxMethodAttribute class, 72

AjaxOptions class

LoadingElementId property, 436

OnBegin property, 439

OnComplete property, 439

ajaxSetup() method, 496

alternative view engines

Brail, 98

custom view engine

creating, 99-104

testing, 114-117

NHaml, 98

nVelocity, 98

overview, 97-98

Spark, 98

animations

displaying as progress indicators, 439-442

jQuery animations, 489-491

anonymous types, 649-651

antiforgery tokens, 169-173

AntiForgeryToken() HTML helper, 169-173

App_Data folder, 19

Application_Start() method, 271

ApplicationController class, 308-309

ApplicationName setting, 378

applications

architecture, 16-17

bin deployment, 424-425

blog. See UnleashedBlog application

MyFirstMvcApp sample application

code listings, 20-22

creating, 17-18

folder conventions, 19--19

running, 19-20

Toy Store. See Toy Store application

architecture of ASP.NET MVC applications, 16-17

ArchiveController class, 549-552

ArchiveControllerTests class, 544-549, 572-573

ArchiveYear test, 559

ArchiveYearMonth test, 559

ArchiveYearMonthDay test, 559

ArchiveYearMonthDayName() method, 559, 641-642

AreEqual() method, 669-670

AreEquivalent() method, 669

ASP.NET MVC 1.0, 1

ASP.NET Unleashed (Walther), 15

ASP.NET Web Forms,

combining with ASP.NET MVC, 424

modifying to support ASP.NET MVC

Global.asax file, 422-424

overview, 414

required assemblies, 415-416

Visual Studio project files, 415

web configuration files, 416-422

assemblies

adding, 415-416

System.Web.Abstractions, 415

System.Web.Mvc, 415

System.Web.Routing assembly, 415

Assert class, 669

assertions, 669-672

asynchronous content retrieval

creating delete links, 462-467

downlevel browser support, 468-473

highlighting selected link, 459-462

sample application, 454-459

Asynchronous JavaScript and XML. See Ajax

asynchronous posting of forms

displaying progress, 435-442

downlevel browser support, 452-455

sample application, 430-435

updating content after posting, 443-447

validation, 447-452

attacks

CSRF (cross-site request forgery) attacks, 169

JavaScript injection attacks, 95-97

Attributes property (TagBuilder class), 176

AuthenticatedConstraint, 280-283

authentication

authorizing users

with Authorize attribute, 368-370

authorizing particular roles, 371-372

authorizing particular users, 370-371

overview, 368

with User property, 372-374

membership, configuring

with Membership and Role Manager API, 381-385

membership database, 375-379

membership settings, 378-380

overview, 363-365

testing

for Authorize attribute, 390-392

with user model binder, 393-400

users and roles, creating

with Account controller, 367-369

with Web Site Administration Tool, 365-366

Windows authentication

authenticating Windows users and groups, 386-390

configuring, 385-387

overview, 385

types of authentication, 386

AuthenticationType property (Identify object), 373

Authorize attribute, 368-370

testing for, 390-392

authorizing users

with Authorize attribute, 368-370

authorizing particular roles, 371-372

authorizing particular users, 370-371

overview, 368

with User property, 372-374

avoiding code smells, 9-10

B

Basic authentication, 386

Beck, Kent, 509

BeginForm() HTML helper, 162, 166-167

bin deployment, 424-425

Bind attribute (model binders)

applying to classes, 221-225

applying to method parameters, 218-221

prefixes, 225-228

binding to complex classes, 212-218

blog application. See UnleashedBlog application

blog entries, creating, 520-523

BlogArchive route, 276

BlogController class

BlogArchive route, 277

_blogEntries field, 522-523

BlogRepositoryBase class. See BlogRepositoryBase class

BlogService. See BlogService class

CreateNameFromTitle() method, 589-590

creating, 517-518

Entity Framework blog repository, 537-539

ignoring Id property, 580-581

Index_Ajax() method, 614-615

paging support, 597-601

validating blog entry title, 570-571

validating length of property, 577-578

BlogControllerTests class

CreateBlogEntry() method, 520-521

CreateNameIsValid() method, 587

CreateTitleMaximumLength500() method, 576-577

CreateTitleRequired() method, 568-569

FakeBlogRepository(), 528-530

Index_AjaxReturnsPartialViewResult() method, 614

IndexReturnsBlogEntriesByYear() test, 575

paging tests, 596-600

ShowNewBlogEntries() method, 515-516

_blogEntries field, 588-589

BlogEntries partial, 607-608, 616-617

BlogEntriesIncludeCommentCount() method, 631-632

BlogEntry class, 517

BlogEntryEntity class, 536-537

BlogEntryFactory class, 573-576

BlogLink() HTML helper, 608-609

BlogLinkHelper class, 608-609

BlogPager() Ajax helper, 618-619

BlogPager() HTML helper, 610-612

BlogPagerHelper class, 610-612

BlogRepositoryBase class

first iteration, 524-525

ListBlogEntries() method, 552-553

paging support, 602-605

BlogService class

blog entry Name property, 588-589

initial code listing, 581-583

ListBlogEntries() method, 601-603

Brail, 98

browsers, downlevel browser support

posting forms asynchronously, 452-455

retrieving content asynchronously, 468-473

BulletedListHelper class, 180-182

business rules in UnleashedBlog application, 586-591

C

C# language features

anonymous types, 649-651

extension methods, 652-654

generics, 654-655

lambda expressions, 655

LINQ (Language Integrated Query), 656-658

nullable types, 651-652

object initializers, 648

type inference, 647-648

Cache class, 347-353

Cache-Control HTTP header, 345

CacheControlController class, 345-346

CacheWrapper class, 360

caching, 333-335

with Cache class, 347-353

with HttpCachePolicy class, 345-346

with OutputCache attribute, 330-331

cache location, setting, 333-335

cache profiles, 343-344

Location property, 333-335

removing items from output cache, 341-343

sample application, 325-330

security issues, 330-331

VaryByContentEncoding property, 337

VaryByCustom property, 338-341

VaryByHeader property, 337-338

VaryByParam property, 335-337

varying output cache, 335-341

what gets cached, 331-333

overview, 323-325

sliding expiration cache policy, 351-352

testing cache

OutputCache attribute, 353-355

overview, 353

verifying that database data is cached, 355-362

call manager application case study, 7-8

Cascading Style Sheets (CSS), error message styles, 247-248

CatalogController class, 77-78

catch-all parameter (routes), 285-288

Certification authentication, 386

ChangePassword() method, 367

ChangePasswordSuccess() method, 367

changing passwords, 368-369

CheckBox() HTML helper, 162-165

classes, 325-330

AjaxMethodAttribute, 72

AjaxOptions

LoadingElementId property, 436

OnBegin property, 439

OnComplete property, 439

ApplicationController, 308-309

ArchiveController, 549-552

ArchiveControllerTests, 544-549, 572-573

Assert, 669

binding to complex classes, 212-218

BlogController

BlogArchive route, 277

_blogEntries field, 522-523

BlogRepositoryBase class. See BlogRepositoryBase class

BlogService. See BlogService class

CreateNameFromTitle() method, 589-590

creating, 517-518

Entity Framework blog repository, 537-539

ignoring Id property, 580-581

Index_Ajax() method, 614-615

paging support, 597-601

validating blog entry title, 570-571

validating length of property, 577-578

BlogControllerTests

CreateBlogEntry() method, 520-521

CreateNameIsValid() method, 587

CreateTitleMaximumLength500() method, 576-577

CreateTitleRequired() method, 568-569

FakeBlogRepository(), 528-530

Index_AjaxReturnsPartialViewResult() method, 614

IndexReturnsBlogEntriesByYear() test, 575

paging tests, 596-600

ShowNewBlogEntries() method, 515-516

BlogEntry, 517

BlogEntryEntity, 536-537

BlogEntryFactory, 573-576

BlogLinkHelper, 608-609

BlogPagerHelper, 610-612

BlogRepositoryBase, 602-605

first iteration, 524-525

ListBlogEntries() method, 552-553

BlogService

blog entry Name property, 588-589

initial code listing, 581-583

ListBlogEntries() method, 601-603

BulletedListHelper, 180-182

Cache, 347-353

CacheControlController, 345-346

CacheWrapper, 360

CatalogController, 77-78

CollectionAssert, 669

Comment, 624-625

CommentController, 625-626

CommentControllerTests

BlogEntriesIncludeCommentCount() method, 631-632

CommentsOrderByDatePublished() method, 629-630

CreateAndThenGetComment() method, 627-629

CreateComment() method, 622-623

CompanyController, 369-372

ContentManagerController, 63-64

Controller, 372-374

controller classes, creating, 681-682

creating from interfaces, 681-690

Customer, binding to, 213-218

CustomerController, 53-54

data model classes. See data models

DataGridHelperBasic, 183-187

DataGridHelperTests, 201-205

DeleteController, 463-465

DownlevelController, 453-454

DownLinkController, 468-471

DynamicController, 302-303

EmployeeController, 65-67

EntityFrameworkBlogRepository, 534-537, 634-636

Enumerable, 656

FakeBlogRepository, 526-528, 632-633

FakeClass, 360

FakeIdentity, 398-400

FakeMovieRepository, 267

FakePrincipal, 396-398

generics, 654-655

GuestBookController, 446-447

HelloController, 58

HomeController, 20-21

caching, 325-330

creating, 30-37

HomeController class listing in C#, 31-32, 34-35

HomeController class listing in VB, 32-34, 35-36

testing, 106-108

HomeControllerTest, 106-108

HomeControllerTestFake, 155-157

HomeControllerTestMock, 153-155

HTMLTextWriter, 180-183

HttpCachePolicy, 345-346

ImageLinkHelper, 177-180

JackController, 391

JackControllerTests, 391-392

JillController, 393-394

JillControllerTests, 394-396

LogActionFilter, 237-239

LogController, 239-240

LookupController, 382-383

MasterDetailController, 457-458

MathUtility, 666

MathUtilityTests, 666-668

Membership, 381-385

MembershipUser, 381-385

MerchandiseController, 70-71

Movie2Controller, 252-253

Movie2ControllerTests, 264-266

MovieController, 684-686

model state, 242-244

posting forms asynchronously, 430-435

retrieving movies, 496-498

MovieRepository, 257-258, 347-349, 686-687

MovieService, 254-256, 684-686

MovieServiceTests, 688-689

NewsController, 73-74, 493-494

PagedList, 193-195

PageList, 594-596

PagingLinqExtensions, 195-197

PersonController, 78-81

Product, 261-263

ProductController, 48-51, 259-261, 318-319

ProductControllerTests

C# code listing, 661-663

VB code listing, 663-664

ProductHelper, 110-112

ProductHelperTest, 112-114

ProductRepository, 133-136

ProfileController, 344

Queryable, 656-657

QuotationController, 59-60

RemoveController, 342-343

Repository, 148-149

Roles, 382

RouteTest, 293-294, 289-290

RouteTests, 554-558, 641-642

SelectorController, 457-476

ServerValidateController, 450-451

SimpleControllerTest, 114-116

SimpleMovieController, 358-359

SimpleMovieRepository, 356

SimpleMovieService, 356-358

SimpleView, 100-103

SimpleViewEngine, 99-104

SlidingController, 351-352

SortController, 288

StringAssert, 669

TagBuilder, 176-180

TheaterController, 319-320

UserController, 373-374

UserModelBinder, 233-236

VaryCustomController, 340

ViewDataDictionary, 91

VirtualPathProviderViewEngine, 99

WidgetController, 55-56

WindowsController, 387-390

classic mode (IIS), 402-403

code samples, downloading, 3

code smells, avoiding, 9-10

CollectionAssert class, 669

commands. See specific commands

Comment class, 624-625

CommentController class, 625-626

CommentControllerTests class

BlogEntriesIncludeCommentCount() method, 631-632

CommentsOrderByDatePublished() method, 629-630

CreateAndThenGetComment() method, 627-629

CreateComment() method, 622-623

comments, adding to blog application

adding comments to database, 633-637

BlogEntriesIncludeCommentCount() method, 631-632

Comment class, 624-625

CommentsOrderByDatePublished() method, 629-630

CreateAndThenGetComment() method, 627-629

CreateComment() method, 622-623, 627-628

displaying comments and comment counts, 637-643

modified FakeBlogRepository class, 632-633

overview, 619-622

Comments database table, adding comments to, 633-637

CommentsOrderByDatePublished() method, 629-630

CompanyController class, 369-372

complexity in software, 10

configuring

ASP.NET Web Forms to support ASP.NET MVC

Global.asax file, 422-424

overview, 414

required assemblies, 415-416

Visual Studio project files, 415

web configuration files, 416-422

default routes, 272-273

IIS (Internet Information Services)

hosted server, 408-410

integrated versus classic mode, 402-403

overview, 401-402

route table, adding extensions to, 403-408

wildcard script maps, 410-414

membership

with Membership and Role Manager API, 381-385

membership database, 375-379

membership settings, 378-380

Windows authentication, 385-387

CONNECT operation (HTTP), 68, 462

constraints

route constraints, creating

AuthenticatedConstraint, 280-283

HttpMethod constraint, 280-281

NotEqual constraint, 283-285

regular expression constraints, 278-279

testing routes with, 292-294

Contains() method, 669

Content folder, 19

Content() method, overloading, 59

ContentManagerController class, 63-64

ContentResult, 52

returning, 57-59

Controller class, 372-374

Controller command (Add menu), 47

controllers, 16

ActionResults, returning

ContentResult, 57-59

FileResult, 63-65

JsonResult, 59-62

overview, 51-52

RedirectResult, 55-57

types of ActionResults, 51-52

ViewResult, 52-55

actions

AcceptVerbs attribute, 65-69

ActionMethodSelector attribute, 72-75

ActionName attribute, 70-71

invoking, 51

testing, 78-81

unknown actions, handling, 76-78

ApplicationController class, 308-309

ArchiveController class, 549-552

BlogController class

BlogArchive route, 277

_blogEntries field, 522-523

BlogRepositoryBase class. See BlogRepositoryBase class

BlogService. See BlogService class

CreateNameFromTitle() method, 589-590

Entity Framework blog repository, 537-539

ignoring Id property, 580-581

Index_Ajax() method, 614-615

paging support, 597-601

validating blog entry title, 570-571

validating length of property, 577-578

CacheControlController class, 345-346

CatalogController class, 77-78

CommentController class, 625-626

CompanyController class, 369-372

ContentManagerController class, 63-64

Controller class, 372-374

creating, 47-51, 681-684

CustomerController class, 53-54

DeleteController class, 463-465

DownlevelController class, 453-454

DownLinkController class, 468-471

DynamicController class, 302-303

EmployeeController class, 65-67

GuestBookController class, 446-447

HelloController class, 58

HomeController class, 20-21

caching, 325-330

creating, 30-37

HomeController class listing in C#, 31-32, 34-35

HomeController class listing in VB, 32-34, 35-36

testing, 106-108

JackController class, 391

JillController class, 393-394

LookupController class, 382-383

MasterDetailController class, 457-458

MerchandiseController class, 70-71

Movie2Controller class, 252-253

MovieController class, 684-686

model state, 242-244

posting forms asynchronously, 430-435

retrieving movies, 496-498

NewsController class, 73-74, 493-494

overview, 46-47

PersonController class, 78-81

ProductController class, 259-261, 318-319

ProfileController class, 344

QuotationController class, 59-60

RemoveController class, 342-343

SelectorController class, 457-476

ServerValidateController class, 450-451

setting view master pages from, 302-304

SimpleMovieController class, 358-359

SlidingController class, 351-352

SortController class, 288

TheaterController class, 319-320

UserController class, 373-374

VaryCustomController class, 340

WidgetController class, 55-56

WindowsController class, 387-390

Controllers folder, 19

controls. See user controls

ConvertCommentToCommentEntity() method, 637

Create() method, 65

creating records, 127-128

HomeController class, 34-37

UnleashedBlog application, 521-522

Create Unit Test Project dialog, 24, 513, 511, 660

Create view

Ajax posts, 432-435

for Toy Store application, 42-45

CreateAndThenGetComment() method, 627-629

createBeing() method, 442

CreateBlogEntry() method, 520-523, 536, 588-591, 627-628

CreateComment() method, 622-623, 627-628

createComplete() method, 442

CreateItems() method, 205

CreateMovie() method, 349

fake values, returning, 690-693

CreateNameFromTitle() method, 589-590

CreateNameIsValid() method, 587

createSuccess() method, 435

CreateTitleMaximumLength500() method, 576-577

CreateTitleRequired() method, 568-569

CreateWithBadMovieReturnsView() method, 693

CreateWithGoodMovieReturnsRedirect() method, 693

cross-site scripting (XSS) attacks, 96

CSRF (cross-site request forgery) attacks, 169

CSS (Cascading Style Sheets), error message styles, 247-248

custom HTML helpers, creating

HTML.DataGrid() helper, 183-201

C# code listing, 183-185

calling, 187-188

paging support, 192-201

reflection, 188-189

sorting suport, 190-192

testing, 201-205

VB code listing, 186-187

HTML.SubmitButton() example, 173-176

with HTMLTextWriter class, 180-183

with TagBuilder class, 176-180

custom model binders, creating, 233-236

custom routes, creating, 275-277

custom view engine

creating, 99-104

testing, 114-117

Customer class, binding to, 213-218

CustomerController class, 53-54

D

data access, testing

with fake generic repository, 155-157

with mock repository, 150-155

overview, 149-150

data models

creating with Microsoft Entity Framework, 120-124

data access, testing

with fake generic repository, 155-157

with mock repository, 150-155

overview, 149-150

for Entity Framework blog repository, 532-533

overview, 117-119

records

creating, 127-128

deleting, 131-132

editing, 128-130

listing, 124-126

retrieving single record, 126

Repository pattern

Dependency Injection pattern, 138-139

generic repositories, 139-149

overview, 132

product repositories, 133-138

for Toy Store application, 27-30

databases

adding comments to, 633-637

database objects for Entity Framework blog repository, 531-532

membership database, configuring, 375-379

Toy Store database, creating, 23-27

DataGrid() HTML helper, 183-201

C# code listing, 183-185

calling, 187-188

paging support, 192-201

PagedList class, 193-195

PagedSortedProducts() action, 200-201

PagingLinqExtensions class, 195-197

reflection, 188-189

sorting support, 190-192

testing, 201-205

VB code listing, 186-187

DataGridHelperBasic class, 183-187

DataGridHelperTests class, 201-205

dateReleased variable, 651

debugging

Ajax, 428-429

routes, 274-275

default model binder

binding to complex classes, 212-218

overview, 210-212

default routes

configuring, 272-273

Global.asax file, 269-271

DefaultRoute test, 559

DefaultRouteMatchesHome() method, 289-290

delete links, creating, 462-467

Delete() method, 131-132

DELETE operation (HTTP), 68-69, 462

Delete_GET() action, 465

Delete_POST() action, 465

DeleteController class, 463-465

deleting records, 131-132

Dependency Injection pattern, 138-139

deployment, bin, 424-425

Description setting, 378

design (software)

design patterns, 11-12

design principles, 10-11

short-term versus long-term planning, 14

test-driven development, 13

unit tests, 12-13

Design Patterns: Elements of Reusable Object-Oriented Software, 11

Details() method, 34

retrieving single record, 126

Details view for UnleashedBlog application, 637-641

DetailsWithId() method, 80-81

DetailsWithoutId() method, 80-81

development, test-driven. See test-driven development

dialogs. See specific dialogs

Digest authentication, 386

disabling request validation, 97

divLoading element, 436

Domain-Driven Design (Evans), 11

doubles, 680

downlevel browser support

asynchronous content retrieval, 468-473

posting forms asynchronously, 452-455

DownlevelController class, 453-454

DownLinkController class, 468-471

downloading

code samples, 3

jQuery plug-ins, 498-499

NUnit, 672

drop-down lists, rendering, 167-168

DropDownList() HTML helper, 162, 167-168

DynamicController class, 302-303

E

Edit() method, 34

editing records, 128-130

EFGenericRepository project, 140

EFMvcApplication project, 142-144

embedding scripts in views, 86-87

EmployeeController class, 65-67

EmptyResult, 52

EnablePasswordReset setting, 379

EnablePasswordRetrieval setting, 379

Encode() HTML helper, 169

encoding HTML content, 169

EndForm() HTML helper, 162, 166-167

Entity Data Model Wizard, 28-30

Entity Framework. See Microsoft Entity Framework

EntityFrameworkBlogRepository class, 534-537, 634-636

Enumerable class, 656

error messages

Sys Is Undefined error, 428

Type Is Undefined error, 428

validation error messages

prebinding versus postbinding, 248-250

styling, 247-248

in UnleashedBlog application, 578-581

ETag HTTP header, 345

Evans, Eric, 11-12

event handlers in jQuery, 487-488. See also specific event handlers

evolutionary design, 507-508

Exclude property (Bind attribute), 218

Expires HTTP header, 345

expressions, lambda, 655

extending generic repositories, 147-149

extension methods, 652-654

extensions, adding to route table, 403-408

F

Factoring: Improving the Design of Existing Code (Fowler), 506

fake repositories

testing data access with, 155-157

for UnleashedBlog application, 526-530, 632-633

fake values, returning, 690-693

FakeBlogRepository class, 526-528, 632-633

FakeCache class, 360

FakeIdentity class, 398-400

FakeMovieRepository class, 267

FakePrincipal class, 396-398

fakes, definition of, 680

Feathers, Michael, 9, 12,

FeaturedProductActionFilter, 316-318

Fiddler, 428-429

File menu commands, New Project, 23

File() method, overloading, 64

FileResult, 52, 63-65

files. See specific files

filters. See action filters

Firebug, 429

folders, conventions for, 19

form collection model binder, 228-231

form validation. See validation

forms

form elements, rendering, 162-165

posting asynchronously

displaying progress, 435-442

downlevel browser support, 452-455

sample application, 430-435

updating content after posting, 443-447

validation, 447-452

rendering, 166-167

validating. See validation

Fowler, Martin, 11, 506, 680

fragility in software, 10

G

GenerateId() method, 176

generic repositories

creating, 139-141

extending, 147-149

with LINQ to SQL, 144-147

with Microsoft Entity Framework, 141-144

testing data access with fake generic repositories, 155-157

GenericRepository project, 140

GenericRepository.Tests project, 140

generics, 654-655

get() method, 491

GET operation (HTTP), 67, 462

getJSON() method, 491, 494

GetProductCount() method, 148

GetRandomProducts() method, 318

getScript() method, 491

GetWithDatePublished() method, 574, 573

Global.asax file, 269-271

adding routes to, 561-563, 642

configuring ASP.NET Web Forms files to support ASP.NET MVC, 422-424

hosted server configuration, 408-410

registering custom view engines in, 103

route table, adding extensions to, 403-408

wildcard script maps, 412-413

goes to (=>) operator, 655

guestbook application

updating content after posting, 443-447

validation, 447-452

GuestBookController class, 446-447

Guthrie, Scott, 16

H

HandleUnknownAction() method, 76-78

HasErrorMessage() method, 569

Head First Design Patterns, 11

HEAD operation (HTTP), 67, 462

headers (HTTP), 345

HelloController class, 58

helpers, Ajax

Ajax.ActionLink() helper, 454-457, 462. See also asynchronous content retrieval

Ajax.BeginForm() helper, 430. See also posting forms asynchronously

Ajax.BlogPager() helper, 618-619

required libraries, 427-428

helpers, HTML. See HTML helpers

Heraclitus, 7

Hidden() HTML helper, 162-165

highlighting selected links, 459-462

HomeController class, 20-21

caching, 325-330

creating, 30-37

HomeController class listing in C#, 31-32, 34-35

HomeController class listing in VB, 32-34, 35-36

testing, 106-108

HomeControllerTest class, 106-108

HomeControllerTestFake class, 155-157

HomeControllerTestMock class, 153-155

host servers, 408-410

hover() method, 487-488

HTML content, encoding, 169

HTML helpers

custom HTML helpers, creating

HTML.ImageLink() example, 177-180

HTML.SubmitButton() example, 173-176

with HTMLTextWriter class, 180-183

with TagBuilder class, 176-180

HTML.ActionLink() helper, 160-161

HTML.AntiForgeryToken() helper, 169-173

HTML.BeginForm() helper, 162, 166-167

Html.BlogLink() helper, 608-609

Html.BlogPager() helper, 610-612

HTML.CheckBox() helper, 162-165

HTML.DataGrid() helper. See HTML.DataGrid() helper

HTML.DropDownList() helper, 162, 167-168

HTML.Encode() helper, 169

HTML.EndForm() helper, 162, 166-167

HTML.Hidden() helper, 162-165

HTML.ListBox() helper, 162-165

HTML.Password() helper, 162-165

HTML.RadioButton() helper, 162-165

HTML.TextArea() helper, 162-165

HTML.TextBox() helper, 162-165

overview, 157-160

testing, 108-114, 201-205

URL.Action() helper, 161-162

HTML links

creating delete links, 462-467

highlighting selected link, 459-462

image links, rendering, 161-162

rendering, 160-161

HTML.ActionLink() helper, 160-161

HTML.AntiForgeryToken() helper, 169-173

HTML.BeginForm() helper, 162, 166-167

Html.BlogLink() helper, 608-609

Html.BlogPager() helper, 610-612

HTML.CheckBox() helper, 162-165

HTML.DataGrid() helper, 183-201

C# code listing, 183-185

calling, 187-188

paging support, 192-201

PagedList class, 193-195

PagedSortedProducts() action, 200-201

PagingLinqExtensions class, 195-197

reflection, 188-189

sorting support, 190-192

testing, 201-205

VB code listing, 186-187

HTML.DropDownList() helper, 162, 167-168

HTML.Encode() helper, 169

HTML.EndForm() helper, 162, 166-167

HTML.Hidden() helper, 162-165

HTML.ImageLink() helper, 177-180

HTML.ListBox() helper, 162-165

HTML.Password() helper, 162-165

HTML.RadioButton() helper, 162-165

HTML.SubmitButton() helper, 173-176

HTML.TextArea() helper, 162-165

HTML.TextBox() helper, 162-165

HTMLTextWriter class, 180-183

Html.ValidationMessage() helper, 245-247

Html.ValidationSummary() helper, 245-247

HTTP

headers, 345

HTTP posted file base model binder, 231-233

operations, 67-68, 462

HttpCachePolicy class, 345-346

HttpMethod constraint, 280-281

HttpUnauthorizedResult, 52

I

ICache interface, 359

IDataErrorInfo interface, validating form data with, 258-263

IdAttributeDotReplacement property (TagBuilder class), 176

Identity object, 373

IEnumerable interface, 91, 656

IGenericRepository interface, 140

IIS (Internet Information Services) configuration

hosted server, 408-410

integrated versus classic mode, 402-403

overview, 401-402

route table, adding extensions to, 403-408

wildcard script maps, 410-414

image links, rendering, 161-162

ImageLink() HTML helper, 177-180

ImageLinkHelper class, 177-180

importing namespaces

overview, 519

UnitTesting namespace, 665

Include property (Bind attribute), 218

including libraries. See libraries

Index() method, 20-21, 34-37, 49

listing records, 124-126

UnleashedBlog application, 519-520

Index view

MyFirstMvcApp sample application, 21-22

for Toy Store application, 37-42, 37-45, 39-42

for UnleashedBlog application, 605-611, 615-616

Index_Ajax() method, 614-615

Index_AjaxReturnsPartialViewResult() method, 614

IndexAcceptsPage() method, 597-600

IndexAddsMoviesToCache() method, 360-362

IndexedCached() method, 325

IndexRetrievesMoviesFromCache() method, 360-362

IndexReturnsBlogEntriesByYear() test, 571, 575

IndexReturnsBlogEntriesInOrderOfDatePublished() method, 597-600

IndexReturnsLessThan6BlogEntries() method, 597-600

IndexReturnsPagedListForPage() method, 597-600

initializers (object), 648

injection attacks, preventing, 95-97

InnerHTML property (TagBuilder class), 176

installing

Moq, 680-681

NUnit, 673

integrated mode (IIS), 402-403

Integrated Windows authentication, 386

Intellisense (Visual Studio) and jQuery, 481-482

interfaces

creating classes from, 681-690

generics, 654-655

ICache, 359

IDataErrorInfo, validating form data with, 258-263

IEnumerable, 91, 656

IGenericRepository, 140

IProductRepository, 133

IQueryable, 657

IRepository, 147-148

Internet Information Services. See IIS (Internet Information Services) configuration

invoking

Archive controller, 564-565

controller actions, 51

IProductRepository interface, 133

IQueryable interface, 657

IRepository interface, 147-148

Is Design Dead? (Fowler), 509

IsAjaxRequest() method, 454

IsAuthenticated property (Identity object), 373

IsInRole() method, 373

IsInstanceOfType() method, 669

J-K

JackCanAccessIndex() method, 391-392

JackCannotAccessIndex() method, 394-396

JackController class, 391

JackControllerTests class, 391-392

JavaScript, injection attacks, preventing, 95-97

JavaScriptResult, 52

JillCanAccessIndex() method, 394-396

JillController class, 393-394

JillControllerTests class, 394-396

jQuery

and Ajax, 491-498

animations, 489-491

event handlers, 487-488

including in views, 480-481

overview, 480

plug-ins, 498-501

downloading, 498-499

tablesorter, 499-501

selectors, 482-487

and Visual Studio Intellisense, 481-482

Json() method, overloading, 62

JsonResult, 52, 59-62

keyboard combinations for running unit tests, 665-666

KISS Principle (Keep It Simple Stupid), 507

L

lambda expressions, 655

Language Integrated Query (LINQ), 656-658

LINQ to SQL, 144-147

Last-Modified HTTP header, 345

launching Microsoft Web Platform Installer, 2

length of property, validating, 576-578

libraries

jQuery. See jQuery

MicrosoftAjax.js library, including, 427-428

MicrosoftMvcAjax.js library, including in pages, 427-428

limiting unit test results, 671-672

links (HTML)

creating delete links, 462-467

highlighting selected link, 459-462

image links, rendering, 161-162

rendering, 160-161

LINQ (Language Integrated Query), 656-658

LINQ to SQL, 144-147

ListBlogEntries() method, 536, 552, 553, 601

ListBox() HTML helper, 162-165

listing records, 124-126

ListMovies() method, 349

ListMoviesCached() method, 349

lists, drop-down lists, 167-168

load() method, 491

LoadingElementId property (AjaxOptions class), 436

location of cache, setting, 333-335

Location property (OutputCache attribute), 333-335

LogActionFilter class, 237-239

LogController class, 239-240

LogOff() method, 367

LogOn() method, 367

long-term versus short-term planning, 14

LookupController class, 382-383

LSGenericRepository project, 140

LSMvcApplication project, 144-147

M

MapRoute() method, 272

maps, wildcard script maps, 410-414

Martin, Micah, 10

Martin, Robert, 10

master pages. See view master pages

MasterDetailController class, 457-458

Matches() method, 669

MathUtility class

C# code listing, 667

VB code listing, 668

MathUtilityTests class

C# code listing, 675

VB code listing, 676

MaxInvalidPasswordAttempts settings, 379

membership, configuring

with Membership API, 381-385

membership database, 375-379

membership settings, 378-380

Membership API, 381-385

Membership class, 381-385

MembershipUser class, 381-385

memory caching. See caching

MerchandiseController class, 70-71

MerchandiseRepository() method, 70-71

MergeAttribute() method, 176

messages (error). See error messages

Meszaros, Gerard, 680

methods. See specific methods

Microsoft ASP.NET MVC 1.0, 1

Microsoft Entity Framework

data models

creating models, 120-124

creating records, 127-128

deleting records, 131-132

editing records, 128-130

listing records, 124-126

retrieving single record, 126

Entity Framework blog repository, creating

database objects, 531-532

Entity Framework data model, 532-533

EntityFrameworkBlogRepository class, 534-537, 634-636

overview, 530-531

testing, 537-541

generic repositories, 141-144

Microsoft .NET Framework 3.5 Service Pack 1, 1

Microsoft SQL Server Express, 25

Microsoft Visual Web Developer 2008 Service Pack 1, 2

Microsoft Web Platform Installer, launching, 2

MicrosoftAjax.js library, including in pages, 427-428

MicrosoftMvcAjax.js library, including in pages, 427-428

MinRequiredNonalphanumericCharacters setting, 379

MinRequiredPasswordLength setting, 379

Mock Object Frameworks

doubles, 680

fake values, returning, 690-693

fakes, 680

mocks, 680

Moq, 679

classes, creating from interfaces, 681-690

installing, 680-681

unblocking, 681

overview, 679

Rhino Mocks, 679

stubs, 680

Typemock Isolator, 679

mocks

definition of, 680

mock repositories, testing data access with, 150-155

Mocks Aren’t Stubs (Fowler), 510

model binders

Bind attribute

applying to classes, 221-225

applying to method parameters, 218-221

prefixes, 225-228

custom model binders, creating, 233-236

default model binder

binding to complex classes, 212-218

overview, 210-212

form collection model binder, 228-231

HTTP posted file base model binder, 231-233

overview, 205-210

testing authentication with, 393-400

model state, 241-244

model state dictionary, 241

models. See data models

Models folder, 19

MonoRail, 16

Moq, 679

classes, creating from interfaces, 681-690

installing, 680-681

unblocking, 681

Movie2Controller class, 252-253

Movie2ControllerTests class, 264-266

MovieController class

C# code listing, 682-683

model state, 242-244

posting forms asynchronously, 430-435

retrieving movies, 496-498

VB code listing, 683-684

MovieMaster page, 310-311

MovieRepository class, 686-688

caching, 347-349

MovieRepository class, 257-258

MovieService class, 254-256

C# code listing, 684-685

VB code listing, 685-686

MovieServiceTests class, 688-689

MovieTemplate user control, 322-323

MVC pattern, 16

MVCFakes assembly, 289

MyFirstMvcApp sample application

code listings, 20-22

creating, 17-18

folder conventions, 19

running, 19-20

N

Name property (Identity object), 373

Name setting, 379

namespaces

importing, 519

System.Linq namespace, 656

UnitTesting, importing, 665

naming conventions for views, 39

needless complexity in software, 10

needless repetition in software, 10

nested master pages, 306-307

.NET framework, 14

.NET Framework 3.5 Service Pack 1, 1

New Item command (Add menu), 26

New Project command (File menu), 23

New Test command (Add menu), 660-661

Newkirk, James, 510

NewsController class, 73-74, 493-494

NHaml, 98

NotEqual constraint, 283-285

NTLM authentication, 385-386

nullable types, 651-652

NUnit, 508-509, 672-678

creating tests, 660-666

downloading, 672

installing, 673

running tests, 669-671

nVelocity, 98

O

object initializers, 648

objects

database objects for Entity Framework blog repository, 531-532

Mock Object Frameworks. See Mock Object Frameworks

object initializers, 648

OnBegin property (AjaxOptions class), 439

OnComplete property (AjaxOptions class), 439

OnNameChanging() event handler, 263

OnPriceChanging() event handler, 263

opacity in software, 10

OPTIONS operation (HTTP), 67, 462

origins of ASP.NET MVC framework, 14

OutputCache attribute

cache location, setting, 333-335

cache profiles, 343-344

Location property, 333-335

removing items from output cache, 341-343

sample application, 325-330

security issues, 330-331

testing, 353-355

VaryByContentEncoding property, 337

VaryByCustom property, 338-341

VaryByHeader property, 337-338

VaryByParam property, 335-337

varying output cache, 335-341

what gets cached, 331-333

overloading

Content() method, 59

File() method, 64

Json() method, 62

RedirectToAction() method, 57

View() method, 55

P

PagedList class, 193-195

PagedSortedProducts() action, 200-187

PageList class, 594-596

pageReady() method, 462, 485

paging

supporting in HTML.DataGrid() HTML helper, 192-201

PagedList class, 193-195

PagedSortedProducts() action, 200-201

PagingLinqExtensions class, 195-197

supporting in UnleashedBlog application

BlogController Index() method, 600-601

BlogRepositoryBase class, 602-605

controller tests, 596-600

overview, 591

PageList class, 594-596

PagingLinqExtensions class, 195-197

PartialView() method, 52

PartialViewResult, 51

passing

view data to user controls, 314-319

view data to view master pages, 308-311

Password() HTML helper, 162-165

PasswordAttemptWindow setting, 379

PasswordFormat setting, 379

passwords, changing, 368-369

PasswordStrengthRegularExpression setting, 379

patterns

Dependency Injection pattern, 138-139

Repository pattern. See Repository pattern

Patterns of Enterprise Application Architecture (Fowler), 11

PersonController class, 78-81

plug-ins (jQuery), 498-501

downloading, 498-499

tablesorter, 499-501

Poole, Charlie, 509

post() method, 491

POST operation (HTTP), 67, 462

postbinding validation error messages, 248-250

posting forms asynchronously

displaying progress, 435-442

downlevel browser support, 452-455

sample application, 430-435

updating content after posting, 443-447

validation, 447-452

prebinding validation error messages, 248-250

Prefix property (Bind attribute), 218, 225

prefixes when binding, 225-228

preventing JavaScript injection attacks, 95-97

private data, caching, 330-331

Product class, 261-263

product repositories, creating, 133-138

ProductController class, 48-51, 259-261, 318-319

ProductControllerTests class, 660-661

ProductHelper class, 110-112

ProductHelperTest class, 112-114

ProductInsertDoesNotMatchGet() method, 293-294

ProductInsertMatchesPost() method, 293-294

ProductRepository class, 133-136

Products table (ToyStoreDB), 27

ProfileController class, 344

profiles (cache), 343-344

progress indicators, displaying, 435-442

Project menu commands, Add Reference, 274

properties, validating length of, 576-578

PUT operation (HTTP), 67, 462

Q-R

Queryable class, 656-657

QuotationController class, 59-60

RadioButton() HTML helper, 162-165

records

creating, 127-128

deleting, 131-132

editing, 128-130

listing, 124-126

retrieving single record, 126

Red/Green/Reactor process, 505-506

RedirectResult, 52

returning, 55-57

RedirectToAction() method, 52

RedirectToRouteResult, 52

Reenskaug, Trygve, 15

Reeves, Jack, 509

refactoring

overview, 12, 506

UnleashedBlog application to use Repository pattern, 524-526

referencing jQuery, 480-481

reflection in HTML.DataGrid() helper, 188-189

Refresh() method, 494

Register() method, 367

RegisterRoutes() method, 271-272

regular expression constraints, 278-279

RemoveController class, 342-343

removing items from output cache, 341-343

Render() method, 103

RenderBeginTag() method, 180

RenderEndTag() method, 180

RenderHead() method, 190-191

rendering

drop-down lists, 167-168

form elements, 162-165

forms, 166-167

HTML links, 160-161

image links, 161-162

RenderPagerRow() method, 199

RenderPartial() method, 313

repetition in software, 10

repositories

data access, testing with mock repository, 150-155

FakeMovieRepository class, 267

generic repositories

creating, 139-141

extending, 147-149

with LINQ to SQL, 144-147

with Microsoft Entity Framework, 141-144

MovieRepository class, 257-258, 347-349

product repositories, creating, 133-138

Repository class, 148-149

repository classes, creating, 686-688

SimpleMovieRepository class, 356

for UnleashedBlog application

BlogRepositoryBase class, 552-553

Entity Framework repository, creating, 530-541

fake blog repository, creating, 526-530, 632-633

Repository class, 148-149

Repository pattern, 11-12

creating product repositories, 133-138

Dependency Injection pattern, 138-139

generic repositories

creating, 139-141

extending, 147-149

with LINQ to SQL, 144-147

with Microsoft Entity Framework, 141-144

overview, 132

refactoring UnleashedBlog application to use, 524-526

request validation, disabling, 97

RequiresQuestionAndAnswer setting, 379

retrieving content asynchronously. See asynchronous content retrieval

Rhino Mocks, 679

rigidity in software, 10

roles

authorizing, 371-372

creating

with Account controller, 367-369

with Web Site Administration Tool, 365-366

Roles class, 382

Roles class, 382

route constraints, creating

AuthenticatedConstraint, 280-283

HttpMethod constraint, 280-281

NotEqual constraint, 283-285

regular expression constraints, 278-279

Route Debugger, 274-275

route table, adding extensions to, 403-408

RouteDebugger, 289

routes. See routing

RouteTest class, 293-294, 289-290

RouteTests class, 554-558, 641-642

routing

catch-all parameter, 285-288

custom routes, creating, 275-277

debugging routes, 274-275

default routes, 269-273

configuring, 272-273

Global.asax file, 269-271

overview, 268-269

route constraints, creating

AuthenticatedConstraint, 280-283

HttpMethod constraint, 280-281

NotEqual constraint, 283-285

regular expression constraints, 278-279

testing routes

with constraints, 292-294

MvcFakes and RouteDebugger assemblies, 289

overview, 288

testing if URL matches route, 289-292

UnleashedBlog application routes

adding to Global.asax file, 642

archive routes, 561-563

controller tests, 543-553

invoking Archive controller, 564-565

overview, 541-544

route tests, 553-560, 641-642

running

MyFirstMvcApp sample application, 19-20

unit tests

with NUnit, 669-671

with Visual Studio Unit Test, 669-671

S

SalesFigures() method, 389

SaveChanges() method, 128

scripts, embedding in views, 86-87

Scripts folder, 19

Secrets() method, 368-370

SecretStuff() method, 390

security issues

authentication. See authentication

caching private data, 330-331

passwords, 368-369

selectLink() method, 462

SelectorController class, 457-476

selectors (jQuery), 482-487

ServerValidateController class, 450-451

service layers

in UnleashedBlog application, 581-586

validation with, 251-258

services

BlogService class

blog entry Name property, 588-589

initial code listing, 581-583

ListBlogEntries() method, 601

MovieService class, 254-256, 684-686

SimpleMovieService class, 356-358

SetCacheability() method, 345-346

SetInnerText() method, 176

SetMaxAge() method, 346

Setup attribute (NUnit tests), 666

short-term versus long-term planning, 14

ShowNewBlogEntries() method, 515-516

SimpleControllerTest class, 114-116

SimpleMovieController class, 358-359

SimpleMovieRepository class, 356

SimpleMovieService class, 356-358

SimpleView class, 100-103

SimpleViewEngine class, 99-104

Single-Responsibility Principle (SRP), 581

slideDown() animation, 489-491

slideUp() animation, 489-491

sliding expiration cache policy, 351-352

SlidingController class, 351-352

software

characteristics of bad software, 10

code smells, avoiding, 9-10

design

design patterns, 11-12

design principles, 10-11

short-term versus long-term planning, 14

test-driven development, 13

unit tests, 12-13

nature of good software

call manager application case study, 7-8

definition of, 8-9

overview, 3-7

software requirements, 2

SOLID (design principles), 11

SortController class, 288

sorting, supporting in HTML.DataGrid() HTML helper, 190-192

Spark, 98

SQL

LINQ to SQL, 144-147

SQL Server Express, 25

SRP (Single-Responsibility Principle), 581

state, model state, 241-244

strongly typed views, 94-95

stubs

creating, 688-689

definition of, 680

styles for validation error messages, 247-248

SubmitButton() HTML helper, 173-176

SuperSecrets() method, 370-371

SuperSuperSecrets() method, 392-393

Sys Is Undefined error, 428

System.Linq namespace, 656

System.Web.Abstractions assembly, 415

System.Web.Mvc assembly, 415

System.Web.Routing assembly, 415

T

tables

Products (ToyStoreDB), 27

route table, adding extensions to, 403-408

tablesorter plug-in (jQuery), 499-501

TagBuilder class, 176-180

TagName property (TagBuilder class), 176

TDD. See test-driven development

templates, user controls as, 319-323

Test attribute (NUnit tests), 666

test-driven development

benefits of, 506

bibliography and resources, 509

definition of, 505-506

KISS Principle (Keep It Simple Stupid), 507

overview, 13, 502-505

Red/Green/Reactor process, 505-506

TDD tests versus unit tests, 508

test flow from user stories, 508-509

Unit Testing Frameworks, 508-509

in UnleashedBlog application, 514-520

waterfall versus evolutionary design, 507-508

YAGNI Principle (You Ain’t Gonna Need It), 507

Test-Driven Development by Example (Beck), 509

Test-Driven Development in Microsoft in .NET (Newkirk and Vorontsov),

TestFixture attribute (NUnit tests), 666

testing

authentication

for Authorize attribute, 390-392

with user model binder, 393-400

cache

OutputCache attribute, 353-355

overview, 353

verifying that database data is cached, 355-362

controller actions, 78-81

data access

with fake generic repository, 155-157

with mock repository, 150-155

overview, 149-150

Entity Framework blog repository, 537-541

HTML helpers, 201-205

routes

with constraints, 292-294

MvcFakes and RouteDebugger assemblies, 289

testing if URL matches route, 289-292

test-driven development, 13, 506

bibliography and resources, 509

definition of, 505-506

KISS Principle (Keep It Simple Stupid), 507

overview, 502-505

Red/Green/Reactor process, 505-506

TDD tests versus unit tests, 508

test flow from user stories, 508-509

Unit Testing Frameworks, 508-509

in UnleashedBlog application, 514-520

waterfall versus evolutionary design, 507-508

YAGNI Principle (You Ain’t Gonna Need It), 507

unit tests. See unit tests

UnleashedBlog application. BlogControllerTests class

validation, 264-268

views

custom view engine, 114-117

HTML helpers, 108-114

overview, 105

view results, 105-108

TextArea() HTML helper, 162-165

TextBox() HTML helper, 162-165

TheaterController class, 319-320

Time() method, 353

TimeIsCached() method, 354-355

titles

master page titles, 303-305

titles of blog entries, validating, 567-573

ArchiveControllerTests class, 572-573

BlogController class, 570-571

BlogControllerTests class, 568-569

IndexReturnsBlogEntriesByYear() test, 571

ToString() method, 176

Toy Store application

controller

creating, 30-37

HomeController class listing in C#, 31-32, 34-35

HomeController class listing in VB, 32-34, 35-36

creating, 23-25

data model classes, 27-30

database, 23-27

overview, 22-23

views

Create view, 42-45

creating, 37-45

Index view, 37-42

naming conventions, 39

TRACE operation (HTTP), 68, 462

type inference, 647-648

Type Is Undefined error, 428

typed views, 88-95

types

anonymous types, 649-651

nullable types, 651-652

typed versus untyped views, 88-95

U

unblocking Moq, 681

unit testing frameworks, 508-509

NUnit, 672-678

creating tests, 660-666

downloading, 672

installing, 673

running tests, 669-671

overview, 659-660

Visual Studio Unit Test, 660-672

assertions, 669-672

creating unit tests, 660-664

limiting test results, 671-672

running tests, 669-671

test attributes, 666

Unit Test Wizard, 291

unit tests, 12-13

assertions, 669-672

compared to TDD tests, 508

creating

with NUnit, 660-666

PersonController class example, 78-81

with Visual Studio Unit Test, 60-661

frameworks. See unit testing frameworks

limiting test results, 671-672

RouteTest class, 289-290

running

with NUnit, 669-671

with Visual Studio Unit Test, 669-671

test attributes, 666

Unit Test Wizard, 291

UnitTesting namespace, importing, 665

unknown actions, handling, 76-78

UnleashedBlog application, 205

Ajax support

Ajax.BlogPager() helper, 618-619

BlogEntries partial, 616-617

Index_Ajax() method, 614-615

Index_AjaxReturnsPartialViewResult() method, 614

modified Index view, 615-616

overview, 612-613

blog entries, creating, 520-523

blog projects, creating, 511-514

BlogArchive route, 276

BlogController class. See BlogController class

BlogControllerTests class. See BlogControllerTests class

comments

adding to database, 633-637

BlogEntriesIncludeCommentCount() method, 631-632

Comment class, 624-625

CommentsOrderByDatePublished() method, 629-630

CreateAndThenGetComment() method, 627-629

CreateComment() method, 622-623, 627-628

displaying comments and comment counts, 637-643

modified FakeBlogRepository class, 632-633

overview, 619-622

Details view, 637-641

overview, 510-511

paging support

BlogController Index() method, 597-601

BlogRepositoryBase class, 602-605

controller tests, 596-600

overview, 591

PageList class, 594-596

refactoring to use Repository pattern, 524-526

repositories

BlogRepositoryBase class. See BlogRepositoryBase class

Entity Framework repository, creating, 530-541

fake blog repository, creating, 526-530, 632-633

routes

adding to Global.asax file, 561-563

archive routes, 561-563

controller tests, 543-553

invoking Archive controller, 564-565

overview, 541-544

route tests, 553-560

tests, creating, 514-520

Add New Test dialog, 514

BlogController class, 517-518

BlogControllerTests class, 515-516

BlogEntry class, 517

Index() method, 519-520

namespaces, importing, 519

validation

BlogEntryFactory class, 573-576

business rules, 586-591

overview, 565-568

refactoring to use service layer, 581-586

validating blog entry title, 567-573

validating length of property, 576-578

validation error messages, 578-581

views, 605-612

BlogEntries partial, 607-608

Html.BlogLink() helper, 608-609

Html.BlogPager() helper, 610-612

Index view, 605-611

untyped views, 88-95

UpdateModel() method, 228-230

updating form content, 443-447

URL.Action() helper, 161-162

URLs, testing if URL matches route, 289-292

user controls

adding to views, 313-314

creating, 312-313

MovieTemplate user control, 322-323

overview, 311-312

passing view data to, 314-319

as templates, 319-323

User property (Controller class), 372-374

user stories, test flow from, 508-509

UserController class, 373-374

UserModelBinder class, 233-234

users. See also user controls

authentication. See authentication

authorizing

with Authorize attribute, 368-370

authorizing particular users, 371-372

overview, 368

with User property, 372-374

creating

with Account controller, 367-369

with Web Site Administration Tool, 365-366

membership, configuring

with Membership and Roles Manager API, 381-385

membership database, 375-379

membership settings, 378-380

passwords, changing, 368-369

user stories, test flow from, 508-509

V

validation

with Ajax posts, 447-452

error messages

prebinding versus postbinding, 248-250

styling, 247-248

with IDataErrorInfo interface, 258-263

model state, 241-244

overview, 240-241

request validation, disabling, 97

with service layers, 251-258

testing, 264-268

in UnleashedBlog application

BlogEntryFactory class, 573-576

business rules, 586-591

overview, 565-568

refactoring to use service layer, 581-586

validating blog entry title, 567-573

validating length of property, 576-578

validation error messages, 578-581

validation helpers, 245-247

A Value Is Required error message, 579-580

values, returning fake values, 690-693

variables, dateReleased, 651

VaryByContentEncoding property (OutputCache attribute), 337

VaryByCustom property (OutputCache attribute), 338-341

VaryByHeader property (OutputCache attribute), 337-338

VaryByParam property (OutputCache attribute), 335-337

VaryCustomController class, 340

VB language features

anonymous types, 649-651

extension methods, 652-654

generics, 654-655

lambda expressions, 655

LINQ (Language Integrated Query), 656-658

nullable types, 651-652

object initializers, 648

type inference, 647-648

verifying caching of database data, 355-362

view content pages, creating, 300-301

view data, 87-88

passing to user controls, 314-319

passing to view master pages, 308-311

view master pages

creating, 295-299

master page titles, 303-305

nested master pages, 306-307

overview, 294-295

passing view data to, 308-311

setting from controller, 302-304

view content pages, 300-301

View() method, 52, 54-55

view results, testing, 105-108

ViewDataDictionary class, 91

ViewResult, 52-55

views, 16. See also view master pages

alternative view engines

Brail, 98

custom view engines, 99-104, 114-117

NHaml, 98

nVelocity, 98

overview, 97-98

Spark, 98

Create, 432-435

creating, 83-87

embedding scripts in, 86-87

Index. See Index view

JavaScript injection attacks, preventing, 95-97

naming conventions, 39

overview, 82-83

testing

custom view engines, 114-117

HTML helpers, 108-114

overview, 105

view results, 105-108

for Toy Store application

Create view, 42-45

creating, 37-45

Index view, 37-42

typed versus untyped views, 88-95

for UnleashedBlog application, 605-612

BlogEntries partial, 607-608

Html.BlogLink() helper, 608-609

Html.BlogPager() helper, 610-612

Index view, 605-611

user controls. See user controls

view data, 87-88

Views folder, 19

VirtualPathProviderViewEngine class, 99

Visual Studio Intellisense and jQuery, 481-482

Visual Studio project files, modifying to support ASP.NET MVC, 415

Visual Studio Unit Test, 660-672, 508

assertions, 669-672

creating unit tests, 60-661

limiting test results, 671-672

running tests, 669-671

test attributes, 666

Visual Web Developer 2008 Service Pack 1, 2

Vorontsov, Alexei, 510

W

waterfall design, 507-508

web configuration files, configuring ASP.NET Web Forms files to support ASP.NET MVC, 416-422

Web Forms. See ASP.NET Web Forms

Web Platform Installer, launching, 2

Web Site Adminstration Tool, 365-366

web.config files, configuring ASP.NET Web Forms files to support ASP.NET MVC, 416-422

What Is Software Engineering? (Reeves), 509

Where() method, 656

WidgetController class, 55-56

wildcard script maps, 410-414

Windows authentication

authenticating Windows users and groups, 386-390

configuring, 385-387

overview, 385

types of authentication, 386

WindowsController class, 387-388

wizards, Entity Data Model Wizard, 28-30

Working Effectively with Legacy Code (Feathers), 9, 12, 509

Write() method, 180

WriteLine() method, 180

X-Y-Z

XSS (cross-site scripting) attacks, 96

xUnit Design Patterns: Refactoring Test Code (Meszaros), 680

YAGNI Principle (You Ain’t Gonna Need It), 507

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.172.38