List of Listings

Chapter 4. Automated testing

Listing 4.1. State-based test

Listing 4.2. Interaction-based test

Listing 4.3. Expectation lacking meaning

Listing 4.4. Minimum code to pass test

Listing 4.5. Intention-revealing test name

Listing 4.6. Testing to verify desired functionality

Chapter 5. Software metrics and code analysis

Listing 5.1. Method with a cyclomatic complexity of 3

Listing 5.2. Sample NAnt target executing NCover for code coverage

Chapter 7. Bringing better OO practices to the project

Listing 7.1. Sample ASP.NET click event

Listing 7.2. Polymorphism example

Listing 7.3. Sample fluent interface

Listing 7.4. GetData method

Listing 7.5. Classes that use composition rather than inheritance

Listing 7.6. Class with too many responsibilities

Listing 7.7. PrintManager with one responsibility

Listing 7.8. OrderRepository

Listing 7.9. OrderRepository that’s closed for modification

Listing 7.10. Abstraction using Predicate<T>

Listing 7.11. Abstraction using anonymous delegate

Listing 7.12. Abstraction using lambda expressions

Listing 7.13. Sample Decorator

Listing 7.14. Unit test for testing nonexistent code in VenueBooker

Chapter 8. Relayering your application

Listing 8.1. A repeater displaying a list of artists

Listing 8.2. Code-behind for the page listing our artists

Listing 8.3. Service class that provides the list of artists to the code-behind

Listing 8.4. Naive vertical layer implementation

Listing 8.5. Custom logging attribute

Listing 8.6. Traditional code-behind

Chapter 9. Loosen up: Taming your dependencies

Listing 9.1. A service that spell-checks movie reviews

Listing 9.2. Updated SpellCheckDictionary with support for Spanish

Listing 9.3. Updated MovieReviewService to accommodate new languages

Listing 9.4. Our implementation of new languages

Listing 9.5. Updated service with concrete dependencies removed

Listing 9.6. The base SpellCheckDictionary and interface

Listing 9.7. Test fixture to verify the functionality of SpellChecker

Listing 9.8. An alternate test using a mocking framework

Listing 9.9. Class that creates its dependency in the constructor

Listing 9.10. A class that doesn’t require intimate knowledge to create it

Listing 9.11. Another version that takes an interface in its constructor

Listing 9.12. An example of constructor chaining

Listing 9.13. A class that takes advantage of an IoC container

Listing 9.14. Skeleton wrapper for an IoC container

Listing 9.15. Before applying dependency inversion

Listing 9.16. After applying dependency inversion

Chapter 10. Cleaning up the user interface

Listing 10.1. Sample code-behind for a web page

Listing 10.2. View code for a Passive View

Listing 10.3. Presenter for Passive View

Listing 10.4. View code for a Supervising Controller

Listing 10.5. Presenter for a Supervising Controller

Listing 10.6. Code-behind for a page showing a list of bands

Listing 10.7. Test to prove we can create a presenter

Listing 10.8. Presenter class for our band list page

Listing 10.9. Code-behind converted to a view

Listing 10.10. Final view implementation

Listing 10.11. Final presenter implementation

Chapter 11. Refactoring data access

Listing 11.1. Brownfield sample (read at your own risk)

Listing 11.2. Sample stored procedure

Listing 11.3. Similar SQL code

Listing 11.4. Sample generic data access interface

Listing 11.5. Managing connections through business code

Listing 11.6. Class with no persistence ignorance

Listing 11.7. Sample mapping file using an object-relational mapper

Listing 11.8. Walking an object graph to persist all the data

Listing 11.9. Primitive IsDirty implementation

Listing 11.10. Manual version of lazy loading

Listing 11.11. Virtual proxy version of lazy loading

Chapter 12. Managing external system dependencies

Listing 12.1. OnLoad event for control that calls a web service

Listing 12.2. OnLoad event for a different control

Listing 12.3. Implementation of TwilightStarsProxy

Listing 12.4. Updated OnLoad event for our control

Listing 12.5. Skeleton presenter for our controls

Listing 12.6. Skeleton view for control

Listing 12.7. Initial web service returning an array of objects

Listing 12.8. Signatures for WCF service

Listing 12.9. Encapsulated functionality

Listing 12.10. WCF implementation and updated ASMX

Listing 12.11. Loading MP3s using a third-party library

Listing 12.12. Loading WMAs using a third-party library

Listing 12.13. Click event for the Load button

Listing 12.14. Click event we want to have

Listing 12.15. Interface for the SongRepository object

Listing 12.16. GetAllFrom method on the SongRepository implementation

Listing 12.17. Open method on the Excel.Workbooks object

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

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