You are previewing Test-Driven Development in Microsoft® .NET.
O'Reilly logo
Test-Driven Development in Microsoft® .NET

Book Description

Apply the concepts and techniques of Test-Driven Development to building Microsoft .NET–connected applications. Two experts in agile software development demonstrate by example how to use tests to drive lean, efficient coding and better design.

Table of Contents

  1. Test-Driven Development in Microsoft® .NET
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. Foreword
    3. Acknowledgments
    4. Introduction
      1. What Are the Benefits of Using Tests?
        1. An Example
        2. Organization
      2. How to Use This Book
        1. If You Have Never Used NUnit Before
        2. If You Are a Manager or Business Analyst
      3. Small Steps—A Personal Story
      4. Companion Web Site
    5. I. Test-Driven Development Primer
      1. 1. Test-Driven Development Practices
        1. What Is Test-Driven Development?
          1. Test Types
            1. Programmer Tests
            2. Customer Tests
          2. Simple Design
          3. Refactoring
        2. Process
          1. Test List
          2. Red/Green/Refactor
        3. Summary
      2. 2. Test-Driven Development in .NET—By Example
        1. The Task
        2. Test List
          1. Choosing the First Test
        3. Red/Green/Refactor
          1. Test 1: Create a Stack and verify that IsEmpty is true.
          2. Test 2: Push a single object on the Stack and verify that IsEmpty is false.
          3. Test 3: Push a single object, Pop the object, and verify that IsEmpty is true.
          4. Test 4: Push a single object, remembering what it is; Pop the object, and verify that the two objects are equal.
          5. Test 5: Push three objects, remembering what they are; Pop each one, and verify that they are correct.
          6. Test 6: Pop a Stack that has no elements.
          7. Test 7: Push a single object and then call Top. Verify that IsEmpty returns false.
          8. Test 8: Push a single object, remembering what it is; and then call Top. Verify that the object that is returned is equal to the one that was pushed.
          9. Test 9: Push multiple objects, remembering what they are; call Top, and verify that the last item pushed is equal to the one returned by Top.
          10. Test 10: Push one object and call Top repeatedly, comparing what is returned to what was pushed.
          11. Test 11: Call Top on a Stack that has no elements.
          12. Test 12: Push null onto the Stack and verify that IsEmpty is false.
          13. Test 13: Push null onto the Stack, Pop the Stack, and verify that the value returned is null.
          14. Test 14: Push null onto the Stack, call Top, and verify that the value returned is null.
        4. Summary
      3. 3. Refactoring—By Example
        1. The Sieve
          1. Before Refactoring the Code: Make Sure It All Works
            1. Refactoring Cycle
          2. Refactoring 0: Remove Unneeded Code
          3. Refactoring 1: Rename Method
          4. Refactoring 2: Add a Test
            1. When Are We Finished?
          5. Refactoring 3: Hide Method
          6. Refactoring 4: Replace Nested Conditional with Guard Clauses
          7. Refactoring 5: Inline Method
          8. Refactoring 6: Rename Variable
          9. Refactoring 7: Collapse Loops
          10. Refactoring 8: Remove Dead Code
          11. Refactoring 9: Collapse Loops (Again)
            1. We Can Do Some More...
          12. Refactoring 10: Reduce Local Variable Scope
          13. Refactoring 11: Replace Temp with Query
          14. Refactoring 12: Remove Dead Code
          15. Refactoring 13: Extract Method
          16. Refactoring 14: Extract Method (Again)
          17. Refactoring 15: Reduce Local Variable Scope
          18. Refactoring 16: Convert Procedural Design to Objects
          19. Refactoring 17: Keep the Data Close to Where It Is Used
        2. Summary
    6. II. Test-Driven Development Example
      1. 4. The Media Library Example
        1. The Skinny
          1. Existing Database
            1. Entities
            2. Entity Relationships
        2. The First Feature
        3. Additional Features
      2. 5. Programmer Tests: Using TDD with ADO.NET
        1. Testing the Database Access Layer
        2. The Task
          1. Connecting to the Database
            1. A Small Improvement
            2. We’re Not Finished Yet
              1. Separating the Tests
          2. Individual Entities in Isolation
            1. Defining a Typed DataSet for the Recording Database
            2. Artist Gateway
              1. Primary Key Management
              2. ArtistFixture.cs
            3. Genre Gateway
              1. ConnectionFixture.cs
              2. IdGeneratorFixture.cs
            4. Finishing Up
        3. Testing Relationships Between Entities
          1. Track-Recording Relationship
        4. Retrieve a Recording
        5. Test Organization
        6. Summary
      3. 6. Programmer Tests: Using TDD with ASP.NET Web Services
        1. The Task
          1. Test List
        2. Data Transformation
          1. Data Transfer Object
            1. Recording.xsd
            2. Checking the "Title" Field
            3. Building an Assembler
            4. Mapping the Relationships in the Assembler
        3. Database Catalog Service
        4. Web Service Tests
          1. Web Service Producer and Consumer Infrastructure
            1. Web Service Producer
            2. Web Service Consumer
            3. Running the Test
            4. Web Services Security
        5. Almost Done
          1. The Bad News
        6. Summary
          1. Emerging Architecture
      4. 7. Customer Tests: Completing the First Feature
        1. Are We Done?
          1. Customer Tests
        2. Customer Tests for Recording Retrieval
          1. Script 1. Retrieve an existing recording and verify its content
          2. Script 2. Retrieve a nonexistent recording
        3. Automating Customer Tests
          1. FIT Overview
          2. Connecting FIT to the Implementation
          3. Automation with FIT
            1. Start Command
            2. Enter Action
            3. Check Action
            4. CatalogAdapter
            5. Running the Script
            6. Continuing with the Automation
            7. Verifying Track Information
            8. Verifying Review Information
            9. Invalid ID Script
            10. Automation Summary
        4. Reconciling Viewpoints
          1. Track Duration
          2. Recording Duration
        5. Summary
      5. 8. Driving Development with Customer Tests
        1. The FIT Script
          1. Add a review to an existing recording
          2. Implementing Add/Delete Review
            1. Test List
            2. Changing the Catalog Class
            3. Changing the CatalogService Class
            4. Updating DatabaseCatalogService
            5. Updating CatalogServiceInterface
            6. Fixing AddReviewAdapter
        2. Summary
      6. 9. Driving Development with Customer Tests: Exposing a Failure Condition
        1. Programmer Tests
          1. Propagating the Exception
          2. Implementing a SOAP Fault
        2. Summary
      7. 10. Programmer Tests: Using Transactions
        1. Programmer Tests
          1. Transaction Manager
            1. Integrating TransactionManager with the Tests and Application Code
        2. Programmer Tests: Catalog Class
          1. Refactoring the Catalog class
        3. Summary
      8. 11. Service Layer Refactoring
        1. The Problem
          1. What’s Wrong?
          2. The Solution
        2. Summary
      9. 12. Implementing a Web Client
        1. Testing User Interfaces
        2. The Task
        3. Implementing Search
          1. Implementing the Search Service
          2. Implementing the Search Page
          3. Binding the Results to a Repeater Web Control
            1. Creating the Page
          4. Enough of This Stub
        4. Summary
    7. III. Appendixes
      1. A. NUnit Primer
        1. NUnit Quick Start
          1. Step 1. Create Visual Studio Project for your test code.
          2. Step 2. Add a reference to the NUnit Framework.
          3. Step 3. Add a class to the project.
          4. Step 4. Set up your Visual Studio Project to use the NUnit-Gui test runner.
          5. Step 5. Compile and run your test.
          6. Step 6. Become familiar with the NUnit-Gui layout.
        2. NUnit Core Concepts
          1. Test Case
            1. Test Suite
            2. Test Fixture
            3. Tests and Test Fixtures
            4. Working with Test Runners
            5. Assertions
        3. Other NUnit Capabilities
          1. Using SetUp/TearDown Attributes
          2. Using ExpectedException
          3. Using the Ignore Attribute
          4. Using TestFixtureSetUp/TestFixtureTearDown
          5. Test Life-Cycle Contract
        4. Using the Visual Studio .NET Debugger with NUnit-Gui
      2. B. Transactions in ADO.NET
        1. Transaction Management
          1. Manual Transaction Management
          2. Automatic Transaction Management
        2. Transaction Participation
      3. C. Bibliography
        1. Bibliography
      4. About the Authors
    8. Index
    9. SPECIAL OFFER: Upgrade this ebook with O’Reilly