Index

client and server validation testing and, SYMBOLS 77–80 $(document).read(), jQuery, 143 composing messages, 170–171 handling validation of data layer repository, A 94–96 abstraction, of data layer, 93–94 InMemoryContactService and, 121–122 acceptable verbs, 38 usage tracking and, 241–242, 246, 248 [AcceptVerbs] attribute validation testing and, 80 overview of, 38 advice, AOP, 13 testing existence of Register action and AJAX correct signature, 39–40 displaying images after upload, 206 Accordion UI control, 251 message templating and, 219–220, 224 account management, high-level design POST vs. GET, 258 for, 29–30 submitting form data with, 201–204 AccountController class Alert boxes, 196 creating tests related to membership Amazon EC2 (Elastic Computer Cloud), actions, 37 260 testing user registration, 41–42 AOP (aspect-oriented programming), AccountControllerTest class, 39 12–13 action fi lters, ASP.NET MVC, 9 AppHelper class Action method creating for membership test, 46–48 image hosting, 208 testing validity for contact import, message composition, 173 155–156 message retrieval, 180–181 AppHelperTest class ActionFilterAttribute, creating action creating for membership test, 46 fi lters, 9 validating email address for registration, ActionResult, testingCOPYRIGHTED validity of, 37 MATERIAL45–47 ActiveX, 187 .ascx user controls, 132–134 Add method aspect, AOP, 13 adding messages to repository, 171 aspect-oriented programming (AOP), assigning unique ID, 97–98 12–13

447628bindex.indd7628bindex.indd 226363 88/4/09/4/09 99:34:06:34:06 AMAM ASP.NET MVC framework

ASP.NET MVC framework, overview, 6–10 BlackTie theme, ThemeRoller, 255 action fi lters, 9 Browse actions/methods controller, 7–8 browsing messages, 179–180 HTML helpers, 9 contact management and, 129 model, 7–8 IContactService interface, 127 ModelState, 10 message composition and, 178 overview of, 6 redirection to following import, 149 routing, 8 sorting and, 134 TempData, 9–10 browsing contacts view, 7–8 adding pager as user control, 132–134 ViewData, 8–9 controller action for, 127 WebForms model vs., 6–7 design, 111 AssertCreateValidationError helper mapping URL to Contact controller, 129 function, for asserting validation overview of, 125 error, 169 PagedList class and, 127–129 assertions populating repository with test data, refactoring code and, 67–72 126–127 refactoring design and, 66 sorting and, 134–136 similarities pointing to need for refactoring, testing contract retrieval for logged-in user, 72 129–130 Assert.Throws, in exception testing, 79 testing retrieval of one page of contacts, attributes, validation, 84 126 authentication, forms, 54–55 view for iterating through contact list, Authorize action fi lter, 9 130–132 Authorize attribute, 168 bugs Autofac, IoC container, 21 creating contacts and, 121, 125 importing contacts and, 161–165 B refactoring not fi xing, 259 TDD (Test Driven Development) and, 11 banners, as images, 195 business logic object, 77 billing and subscriptions buttons constructing payment service, 226–228 creating for PayPal, 234 design, 225–226 CSS interaction state classes applied overview of, 225 to, 256 PayPal implementation, 228–230 as images, 195 problem statement, 225 Insert Image button, 196–198 summary, 236 View of, 233–236

264

447628bindex.indd7628bindex.indd 226464 88/4/09/4/09 9:34:069:34:06 AMAM contact management

