Professional Test Driven Development with C Developing Real World Applications with TDD 1st Edition James Bender instant download
Professional Test Driven Development with C Developing Real World Applications with TDD 1st Edition James Bender instant download
https://ebookname.com/product/professional-test-driven-
development-with-c-developing-real-world-applications-with-
tdd-1st-edition-james-bender-2/
https://ebookname.com/product/professional-test-driven-
development-with-c-developing-real-world-applications-with-
tdd-1st-edition-james-bender/
https://ebookname.com/product/test-driven-development-for-
embedded-c-1st-edition-james-w-grenning/
https://ebookname.com/product/test-driven-net-development-with-
fitnesse-2nd-edition-edition-gojko-adzic/
https://ebookname.com/product/the-ploy-of-instinct-victorian-
sciences-of-nature-and-sexuality-in-liberal-governance-1st-
edition-frederickson/
Crafting Rails Applications Expert Practices for
Everyday Rails Development 1st Edition Jose Valim
https://ebookname.com/product/crafting-rails-applications-expert-
practices-for-everyday-rails-development-1st-edition-jose-valim/
https://ebookname.com/product/american-public-policy-promise-and-
performance-b-guy-peters/
https://ebookname.com/product/injection-treatments-in-cosmetic-
surgery-1st-edition-benjamin-ascher/
https://ebookname.com/product/between-transcendence-and-
historicism-the-ethical-nature-of-the-arts-in-hegelian-
aesthetics-brian-k-etter/
https://ebookname.com/product/medical-nutrition-disease-a-case-
based-approach-3rd-edition-lisa-hark/
Psychology of Terrorism Condensed Edition Coping with
the Continuing Threat Contemporary Psychology Chris E.
Stout
https://ebookname.com/product/psychology-of-terrorism-condensed-
edition-coping-with-the-continuing-threat-contemporary-
psychology-chris-e-stout/
PROFESSIONAL
TEST-DRIVEN DEVELOPMENT WITH C#
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
PROFESSIONAL
James Bender
Jeff McWherter
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
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)
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.
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.
For Gayle. Thank you for being so awesome!
—James
—Jeff
— Michael
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.
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.
x
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.
CREDITS
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
CONTENTS
INTRODUCTION xxv
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
xviii
CONTENTS
xix
CONTENTS
xx
CONTENTS
xxi
CONTENTS
xxii
CONTENTS
INDEX 311
xxiii
Exploring the Variety of Random
Documents with Different Content
Who was the traitor, Cromwell, then;
So I care not what they do with me.
In Glen-Prosen we rendezvous'd,
March'd to Glenshie by night and day,
And took the town of Aberdeen,
And met the Campbells in their array.40
There's some say that we wan, and some say that they wan,
And some say that nane wan at a', man;
But one thing I'm sure, that at Sherra-muir
A battle there was that I saw, man.
And we ran, and they ran, and they ran, and we ran,5
But Florence ran fastest of a', man.
Sir John Schaw, that great knight, with broad sword most bright,15
On horseback he briskly did charge, man;
A hero that's bold, none could him withhold,
He stoutly encounter'd the targemen.
And we ran, &c.
For the cowardly Whittam, for fear they should cut him,
Seeing glittering broad swords with a pa', man,
And that in such thrang, made Baird edicang,21
And from the brave clans ran awa, man.
And we ran, &c.
Wi' the Earl o' Seaforth, and the Cock o' the North;95
But Florence ran fastest of a', man,
Save the laird o' Phinaven, who sware to be even
W' any general or peer o' them a', man.]
And we ran, &c.
6. Florence was the Marquis of Huntly's horse. Hogg.
7-10. Lord Belhaven, the Earl of Leven, and the Earls of Rothes and
Haddington, who all bore arms as volunteers in the royal army.
Major-General Joseph Wightman, who commanded the centre of the
royal army.
11-14. John, fifth Duke of Roxburgh, a loyal volunteer. Archibald,
Duke of Douglas, who commanded a body of his vassals in the royal
army. Hugh Campbell, third Earl of Loudoun, of the royal army. The
Earl of Ilay, brother to the Duke of Argyle. He came up to the field
only a few hours before the battle, and had the misfortune to be
wounded.
15. Sir John Shaw of Greenock, an officer in the troop of volunteers,
noted for his keen Whiggish spirit.
17. Major-General Whitham, who commanded the left wing of the
King's army.
39-42. James, Lord Drummond, eldest son of the Earl of Perth, was
Lieutenant-general of horse under Mar, and behaved with great
gallantry. William Mackenzie, fifth Earl of Seaforth. The Viscount
Kilsyth. The Viscount Strathallan. Lieutenant-general George
Hamilton, commanding under the Earl of Mar.
27-30. James, Earl of Panmure. The Honourable Harry Maule of
Kellie, brother to the foregoing, whom he recaptured after the
engagement.
31-4. The Earls of Marischal and Linlithgow. The Chief of Glengary.
Thomas Drummond of Logie Almond.
35-8. The Earl of Strathmore, killed in the battle. The Chief of
Clanranald. The Earl of Forfar—on the King's side—wounded in the
engagement.
43. James, fifth Earl of Southesk. The Marquis of Tullibardine, eldest
son of the Duke of Athole.
47-50. Lord Rollo. The Earl of Kintore. Lord Pitsligo. Lord Ogilvie, son
of the Earl of Airly. Bruce, Laird of Clackmannan—the husband, I
believe, of the old lady who knighted Robert Burns with the sword of
Bruce, at Clackmannan Tower. Lord Burleigh.
51. Major William Clephane. Alexander Robertson of Struan, chief of
the Robertsons.
55. Alexander, Marquis of Huntly, afterwards Duke of Gordon. The
Master of Sinclair.
59-74. These four stanzas seem to refer to a circumstance reported
at the time; namely, that a person had left the Duke of Argyle's
army, and joined the Earl of Mar's, before the battle, intending to act
as a spy; and that, being employed by Mar to inform the left wing
that the right was victorious, he gave a contrary statement, and,
after seeing them retire accordingly, went back again to the royal
army.
75. The celebrated Rob Roy. This redoubted hero was prevented, by
mixed motives, from joining either party. He could not fight against
the Earl of Mar, consistent with his conscience, nor could he oppose
the Duke of Argyle, without forfeiting the protection of a powerful
friend.
93. This point is made at the expense of a contradiction. See v. 27.
95-7. The Cock of the North is an honorary popular title of the Duke
of Gordon. Carnegy of Finhaven.
LORD DERWENTWATER.
James Radcliff, Earl of Derwentwater, fell into the hands of the
Whigs at the surrender of Preston, on the very day of the battle of
Sheriff-Muir, and suffered death in February, 1716, for his
participation in the rebellion. Smollet has described him as an
amiable youth,—brave, open, generous, hospitable, and humane.
"His fate drew tears from the spectators, and was a great misfortune
to the country in which he lived. He gave bread to multitudes of
people whom he employed on his estate;—the poor, the widow, and
the orphan rejoiced in his bounty." (History of England, quoted by
Cromek.) We are told that the aurora borealis was remarkably vivid
on the night of the earl's execution, and that this phenomenon is
consequently still known in the north by the name of "Lord
Derwentwater's Lights."
Although this ballad is said to have been extremely popular in the
North of England for a long time after the event which gave rise to
it, no good copy has as yet been recovered. The following was
obtained by Motherwell (Minstrelsy, p. 349) from the recitation of an
old woman. Another copy, also from recitation but "restored to
poetical propriety," is given in the Gentleman's Magazine, for June,
1825 (p. 489), and fragments of a third in Notes and Queries, vol.
xii. p. 492. Two spurious ballads on the death of Lord Derwentwater
have been sometimes received as genuine: one by Allan
Cunningham, first published in Cromek's Nithsdale and Galloway
Song, p. 129, another (Lord Derwentwater's Goodnight) by Surtees,
printed in Hogg's Jacobite Relics, ii. 31. Still another modern
imitation is Young Ratcliffe, in Sheldon's Minstrelsy of the English
Border, p. 401.
There is a ballad on the disgraceful capitulation of Preston in Hogg's
Jacobite Relics, ii. 102, also, Northumberland Garland, p. 85,
beginning "Mackintosh was a soldier brave."
Mr. Laing, in his Early Metrical Tales (p. xlv.) speaks of an edition
printed in the year 1668 as being "in the curious library of old Robert
Myln." No copy is now known to exist of a date anterior to that
which was published in Ramsay's Evergreen. Of the age of this copy
the most opposite opinions have been maintained, some regarding
the ballad as contemporary with the event, and others insinuating
that Ramsay, or one of his friends, is chargeable with the authorship.
This last notion has no other ground than the freedom which
Ramsay notoriously took with his texts, and that freedom has very
likely been exercised in the present case. We shall, perhaps, be
going quite as far as is prudent, if we acknowledge that this may be
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.
ebookname.com