C# and .NET Core Test Driven Development
- Length: 300 pages
- Edition: 1
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2018-05-18
- ISBN-10: 1788292480
- ISBN-13: 9781788292481
- Sales Rank: #1467827 (See Top 100 Books)
C# and .NET Core Test Driven Development: Dive into TDD to create flexible, maintainable, and production-ready .NET Core applications
Learn how to apply a test-driven development process by building ready C# 7 and .NET Core applications.
Key Features
- Create tests to quickly detect and resolve issues when writing portable code
- Uncover code integration issues that improve code quality using continuous integration
- Set up and use data-driven unit testing to verify your code
Book Description
This book guides developers to create robust, production-ready C# 7 and .NET Core applications through the practice of test-driven development process.
In C# and .NET Core Test-Driven Development, you will learn the different stages of the TDD life cycle, basics of TDD, best practices, and anti-patterns. It will teach you how to create an ASP.NET Core MVC sample application, write testable code with SOLID principles and set up a dependency injection for your sample application. Next, you will learn the xUnit testing framework and learn how to use its attributes and assertions. You’ll see how to create data-driven unit tests and mock dependencies in your code. You will understand the difference between running and debugging your tests on .NET Core on LINUX versus Windows and Visual Studio. As you move forward, you will be able to create a healthy continuous integration process for your sample application using GitHub, TeamCity, Cake, and Microsoft VSTS.
By the end of this book, you will have learned how to write clean and robust code through the effective practice of TDD, set up CI build steps to test and build applications as well as how to package application for deployment on NuGet.
What you will learn
- Write flexible, maintainable, and verifiable code for .NET Core
- Write testable code using SOLID principles and dependency injections
- Recognize the characteristics of a good unit test
- Structure and group your unit test
- Use mock objects to handle dependencies
- Set up an end-to-end continuous integration process
Who This Book Is For
This book is for .NET developers who would like to build efficient applications by implementing principles of test-driven development. C# programming and working knowledge of VS is assumed.
Table of Contents
Chapter 1 Exploring Test-driven Development
Chapter 2 Getting Started with .NET Core
Chapter 3 Write Testable Code
Chapter 4 .NET Core Unit Testing
Chapter 5 Data Driven Unit Tests
Chapter 6 Mocking Dependencies
Chapter 7 Hosting Project and Configure for Continuous Integration
Chapter 8 Create Continuous Integration Build Process
Chapter 9 Testing and Packaging the Application
Title Page Copyright and Credits C# and .NET Core Test-Driven Development Dedication Packt Upsell Why subscribe? PacktPub.com Contributors About the author About the reviewer Packt is searching for authors like you Preface Who this book is for What this book covers To get the most out of this book Download the example code files Download the color images Conventions used Get in touch Reviews Exploring Test-Driven Development Difficulty in maintaining code How does bad code appear? Tight coupling Code smell Bad or broken designs Naming the program elements Source code readability Poor source code documentation Non-tested code What we can do to prevent bad code Loose coupling Sound architecture and design Preventing and detecting code smell C# coding conventions Succinct and proper documentation Why test-driven development? Building for longevity The principles of test-driven development Origin of TDD TDD misconceptions Benefits of TDD Types of tests Unit tests Integration tests System testing User acceptance testing Principles of TDD Writing the tests Writing the code Running the tests Refactoring Doing TDD the wrong way The TDD cycle Summary Getting Started with .NET Core .NET Core framework .NET Standard .NET Core components Supported languages When to choose .NET Core over .NET Framework Cross-platform requirements Ease of deployment Scalability and performance Limitations of .NET Core Structure of a .NET Core application ASP.NET Core MVC project structure wwwroot folder Models, Views, and Controllers folders JSON files – bower.json, appsettings.json, bundleconfig.json Program.cs Startup.cs Tour of Microsoft's Visual Studio Code editor Installing .NET Core on Linux Installing and setting up Visual Studio Code on Linux Exploring Visual Studio Code A look at the new features of C# 7 Tuples enhancement Out keyword Ref locals and returns Ref locals Ref returns Local function Patterns matching Digit separator and binary literal Creating an ASP.NET MVC Core application Summary Writing Testable Code Warning signs when writing untestable code Tight coupling Monster Constructor Classes with more than one responsibility Static objects Law of Demeter Train Wreck The SOLID architecture principles Single Responsibility Principle Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle Setting up a DI container for ASP.NET Core MVC Summary .NET Core Unit Testing The attributes of a good unit test Readable Unit independence Repeatable Maintainable and runs fast Easy to set up, non-trivial, and with good coverage Unit testing framework ecosystem for .NET Core and C# .NET Core testing with MSTest .NET Core testing with NUnit xUnit.net How to configure xUnit.net xUnit.net test runners Test parallelism Unit testing consideration for ASP.NET MVC Core Unit testing controllers Unit testing razor pages Structuring unit tests with xUnit xUnit.net shared test context Live unit testing with Visual Studio 2017 Enterprise Proving unit test results with xUnit.net assertions The test runners available on both .NET Core and Windows ReSharper Summary Data-Driven Unit Tests The benefits of data-driven unit testing Tests brevity Inclusive testing xUnit.net theory attribute for creating data-driven tests Inline data-driven unit tests Property data-driven unit tests MemberData attribute ClassData attribute Integrating data from other sources SqlServerData attribute Custom attribute Summary Mocking Dependencies The benefits of mocking objects Fast running tests Dependencies isolation Refactoring legacy code Wider test coverage The shortcomings of mocking frameworks Interface explosion Extra complexity Mock explosion Hand-rolling mocks versus using a mocking framework Mocking concept Benefits of hand-rolling mocks Mocks and stubs Hand-rolled mock Mocking objects using Moq framework Mocking methods, properties, and callback Properties Matching parameters Events Callbacks Mock customization CallBase Mock repository Implementing multiple interfaces in a mock Verification method and property invocations with Moq LINQ to mocks Advanced Moq features Mocking internal types Summary Continuous Integration and Project Hosting Continuous integration CI workflow Single source code repository Build automation Automated tests Identical test and production environments Daily commit Benefits of CI Quick bugs detection Improved productivity Reduced risks Facilitating continuous delivery CI tools Microsoft Team Foundation Server TeamCity Jenkins Continuous delivery Benefits of continuous delivery Lower risks Quality software products Reduced costs GitHub online project hosting Project hosting Branching with GitHub Flow Pull request Reviewing changes and merging Basic Git commands Configuration commands Initializing repository commands Change commands Branching and merging commands Configuring GitHub WebHooks Consuming WebHooks GitHub WebHook Events and payloads Setting up your first WebHook TeamCity CI platform TeamCity concepts Installing TeamCity Server TeamCity CI workflow Configuring and running build Summary Creating Continuous Integration Build Processes Installing the Cake Bootstrapper Installation PowerShell security Cake Bootstrapper installation steps Step 1 Step 2 Step 3 Writing build scripts in C# Task TaskSetup and TaskTeardown Configuration and preprocessor directives Dependencies Criteria Cake's error handling and finally block LoanApplication build script Cake Extension for Visual Studio Cake templates Task Runner Explorer Syntax highlighting Using Cake tasks to build steps CI with Visual Studio Team Services Setting up a project in VSTS Installing Cake into VSTS Adding a build task Summary Testing and Packaging the Application Executing xUnit.net tests with Cake Executing xUnit.net tests in .NET projects Executing xUnit.net tests in .NET Core projects .NET Core versioning Versioning principle Installer Package manager Docker Semantic Versioning .NET Core packages and metapackages Metapackage Microsoft.AspNetCore.All metapackage Packaging for NuGet distribution dotnet publish command Creating a NuGet package Summary Other Books You May Enjoy Leave a review - let other readers know what you think
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: C# and .NET Core Test Driven Development
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.