万本电子书0元读

万本电子书0元读

顶部广告

C# and .NET Core Test Driven Development电子书

售       价:¥

7人正在读 | 0人评论 9.8

作       者:Ayobami Adewole

出  版  社:Packt Publishing

出版时间:2018-05-18

字       数:34.8万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Learn how to apply a test-driven development process by building ready C# 7 and .NET Core applications. About This Book ? 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 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. 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 In Detail 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. Style and approach The book explores the concepts of test driven development in depth so readers can apply these proven techniques to build sophisticated software with C# and .NET.
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部