100% found this document useful (2 votes)
13 views

(Ebook) Professional test-driven development with C# : developing real world applications with TDD by James Bender; Jeff McWherter ISBN 9781118102107, 9781118102114, 9781118102121, 111810210X, 1118102118, 1118102126 pdf download

The document is an ebook titled 'Professional Test-Driven Development with C#' by James Bender and Jeff McWherter, focusing on developing real-world applications using Test-Driven Development (TDD). It covers various aspects of TDD, including unit testing, refactoring, and practical scenarios for web and application testing. The ebook is available for download along with recommendations for additional related ebooks.

Uploaded by

trellvinniqm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
13 views

(Ebook) Professional test-driven development with C# : developing real world applications with TDD by James Bender; Jeff McWherter ISBN 9781118102107, 9781118102114, 9781118102121, 111810210X, 1118102118, 1118102126 pdf download

The document is an ebook titled 'Professional Test-Driven Development with C#' by James Bender and Jeff McWherter, focusing on developing real-world applications using Test-Driven Development (TDD). It covers various aspects of TDD, including unit testing, refactoring, and practical scenarios for web and application testing. The ebook is available for download along with recommendations for additional related ebooks.

Uploaded by

trellvinniqm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

(Ebook) Professional test-driven development

with C# : developing real world applications


with TDD by James Bender; Jeff McWherter ISBN
9781118102107, 9781118102114, 9781118102121,
111810210X, 1118102118, 1118102126 download
https://ebooknice.com/product/professional-test-driven-
development-with-c-developing-real-world-applications-with-
tdd-4106424

Explore and download more ebooks at ebooknice.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

(Ebook) Professional Test Driven Development with C#: Developing Real


World Applications with TDD by James Bender; Jeff McWherter ISBN
9780470643204, 047064320X

https://ebooknice.com/product/professional-test-driven-development-
with-c-developing-real-world-applications-with-tdd-33558838

(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James


ISBN 9781459699816, 9781743365571, 9781925268492, 1459699815,
1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans


Heikne, Sanna Bodemyr ISBN 9789127456600, 9127456609

https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT II Success)


by Peterson's ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042

https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-
arco-master-the-sat-subject-test-math-levels-1-2-2326094