populating repository with messages, C 179–180 caching problem statement, 167 images, 257–258 Request Validation and, 185 output caching, 258 returning error message if requested callbacks message does not exist, 181–182 payment processing and, 225 saving changes to repository, 183 verifying performance by callback method, summary, 185–186 226–228 testing if user can see messages, 182 campaign report, reports and stats testing that message is added to repository, design, 5 171–172 Cascading Style Sheets (CSS) validating message name, 168–169 in jQuery UI Library, 252–256 views of, 172–173, 178–179, 183–184 minifi cation of, 257 compression, gzip for, 257 classes constructor parameters, dependency ASP.NET MVC model, 7 injection and, 103, 106–107 defi ning user class, 122 Contact Lists, 110 click events, images, 209 contact management client-side validation, 87–92 browsing contacts. See browsing contacts benefi ts of, 73 checking validity of contact information options for, 87–88 (email, date of birth), 114–116 test class for, 88–92 contact defi ned, 111 validating contact view, 115–116 controller for, 112–113 cloud computing, 260 Create action, 113–114, 119 code coverage, 19–20 creating contacts, 111 code refactoring. See refactoring code deleting contacts, 111, 143–144 ComplexModelBinder, 69 design, 110–111 composing messages editing contacts. See editing contacts adding instance of IMessageService, 170 establishing relationship between user and Authorize attribute for controlling access contact, 121–122 to message creation, 168 high-level design for, 32–33 coding edit functionality, 180–181 importing contacts. See importing contacts creating message controller, 168 instantiating controller using dependency design process, 167 injection, 123–125 helper methods for populating repository, notifi cation of successful creation of 176–177 contact, 119–120 listing existing messages, 174–175 overview of, 3–5, 109 overview of, 167

265

447628bindex.indd7628bindex.indd 226565 88/4/09/4/09 9:34:069:34:06 AMAM contact management (continued)

contact management (continued) controls, in jQuery UI Library, 251 problem statement, 109–110 Convention over Confi guration principle, summary, 145 17–18 testing contact creation, 116–118 copying/pasting contacts, 147 testing invalid email, 118 coupling, benefi ts of loosely coupled testing that multiple users can access systems, 103 same contact, 123 Create action/methods testing uniqueness of email addresses, action fi lters, 9 120–121 contact management, 113–114 TinyMCE integration with contact contacts, 3–4 management systems, 188 CRUD operations, 31 ContactController message controller, 168 creating contacts and, 112–113 messages, 2, 31, 76 importing contacts and, 148 preventing unauthorized access to, 168 ContactServiceTests class, 159 CreateUser method containers, IoC. See IoC (Inversion handling registration failures from of Control) Membership Provider, 49–50 controllers simulating call to membership AccountController class, 37, 39, 41–42 provider, 40–42 ASP.NET MVC, 7–8 creating contacts Browse controller action, 127–130 checking validity of contact information confi guring for dependency injection, 106 (email, date of birth), 114–116 contact editing, 137 controller for, 112–113 contact management, 112–113 Create action, 113–114, 119 ContactController class, 148 design, 111 creating message controller, 168 establishing relationship between user and GalleryController class, 199–200 contact, 121–122 helper method for instantiating, 177 instantiating controller using dependency IoC (Inversion of Control), 123–124 injection, 123–125 MessageController class, 75, 77, notifi cation of successful contact 84–85, 170 creation, 119–120 PayController controller, 226 testing contact creation, 116–118 refactoring controller actions, 65 testing invalid email, 118 SetUp method and, 176 testing that multiple users can access template controllers, 213–214 same contact, 123 TrackerController controller, 239, 241 testing uniqueness of email usage tracking, 238–241 addresses, 120–121

266

447628bindex.indd7628bindex.indd 226666 88/4/09/4/09 9:34:069:34:06 AMAM edit actions

