C# and .NET Core Test-Driven Development
Dive into TDD to create flexible, maintainable, and production-ready .NET Core applications
Ayobami Adewole
BIRMINGHAM - MUMBAI
C# and .NET Core Test-Driven Development
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Merint Mathew
Acquisition Editor: Chaitanya Nair
Content Development Editor: Priyanka Sawant
Technical Editor: Ruvika Rao
Copy Editor: Safis Editing
Project Coordinator: Vaidehi Sawant
Proofreader: Safis Editing
Indexer: Rekha Nair
Graphics: Jason Monteiro
Production Coordinator: Deepika Naik
First published: May 2018
Production reference: 1160518
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78829-248-1
www.packtpub.com
To my mother, Modupe Adewole, and my father, Adegoke Adewole, for believing in me and buying me my first computer. Also, to my siblings and partner for their love and support.
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Ayobami Adewole comes from Ibadan city in Nigeria. He is very passionate about computers and what they can be programmed to do. He is an ardent lover of the .NET stack of technologies and has developed several cutting-edge enterprise applications using the platform.
He offers consultancy services on VoIP and Unified Communication technologies, Customer Relationship Management Systems, Business Process Automation, Enterprise Application Development, and Quality Assurance.
I would like to specially thank Chaitanya Nair, Priyanka Sawant, Ruvika Rao, and the other staff at Packt for their dedication, patience, and support throughout the course of writing the book. I would also like to thank Gaurav Aroraa for taking the time to review the book.
Special thanks to my parents, siblings, and partner for their unwavering support while I was writing the book.
About the reviewer
Gaurav Aroraa has an MPhil in computer science. He is a Microsoft MVP, lifetime member of Computer Society of India (CSI), advisory member of IndiaMentor, certified as a Scrum trainer/coach, XEN for ITIL-F, and APMG for PRINCE-F and PRINCE-P. He is an open source developer, contributor to TechNet Wiki, and the founder of Ovatic Systems Private Limited. During his 20 year career, he has mentored thousands of students and industry professionals. In addition to this, he's written 100+ white papers for research scholars and various universities across the globe.
I'd like to thank my wife, Shuby Arora, and my angel daughter, Aarchi Arora, as well as the team at Packt.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Preface
How do you verify that your cross-platform .NET Core application will work wherever it is deployed? As your business, team, and the technical environment evolves, can your code evolve with it? You can simplify your code base, make finding and fixing bugs trivial, and ensure your code does what you think it does by following the principles of test-driven development.
This book guides developers through the process of creating robust, production-ready C# 7 and .NET Core applications by establishing a professional test-driven development process. To do this, you will begin by learning the stages of the TDD life cycle, some best practices, and some anti-patterns.
After covering the basics of TDD in the first chapter, you will get right into creating a sample ASP.NET Core MVC application. You will learn how to write testable code with SOLID principles, and set up dependency injection.
Next, you will learn how to create unit tests using the xUnit.net testing framework, and how to use its attributes and assertions. Once you have the basics in place, you will learn how to create data-driven unit tests and how to mock dependencies in your code.
At the end of this book, you will wrap up by creating a healthy continuous integration process, using GitHub, TeamCity, VSTS, and Cake. Finally, you will modify the Continuous Integration build to test, version, and package a sample application.
Who this book is for
This book is for .NET developers who would like to build quality, flexible, easy-to-maintain, and efficient enterprise applications by implementing the principles of test-driven development.
What this book covers
, Exploring Test-Driven Development,
Next page