(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth Study:


the United States, 1919-41 2nd Edition by Benjamin Harrison ISBN
9781398375147, 9781398375048, 1398375144, 1398375047

https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044

(Ebook) Modern C++ programming with test-driven development code


better, sleep better by Jeff Langr ISBN 9781937785482, 1937785483

https://ebooknice.com/product/modern-c-programming-with-test-driven-
development-code-better-sleep-better-21965032

(Ebook) Test-Driven Development with React: Apply Test-Driven


Development in Your Applications by Qiu, Juntao ISBN 9781484269725,
1484269721

https://ebooknice.com/product/test-driven-development-with-react-
apply-test-driven-development-in-your-applications-33648056

(Ebook) Test-Driven Development in Swift: Compile Better Code with


XCTest and TDD by Gio Lodi ISBN 9781484270011, 1484270010

https://ebooknice.com/product/test-driven-development-in-swift-
compile-better-code-with-xctest-and-tdd-33171280
FFIRS.indd ii 3/31/11 8:14:17 AM
PROFESSIONAL
TEST-DRIVEN DEVELOPMENT WITH C#

INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

 PART I GETTING STARTED


CHAPTER 1 The Road to Test-Driven Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CHAPTER 2 An Introduction to Unit Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CHAPTER 3 A Quick Review of Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
CHAPTER 4 Test-Driven Development: Let the Tests Be Your Guide . . . . . . . . . . . . 73
CHAPTER 5 Mocking External Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

 PART II PUTTING BASICS INTO ACTION


CHAPTER 6 Starting the Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
CHAPTER 7 Implementing the First User Story . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137
CHAPTER 8 Integration Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

 PART III TDD SCENARIOS


CHAPTER 9 TDD on the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
CHAPTER 10 Testing Windows Communication Foundation Services . . . . . . . . . . . 227
CHAPTER 11 Testing WPF and Silverlight Applications . . . . . . . . . . . . . . . . . . . . . . . . 245

 PART IV REQUIREMENTS AND TOOLS


CHAPTER 12 Dealing with Defects and New Requirements . . . . . . . . . . . . . . . . . . . . 267
CHAPTER 13 The Great Tool Debate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
CHAPTER 14 Conclusions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
APPENDIX TDD Katas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311

FFIRS.indd i 3/31/11 8:14:15 AM


FFIRS.indd ii 3/31/11 8:14:17 AM
PROFESSIONAL

Test-Driven Development with C#

FFIRS.indd iii 3/31/11 8:14:17 AM


FFIRS.indd iv 3/31/11 8:14:17 AM
PROFESSIONAL

Test-Driven Development with C#


DEVELOPING REAL WORLD APPLICATIONS WITH TDD

James Bender
Jeff McWherter

FFIRS.indd v 3/31/11 8:14:18 AM


Professional Test-Driven Development with C#: Developing
Real World Applications with TDD
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-64320-4
ISBN: 978-1-118-10210-7 (ebk)
ISBN: 978-1-118-10211-4 (ebk)
ISBN: 978-1-118-10212-1 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to
the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011,
fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or
promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work
is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional
services. If professional assistance is required, the services of a competent professional person should be sought. Neither
the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or website is
referred to in this work as a citation and/or a potential source of further information does not mean that the author or the
publisher endorses the information the organization or website may provide or recommendations it may make. Further,
readers should be aware that Internet websites listed in this work may have changed or disappeared between when this
work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available
in electronic books.

Library of Congress Control Number: 2011924919

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other
countries, and may not be used without written permission. All other trademarks are the property of their respective
owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

FFIRS.indd vi 3/31/11 8:14:18 AM


For Gayle. Thank you for being so awesome!

—James

To everyone who has believed in me.

—Jeff

To my wonderful wife Courtney and my


two amazing kids, Katie and Jacob.

— Michael

FFIRS.indd vii 3/31/11 8:14:18 AM


FFIRS.indd viii 3/31/11 8:14:19 AM
ABOUT THE AUTHORS

JAMES BENDER is Vice Present of Technology for Improving Enterprises and has been involved in
software development and architecture for 17 years. He has worked as a developer and architect
on everything from small, single-user applications to Enterprise-scale, multi-user systems. His
specialties are .NET development and architecture, SOA, WCF, WF, cloud computing, and agile
development methodologies. He is an experienced mentor and author.
James has spent his career pushing the envelope of software development and pursuing new and
better ways of building applications. He began his career developing credit card processing
applications in C++ on SCO Unix based systems. In the late 90’s James began exploring web
development with both Java based JSP pages and Microsoft’s ASP technologies. He was an early
adopter of .NET starting with the fi rst public beta. He continued exploring the .NET technology
stack, focusing on the distributed computing paradigm made possible by .NET web services, which
naturally evolved into a somewhat obsessive interest in Microsoft’s Windows Communication
Foundation (WCF).
James has been practicing agile-based methodologies since 2003, including Scrum and eXtreme
Programming (XP). At part of this interest in agile methodologies, James began exploring test-driven
development at the same time. He was instrumental in introducing the concepts and techniques used
in agile software development and test-driven development to many developers at his clients and in
the software development community in general.
James is a Microsoft MVP for Visual C#. James is an active member of the development community.
He is the current president of the Central Ohio .NET Developers Group (www.condg.org) and
continues to lead the Columbus Architects Group (www.colarc.org) and is the senior editor of
fi rst-party content for nplus1.org, an educational website aimed toward architects and aspiring
architects. His blog can be found at www.jamescbender.com.

JEFF MCWHERTER is a partner and director of development at Gravity Works Design and
Development, based in a historic office in Lansing Michigan’s Old Town District. A graduate of
Michigan State University with over 12 years of professional software development experience, Jeff
holds numerous certifications from Microsoft including Microsoft Certified Solutions Developer
(MCSD), Microsoft Certified Database Administrator (MCDBA), Microsoft Certified Application
Developer (MCAD), and Microsoft Technology Specialist (MCTS).
In 2010 Jeff was awarded with the Microsoft Most Valuable Professional (MVP) for the third year
in a row. Also in 2010, Jeff received the Ten Over The Next Ten award presented by the Lansing
Regional Chamber of Commerce, which recognizes 10 young professionals to “watch” over the next
10 years. Jeff is also a published author, with Testing ASP.NET Web Applications published by
Wrox Press.

FFIRS.indd ix 3/31/11 8:14:19 AM


ABOUT THE AUTHORS

Along with being an author and software developer, Jeff is very active in developing programming
communities across the country by speaking at conferences and organizing events such as the
Lansing Give Camp, which pairs developers with non-profit organizations for volunteer projects.

MICHAEL EATON has been developing awesome solutions using Microsoft tools and technologies
since 1994, but in 2001 he broke free from the confi nes of the cube farm to go out on his own.
While he lives in the middle- of-nowhere Michigan, he serves clients throughout the Midwest. Well
known for his dislike of web development and box lunches, his focus over the past few years has
been on XAML -based technologies like WPF and Silverlight. He speaks at regional events and user
groups, runs the Kalamazoo X Conference and helps with the Ann Arbor Give Camp. He is also a
C# MVP. When not working on projects or spending time with his family, he treats his World of
Warcraft addiction with ample doses of time on his XBox 360.

FFIRS.indd x 3/31/11 8:14:19 AM


ABOUT THE TECHNICAL EDITOR

MITCHEL SELLERS specializes in software development using Microsoft technologies. He is the CEO
of IowaComputerGurus Inc., a Microsoft C# MVP, a Microsoft Certified Professional, has served
as an author on two books, and served as technical editor on many other books. You will often fi nd
Mitchel interacting with the greater software development community either at events/conferences
or in online discussion forums. To obtain additional information on Mitchel’s professional
experience, certifications, and publications refer to his resume at MitchelSellers.com.

FFIRS.indd xi 3/31/11 8:14:19 AM


FFIRS.indd xii 3/31/11 8:14:19 AM
CREDITS

ACQUISITIONS EDITOR PRODUCTION MANAGER


Paul Reese Tim Tate

PROJECT EDITOR VICE PRESIDENT AND EXECUTIVE GROUP


Sydney Jones PUBLISHER
Richard Swadley
TECHNICAL EDITORS
Jeff McWherter VICE PRESIDENT AND EXECUTIVE PUBLISHER
Mitchell Sellers Barry Pruett

PRODUCTION EDITOR ASSOCIATE PUBLISHER


Rebecca Anderson Jim Minatel

COPY EDITOR PROJECT COORDINATOR, COVER


Gayle Johnson Katie Crocker

EDITORIAL DIRECTOR PROOFREADER


Robyn B. Siesky Carrie Hunter, Word One New York

EDITORIAL MANAGER INDEXER


Mary Beth Wakefield J & J Indexing

FREELANCER EDITORIAL MANAGER COVER DESIGNER


Rosemarie Graham Michael E. Trent

ASSOCIATE DIRECTOR OF MARKETING COVER IMAGE


David Mayhew © iStock / technotr

FFIRS.indd xiii 3/31/11 8:14:19 AM


FFIRS.indd xiv 3/31/11 8:14:20 AM
ACKNOWLEDGMENTS

I WANT TO START BY THANKING MY GIRLFRIEND (with any luck, fiancé by the time you are reading
this) Gayle. She has been very supportive and EXTREMELY understanding during the process of
writing this book. More than she should have had to be. Thank you.
I want to thank my parents for making this book possible by making me possible. My mother is so
proud she’ll read every page of this book. Bless her heart. I hope she’s still proud when she realizes
I lied and this is NOTHING like a Stephen King novel.
In the understanding and supporting department I would also like to thank Daniel Grey, Mark
Kovacevich, Jeff Perry and everyone else at Improving Enterprises. I’d also like to thank Pete
Klassen. We miss you man!
I’d like to thank Jeff McWherter and Michael Eaton for their contributions to this book. Jeff; thanks
for taking some of the load off. Mike; thank you for pushing me to include the “non-web” people.
I’d also like to thank my editor Sydney for making this book look like I know how to write.
Brian Prince; thank you for pushing me to get involved in the development community. I was going
to write something funny here, but I couldn’t think of anything. I’ll getcha in the next one.
When I was presented with the opportunity to write this book, I almost said no. I want to thank
Ted Neward for talking me into it. So, this is kinda your fault too.
I want to thank my partners in NPlus1.org Mike Wood and Chris Woodruff for picking up my slack
of the past several months while I worked on this.
Long list of general thanks: Brahma Ghosh, Brian Sherwin, Bill Sempf, Jeff Blankenburg, Carey
Payette, Caleb Jenkins, Jennifer Marsman, Sarah & Kevin Dutkiewicz, Steve Harman, Josh
Holmes. Thanks to Matt Groves for pimping this book almost as much as I did. I’m sure I forgot
someone, so I apologize.

—James

FIRST AND FOREMOST I WOULD LIKE TO THANK my very patient wife Carla. Thank you for all the
support, patience, and understanding you have provided to me for all of my endeavors. Thank you to
the staff at Gravity Works — Amelia Marschall, Lauren Colton, Scott Gowell and Dave Smith — for
answering my random questions that appeared to come out of nowhere. And lastly I would like to
thank James for his hard work, dedication, and friendship.

—Jeff

FFIRS.indd xv 3/31/11 8:14:20 AM


FFIRS.indd xvi 3/31/11 8:14:20 AM
CONTENTS

INTRODUCTION xxv

PART I: GETTING STARTED

CHAPTER 1: THE ROAD TO TEST-DRIVEN DEVELOPMENT 3

The Classical Approach to Software Development 4


A Brief History of Software Engineering 4
From Waterfall to Iterative and Incremental 5
A Quick Introduction to Agile Methodologies 6
A Brief History of Agile Methodologies 6
The Principles and Practices of Test-Driven Development 7
The Concepts Behind TDD 8
TDD as a Design Methodology 8
TDD as a Development Practice 8
The Benefits of TDD 9
A Quick Example of the TDD Approach 10
Summary 17
CHAPTER 2: AN INTRODUCTION TO UNIT TESTING 19

What Is a Unit Test? 19


Unit Test Definition 20
What Is Not a Unit Test? 20
Other Types of Tests 22
A Brief Look at NUnit 24
What Is a Unit Test Framework? 24
The Basics of NUnit 25
Decoupling with Mock Objects 28
Why Mocking Is Important 28
Dummy, Fake, Stub, and Mock 29
Best and Worst Practices 35
A Brief Look at Moq 36
What Does a Mocking Framework Do? 36
A Bit About Moq 36
Moq Basics 36
Summary 40

TOC.indd xvii 3/31/11 8:16:30 AM


CONTENTS

CHAPTER 3: A QUICK REVIEW OF REFACTORING 41

Why Refactor? 42
A Project’s Lifecycle 42
Maintainability 43
Code Metrics 43
Clean Code Principles 45
OOP Principles 45
Encapsulation 45
Inheritance 46
Polymorphism 48
The SOLID Principles 49
The Single Responsibility Principle 50
The Open/Close Principle 50
The Liskov Substitution Principle 51
The Interface Segregation Principle 51
The Dependency Inversion Principle 52
Code Smells 52
What Is a Code Smell? 52
Duplicate Code and Similar Classes 53
Big Classes and Big Methods 54
Comments 55
Bad Names 56
Feature Envy 57
Too Much If/Switch 58
Try/Catch Bloat 59
Typical Refactoring 60
Extract Classes or Interfaces 60
Extract Methods 62
Rename Variables, Fields, Methods, and Classes 66
Encapsulate Fields 67
Replace Conditional with Polymorphism 68
Allow Type Inference 71
Summary 71

CHAPTER 4: TEST-DRIVEN DEVELOPMENT: LET THE TESTS


BE YOUR GUIDE 73

It Starts with the Test 74


Red, Green, Refactor 76
The Three Phases of TDD 77
The Red Phase 77
The Green Phase 78

xviii

TOC.indd xviii 3/31/11 8:16:30 AM


Exploring the Variety of Random
Documents with Different Content
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like