Book Image

Improving your C# Skills

By : Ovais Mehboob Ahmed Khan, John Callaway, Clayton Hunt, Rod Stephens
Book Image

Improving your C# Skills

By: Ovais Mehboob Ahmed Khan, John Callaway, Clayton Hunt, Rod Stephens

Overview of this book

This Learning Path shows you how to create high performing applications and solve programming challenges using a wide range of C# features. You’ll begin by learning how to identify the bottlenecks in writing programs, highlight common performance pitfalls, and apply strategies to detect and resolve these issues early. You'll also study the importance of micro-services architecture for building fast applications and implementing resiliency and security in .NET Core. Then, you'll study the importance of defining and testing boundaries, abstracting away third-party code, and working with different types of test double, such as spies, mocks, and fakes. In addition to describing programming trade-offs, this Learning Path will also help you build a useful toolkit of techniques, including value caching, statistical analysis, and geometric algorithms. This Learning Path includes content from the following Packt products: • C# 7 and .NET Core 2.0 High Performance by Ovais Mehboob Ahmed Khan • Practical Test-Driven Development using C# 7 by John Callaway, Clayton Hunt • The Modern C# Challenge by Rod Stephens
Table of Contents (26 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
8
What to Know Before Getting Started
17
Files and Directories
18
Advanced C# and .NET Features
Index

Hello World


Stepping back to one of our first examples, take a look at the sample Hello World application. Remember that, depending on the time of day, a different message is displayed to the user. Before noon, the user is greeted with Good morning, and after noon, Good afternoon is returned to the user.

A change in requirements

Depending on the time of day, the user is greeted with Good morning or Good afternoon. To extend the functionality and introduce a new feature, let's address the user with Good evening if the time of day is between 6 p.m. and midnight.

Good evening 

In order to introduce this new feature, begin with the tests. Modification of an existing test will be needed, as well as adding one or more new tests to cover the change in requirements.

Modify the Theory data provided to GivenAfternoon_ThenAfternoonMessage so that only noon through 6 p.m. are included for this test. Now, create a new test method, GivenEvening_ThenEveningMessage:

[Theory]
[InlineData(19)]
[InlineData(20)]...