cross-cutting concerns, AOP, 12 design, high-level CRUD (create, read, update, and delete) account management, 29–30 contact management using, 31 contact management, 32–33 IRespository pattern and, 94 environment requirements, 34 CSS (Cascading Style Sheets) membership system, 25–29 in jQuery UI Library, 252–256 message management, 31 minifi cation of, 257 overview of, 25 problem, 25 D DI (Dependency Injection) design, 104–105 data layer message templating and, 216 changing InMemoryMessageService to use Ninject IoC Containers for, 105–108 repository, 95–96 overview of, 103 creating IMessageRepository, 94–95 PayPal service, 235 design, 94 principle, 16 implementing IMessageRepository, 96, problem statement, 103–104 100–101 summary, 108 in-memory repository and, 102 overview of, 93 div element problem statement, 93 for hidden layers, 197 testing ability to save existing messages to holding images in, 207 repository, 99–100 document object model (DOM), 143 testing delete functionality, 98–99 DOM (document object model), 143 testing unique ID assignment, 97–98 DRY (don't repeat yourself) data store. See repositories principle, 16 databases. See repositories refactoring code and, 65 Date Picker, UI control, 251 duplicate action, messages, 3 delete actions DynamicImage action contact list, 5 testing fi le content and fi lename, 239–241 contact management, 111, 143–144 tracking email message view, 244 contacts, 4 CRUD operations, 31 E message repository, 98–99 EC2 (Elastic Computer Cloud), 260 messages, 3 edge cases, fi nding/handling, 186 Delete method, verifying removal of edit actions messages, 98–99 contacts, 4, 137 dependencies, 103. See also DI form submission, 140 (Dependency Injection) messages, 2, 182–183 Dependency Injection. See DI (Dependency post, 183 Injection) routing and, 8

267

447628bindex.indd7628bindex.indd 226767 88/4/09/4/09 9:34:069:34:06 AMAM Edit functionality

Edit functionality, coding, 180 ErrorCodeToString method, 51–52 Edit link, creating, 174 EvenContact web application editing contacts defi ned, 1 adding error message for non-existent reasons for creating, 22 contacts, 138–139 requirements. See requirements adding Get method to Excel spreadsheets, importing, 147 IContactService, 137 exceptions design, 111 Assert.Throws, 79 enforcing editing only by logged-in user, creating validation framework, 77–84 139–140 helper functions for asserting validation handling form submission, 140–143 errors, 169 overview of, 136 Message class, 170 testing retrieval of correct contact item, 137 ValidationException, 78 Elastic Computer Cloud (EC2), 260 ExpectedException attribute, 78 email account management design, 29–30 F adding contact to email address list, 33 facicon.ico, 257 checking missing addresses, 43–44 fi elds checking validity of contact information, naming conventions, 57 114–116 validating, 59–60 components of email messages, 167 fi le content, testing in usage tracking, testing email validation, 90–91 239–241 testing invalid addresses, 45–47 fi le upload testing invalid email, 118 displaying images after, 206 testing uniqueness of email addresses, image galleries and, 198 120–121 modal JavaScript dialog box for, 201 tracking email messages, 244 testing functionality of, 204–206 uploading images, 195 fi lenames, testing in usage tracking, error messages 239–241 customizing, 139 FileResult, in image hosting, 208 displaying, 138–139 Firefox Bookmarklet, ThemeRoller, displaying valid, 56 252, 254 membership registration and, 42–43, Flash, HTML editors and, 187 45, 51 fl ash messages Request Validation and, 185 fl ash message pattern, 119–120 requested messages and, 182 Import action and, 149 returning appropriate, 181–182 Ruby on Rails, 119 validation and, 59

268

447628bindex.indd7628bindex.indd 226868 88/4/09/4/09 9:34:069:34:06 AMAM hyperlinks

forms helper functions authentication, 54–55 for asserting validation errors, 169 creating Edit action for form HTML helpers, 9 submission, 140 Html.AttributeEncode helper method, 57 submitting form data with AJAX, 201 for instantiating controller, 177 WebForms suited for Visual Studio, 7 for populating test repository, 176 FormsAuthenticationWrapper class, 54–55 ValidationMessage helper method, 59 front-end optimization tips, 257–258 high-level design account management, 29–30 G contact management, 32–33 environment requirements, 34 galleries membership system, 25–29 browsing image gallery, 195 message management, 31 interface for image gallery, 198 overview of, 25 template gallery, 216 problem, 25 GalleryController class, 199–200 homepage, redirecting user to, 38–39 Get method horizontal scaling, 259 added to IContactService interface, 137 HTML composing messages and, 181–182 components of email messages, 167 contact management and, 140 helpers, 9 image hosting and, 207 message content, 74 message templating and, 215, 221–222 messages and images, 195 MessageService class, 101–102 Prefix, 70 GetPage method, 134, 178 TEXTAREA fi elds, 188 global address book, contacts stored HTML editors, 192–193 in, 3–4 design, 187 GoGrid cloud solution, 260 factors in choosing, 188 Goode, Troy, 129 jWYSIWYG, 192–193 gzip, for compression, 257 NicEdit, 190–191 problem statement, 187 H TinyMCE, 188 HandleError attribute, 139 WYMeditor, 189–190 handshakes Html.AttributeEncode helper method, 57 creating for PayPal, 228–229 hyperlinks payment processing and, 225 adding to master page, 197 verifying performance by callback method, ease of adding with HTML editors, 187 226–228

269

447628bindex.indd7628bindex.indd 226969 88/4/09/4/09 9:34:069:34:06 AMAM icons

testing fi le upload functionality, 204–206 I testing FileResult, 208 icons, in jQuery UI Library, 251 testing image retrieval, 206–207 IContactRepository , 121 images IContactService embedding inline, 187 adding Browse method to, 127 making small and cacheable for creating, 117–118 optimization, 257–258 GetPage method, 134 IMessageAuditService, 240–241 IContactsImporter, 151 IMessageRepository IDE Visual Studio 2008, 7 creating interface for, 94–95 IEnumerable, 127–129 helper methods for populating, 176–177 if statements implementing, 96 server validation with, 73 overview of, 171 writing, 151 populating repository with messages, IFormsAuthentication, 54–55 179–180 IGalleryRepository, 200–201 saving changes to, 183 IGalleryService, 200 testing assignment of unique ID to image editors, 239 messages, 97–98 image galleries IMessageRepository browsing, 195 full implementation of, 100–101 interface for, 198 testing ability to save existing messages to overview of, 196 repository, 99–100 image hosting testing delete functionality of, 98–99 design, 195–196 IMessageService displaying images after upload, 206 changing InMemoryMessageService to use fi le upload added to modal JavaScript repository, 95–96 dialog, 201 LINQ lazy loading and, 101 fi le upload and storage in memory, message composition and, 170–172 198–201 IModelBinder, 69 gallery interface for, 198 import actions and methods Insert Image button, 196 bugs, 161 modal JavaScript dialog box for, 196–198 calling Import method on contacts service, overview of, 195 157–158 problem statement, 195 fl ash messages and, 149–150 selecting images and inserting into populating contact database, 151 message body, 209 validating, 160 submitting form data, 202–204 importing contacts summary, 210 bugs, 161–165

270

447628bindex.indd7628bindex.indd 227070 88/4/09/4/09 9:34:069:34:06 AMAM JavaScript-based editors

controller for, 148 IoC (Inversion of Control) design, 147–148 addressing tight coupling with IoC implementation, 159–161 Containers, 104–105 instantiating importer instances, 151 choosing between IoC Containers, 21, 105 overview of, 147 creating controllers and, 123–124 parser factory, 151–152 overview of, 103 problem statement, 147 principle, 16 string parser, 154–156 uniqueness check for logged-in users, summary, 166 120–122 testing, 165–166 working with Ninject IoC Container, testing parser factory, 156–159 105–108 testing success of Import action, 149–150 IPaymentService, 227 testing that string or uploaded fi le posted to IQueryable server, 148–149 Get method and, 101–102 text fi le parser, 153–154 PagedList collection class, 127–129 View for, 150 IRespository pattern, 93–94, 102. See also inline content editors data layer jWYSIWYG, 192 ISubscriptionPlanRespository, 231 NicEdit, 190 IsValidEmail method, 45–47 in-memory. See also IRespository IsValidUsername method, 47–49 pattern, 121 ITemplateRespository, 215 contact service, 121–122 ITemplateService, 214, 217 data layer and, 102 message service, 95–96, 100 J tight coupling and, 104 Java, HTML editors and, 187 InMemoryContactRepository, 121 JavaScript InMemoryContactService, 121–122 HTML editors and, 187 InMemoryMessageRepository, 100 libraries, 19 InMemoryMessageService minifi cation of, 257 adapting to use IMessageRepository, modal JavaScript dialog box, 196–198, 201 95–96 using third-party library for client-side problem of tight coupling, 104 validation, 87–88 Insert Image button JavaScript Object Notation (JSON) default dialog, 196 message templating and, 219–220, 224 executing custom JavaScript, 196–198 overview of, 203 Internet, validating all data received via, 73 JavaScript-based editors, 187 Inversion of Control. See IoC (Inversion of adding template to, 218–219 Control)

271

447628bindex.indd7628bindex.indd 227171 88/4/09/4/09 9:34:069:34:06 AMAM JavaScript-based editors (continued)

JavaScript-based editors (continued) using third-party library for client-side design, 187 validation, 87–88 factors in choosing, 188 YUI (Yahoo! User Interface Library), 193 jWYSIWYG, 192–193 links. See hyperlinks NicEdit, 190–191 LINQ problem statement, 187 lazy loading, 101–102 saving content as HTML template, 223–224 sorting strings and, 134–135 TinyMCE, 188 LINQ Dynamic Query Library, 135 WYMeditor, 189–190 Liskov substitution principle, 17 joinpoint, AOP, 13 List method, templates, 221–222 jQuery lists $(document).read(), 143 adding contact to, 5, 32–33 JavaScript libraries, 20 Contact Lists, 110 jWYSIWYG using, 192 creating contact list, 4 plug-ins enabling AJAX uploads, 204 deleting contact list, 5 UI Library, 196–197 of existing messages, 174–175 UI library, 250–252 of images, 209 validating contact view, 115–116 iterating through contact list, 130–132 Validation plug-in, 87–90 of messages, 2 WYMeditor using, 190 PagedList class and, 127–130 JSON (JavaScript Object Notation) parsing contact list, 151–157 message templating and, 219–220, 224 of system templates, 213 overview of, 203 logged-in users, uniqueness check for, 122 jWYSIWYG, 192–193 logging, using aspect-oriented programming, 12–13 K login process designing membership system, 27–28 keep it simple, stupid (KISS), 16 refactoring code and, 68 KISS (keep it simple, stupid), 16 LoginModel class, 68 L Lupetti, Antonio, 132 lazy instantiation pattern, 14–15 lazy loading, LINQ, 101–102 M libraries master page JavaScript libraries, 19–20 adding links to, 197 jQuery UI Library, 196–197, 250–256 creating view, 56–58 LINQ Dynamic Query Library, 135 MbUnit mocking, 22 ReSharper test runner and, 34

272

447628bindex.indd7628bindex.indd 227272 88/4/09/4/09 9:34:069:34:06 AMAM mocking

testing email validation, 46–47 overview of, 2, 211 unit testing framework, 17–18 problem statement, 211 membership summary, 224 error returned if email is invalid, 45–47 updating WYSIWYG editor for, 218–219 error returned if email is missing, 43–44 View, 216–217 error returned if username is invalid, 47–52 MessageAudit error returned if username is missing, creating model for, 240 42–45 testing redirection to URL, 245–247 forms authentication, 54–55 tracking type of action performed by user, login process design, 27–28 243–244 overview of, 35–36 MessageController password confi rmation design, 27 creating, 75, 170 problem, 35 test classes, 74–75 redirects to home index on successful test, validation testing, 84–85 40–42, 52–53 messages Registration page view, 56–63 adding page to all existing messages, 174 registration view test, 37–38 assigning unique ID to, 97–98 reset password process, 28–29 components of, 74 test classes for, 36 composing. See composing messages testing user registration, 39–40 design requirements, 2–3 user registration design, 25–26 high-level design for, 31 Membership Provider saving changes to existing, 99–100 creating user with, 40 selecting image and inserting into message handling registration failures from, 49–52 body, 209 simulating call to, 40–42 sending to users. See contact management Message class, 170 testing ability to save existing messages to message ID repository, 99–100 saving to database, 246 testing assignment of unique ID to, 97–98 testing for, 243 verifying removal of, 98–99 message queue, 31 MessageService class, 81, 101–102 message templating methods, naming test, 36 creating template controller, 213–214 Azure, 260 design, 211–213 minifi cation, of JavaScript and CSS, 257 enabling users to save own templates, mocking 219–224 DI (Dependency Injection) combined getting list of system templates, 213 with, 103

273

447628bindex.indd7628bindex.indd 227373 88/4/09/4/09 9:34:069:34:06 AMAM mocking (continued)

mocking (continued) routing, 8 Files collection, 199 TempData, 9–10 forms authentication, 54–55 view, 7–8 IContactsImporter, 151 ViewData, 8–9 IMessageRepository, 95 WebForms model vs., 6–7 libraries, 22 Mocks class, 67–68 N payment processing, 230–233 naming conventions payment service, 227 form fi elds, 57 refactoring design and, 66 test classes and test methods, 36 refactoring mocks, 67–68 tests related to actions, 37 setting up mock objects for message views, 56 composition, 177 NCover, 19 similarities pointing to need for NicEdit, 190–191 refactoring, 72 Ninject (www.ninject.org) simulating call to membership dependency injection with, 105–108 provider, 40–42 IContactService interface and, 118 WebRequest creation, 229–230 IoC Containers and, 105 modal JavaScript dialog box, 196–198, 201 message templates and, 216 model binders, in refactoring, 66, 69–70 PayPal service and, 235 model-based validation, 85 uniqueness check for logged-in users, ModelState, ASP.NET MVC, 10 120–122 Model-View-Controller. See MVC (Model- notifi cation messages View-Controller) notifying user contact message successfully Moq, 22 created, 119 MSDN LINQ Dynamic Query Library, 135 showing save successfully created, 173 MSTest, unit testing framework, 17 notifi cation URL, payment processing Muehsig, Robert, 132 and, 225 MVC (Model-View-Controller), 6 null object pattern, 14 MVC (Model-View-Controller), in ASP.NET, 6–10 action fi lters, 9 O controller, 7–8 objects HTML helpers, 9 business logic object, 77 model, 7–8 indirection of object instantiation, 103–104 ModelState, 10 null object pattern, 14 overview of, 6 Template objects, 213

274

447628bindex.indd7628bindex.indd 227474 88/4/09/4/09 9:34:069:34:06 AMAM public properties

open-closed principle, 15 Patterns of Enterprise Application optimizing code Architecture (Fowler), 13 design, 250 PayController controller, 226 front-end optimization tips, 257–258 payment service, 226–228. See also billing gzip for compression, 257 and subscriptions minifi cation of JavaScript and CSS, 257 PayPal output caching, 258 account management design, 29–30 overview of, 256 implementing PayPal service, 228–230 refactoring code, 258–259 payment processing with, 230–233 Outlook Personal Files, importing, 147 View , 228–230 output caching, 258 performance, improving perceived, 257 PerformHandShake, 227 P Plain Old CLR object (POCO) classes, 7 plaintext messages, 74 page, adding to existing messages, 174 POCO (Plain Old CLR object) classes, 7 PagedList collection class, 127–130 pager user control, 132–134 PopulateRepository method, 126 pagination, of list of images, 209 pop-ups jWYSIWYG and, 192 Pagination class, 129 NicEdit and, 191 Pagination.ascx user control, 132–134 TinyMCE and, 188 parsers WYMeditor and, 190 creating parser factory, 151–153 string parser, 154–156 Prefix, HTML, 70 testing parser factory, 156–159 principles text fi le parser, 153–154 Convention over Confi guration, 17–18 password defi ned, 15 confi rmation, 27 Inversion of Control/Dependency reset process, 28–29 Injection, 16 validating, 44 KISS, 16 patterns, design open-closed, 15 fl ash message pattern, 119–120 overview of, 16 single responsibility, 16–17 IRespository pattern. See IRespository YAGNI, 15 pattern lazy instantiation, 14–15 ProcessPayment method, 232–233 null object, 14 promotional badge, as images, 195 repository, 15 public properties, injecting dependencies strategy, 13–14 with, 103

275

447628bindex.indd7628bindex.indd 227575 88/4/09/4/09 9:34:069:34:06 AMAM queue-monitoring service

overview of, 35–36 Q password confi rmation, 27 queue-monitoring service, 31 problem, 35 reset password process, 28–29 R user registration, 25–26 RAD (Rapid Application Development), 7 regular expression attribute, validation range attribute, validation attributes, 84 attributes, 84 Rapid Application Development (RAD), 7 reports and stats, viewing, 5 read action, CRUD operations, 31 repositories RedirectToRouteResult value, 39 adding contacts to, 159–161 Redmond theme, 254 adding message to, 171 refactoring code, 65–72 creating for usage tracking, 240–241 assertions and, 70–72 helper function for populating test design, 66, 250 repository, 176 generic assertions and, 66–67 IContactRepository, 121 mocking and, 67–68 IGalleryRepository, 200–201 model binders and, 69–70 IMessageRepository. See optimizing code and, 258–259 IMessageRepository overview of, 65 IRespository pattern as alternative to PayPal implementation, 229 testing, 93 problem statement, 65–66 for PayPal service, 235 setup method running for every test, 67 PopulateRepository method, 126–127 summary, 72 populating with messages, 179 Register action tests repository pattern, 15 error returned if email invalid, 45–47 saving changes to, 183 error returned if email missing, 43–44 Request Validation, 185 error returned if username invalid, 47–52 Request.Files, 148, 198 error returned if username missing, 42–43 Request.Url property, 209 getting to register view, 37–38 required attribute, validation attributes, 84 redirects to home index on success, requirements 40–42, 52–53 aspect-oriented programming (AOP), 12–13 successfully registration of new code coverage, 19–20 user, 39–40 contact management design, 3–5 registration (signup) process design, 1–2 action tests. See Register action tests IoC containers, 21 forms authentication, 54–55 JavaScript libraries, 19 login process, 27–28 message management design, 2–3

276

447628bindex.indd7628bindex.indd 227676 88/4/09/4/09 9:34:069:34:06 AMAM subscriptions

miscellaneous design, 5–6 scripting attacks, 185 mocking libraries, 22 search actions Model-View-Controller (MVC), 5–10 contacts, 4 patterns, 13–15 messages, 3 principles, 15–18 security check, enforcing in service problem, 1 layer, 140 reports and stats design, 5 send action, messages, 3, 31 Test Driven Development (TDD), 10–11 server-side validation tools and frameworks, 18–22 benefi ts of, 73 unit testing framework, 17–18 creating test class for, 74–77 ReSharper creating validation framework, 77–84 MbUnit working with, 17–18 SetAuthCookie method, forms overview of, 34 authentication, 54–55 rich text capability, 193 SetFakeStatus method, handling Rich , YUI, 20, 193 registration failures, 49–50 routing, 8 SetUp method Row Tests, MbUnit, 17 initiating controller, 176 Ruby on Rails, 119 refactoring code and, 67 Shared folders, views, 56 S single responsibility principle Liskov substitution, 17 save actions/methods overview of, 16–17 message templates, 219–224 singleton, using for in-memory data messages, 3 class, 125 notifi cation of successful save, 173 software principles, 15–18 Save Message button, 184 sorting saving changes to repository, 183 applying strategy pattern to, 14 testing ability to save existing messages to arguments required for, 134 repository, 99–100 Browse actions and, 134–136 testing presence of email address before startup methods, refactoring code saving data to database, 242–243 and, 67–68 usage tracking and, 246 stats, viewing, 5 scaling applications strategy pattern, 13–14 clouds and, 260 styles, in jQuery UI Library, 251 design, 250 subscriptions. See also billing and scale out (horizontal scaling), 259 subscriptions scale up (vertical scaling), 259 account management design and, 29–30

277

447628bindex.indd7628bindex.indd 227777 88/4/09/4/09 9:34:069:34:06 AMAM subscriptions

subscriptions (continued) TestDriven.net, 34 Subscribe Now button, 234 text subscribing to PayPal, 231–232 components of email messages, 167 SubscriptionPlan model, 236 importing text fi les, 147 unsubscribing from PayPal, 232–233, 235 parsing text fi les, 151–157 styling, 187 T Text property, 171 TEXTAREA fi elds, HTML, 188 tables, 93 ThemeRoller, jQuery, 250–254 Tabs, UI control, 251 CSS Framework, 252–256 TDD (Test Driven Development) Firefox Bookmarklet, 252, 254 code coverage in, 19–20 overview of, 250 MVC suited for, 6 thumbnails, 209 overview of, 10–11 TinyMCE, 188 slowness as factor in, 93 testing/fi xing bugs, 161 TrackerController controller, 239, 241 unit testing framework, 17–18 validation testing, 77 U TempData UI (user interface) adding error message to, 138–139 CSS Framework in jQuery UI Library, ASP.NET MVC and, 9–10 252–256 creating fl ash messages, 119–120 design, 249–250 overview of, 119 jQuery UI Library, 250–252 Template objects, 213 ThemeRoller, 252, 254 templates. See message templating WYSIWYG Editor, 195 test classes unique IDs, messages, 97–98 client-side validation, 88–92 unit testing framework contact management, 112 overview of, 17–18 importing contacts, 151 Register action tests. See Register membership, 36 action tests message composition, 168, 175 update action, CRUD operations, 31 MessageControllerTest, 74–75 Upload action, GalleryController class, naming conventions, 36 199–200 server-side validation, 74–77 Url.Action ("Register") helper Test Driven Development. See TDD (Test method, 57 Driven Development) URLs test runners, 34 inserting URL to a picture, 196 Test Utility, YUI, 20 mapping URL to Contact controller, 129

278

447628bindex.indd7628bindex.indd 227878 88/4/09/4/09 9:34:069:34:06 AMAM View

refactoring code and, 71 of fi elds, 59–60 Request.Url property, 209 fi le upload and, 206 usage tracking helper functions, 169 creating controllers for, 238–241 of import actions and methods, 160 design, 237–238 of MessageController, 84–85 problem statement, 237 model-based, 85 testing presence of email address before moving out of message controller, 77 saving data to database, 242–243 overview of, 73 testing redirection to URL, 245–247 problem statement, 73–74 testing type of action being audited, Request Validation, 185 247–248 server-side. See server-side validation tracking type of action performed by user, summary, 92 243–244 testing all fi elds, 79–80 user controls, pager, 132–134 usernames, 47–52 user interface. See UI (user interface) ValidationException, 78, 80–81 user registration, designing membership ValidationMessage helper method, 59 system, 25–26 verbs, acceptable, 38 user report, 5 vertical scaling, 259 usernames View checking validity of, 47–52 ASP.NET MVC and, 7–8 fi ltering messages by, 182 for billing and subscriptions, 233–236 users, 243–244 for composing messages, 172–173, account management, 29–30 178–179, 183 defi ning user class, 122 for contact management, 115–116, 130 designing membership system, 25–29 conventions for, 56 relationship between user, contact, and for creating contacts, 112–114 Contact List, 110 for editing contacts, 137 for fi le upload, 207 V for importing contacts, 150 for iterating through contact list, 130–132 validation for message templating, 216–217 adding to contact view, 114–115 for My Templates, 222–223 attributes, 84 for PayPal, 228–230 client-side. See client-side validation of Registration page, 56–63 of data layer repository, 94–96 sending data to, 8–9 design, 74 for title setup, 148 email addresses, 43–44

279

447628bindex.indd7628bindex.indd 227979 88/4/09/4/09 9:34:069:34:06 AMAM View state

View state, master page, 60–63 WYMeditor, 189–190 ViewData WYSIWYG (what you see is what you get) ASP.NET MVC, 8–9 editors ModelState property, 10 adding template to, 218–219 TempData vs., 9–10 design, 187 testing for template item, 217 factors in choosing, 188 testing mytemplates data, 222–223 jWYSIWYG, 192–193 viewing, compared with editing, 4 NicEdit, 190–191 ViewPage, ASP.NET MVC, 7 problem statement, 187 Views folder, 56 saving content as HTML template, 223–224 ViewUserControl, 7 TinyMCE, 188 virtual machines, cloud solutions and, 260 WYMeditor, 189–190 Visual Studio 2008, 7 WYSIWYM (what you see is what you mean) editors, 189 W W3C XHTML specifi cation, 189 X Web references XHTML, 189 free test runner, 34 ReSharper, 34 Y WebForms model, ASP.NET YAGNI (you ain't gonna need it) principle, defi ned, 6 15 strengths of, 7 YUI (Yahoo! User Interface Library) WebRequest, mocking creation of, 229–230 Rich Text Editor and, 193 Windows Azure, Microsoft, 260 using, 20

280

447628bindex.indd7628bindex.indd 228080 88/4/09/4/09 9:34:069:34:06 AMAM 447628bindex.indd7628bindex.indd 228181 88/4/09/4/09 9:34:069:34:06 AMAM 447628bindex.indd7628bindex.indd 228282 88/4/09/4/09 9:34:069:34:06 AMAM 447628bindex.indd7628bindex.indd 228383 88/4/09/4/09 9:34:069:34:06 AMAM 447628bindex.indd7628bindex.indd 228484 88/4/09/4/09 9:34:069:34:06 AMAM 447628bindex.indd7628bindex.indd 228585 88/4/09/4/09 9:34:069:34:06 AMAM