Title Page Copyright and Credits Improving your C# Skills About Packt Why subscribe? Packt.com Contributors About the authors 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 Conventions used Get in touch Reviews What's New in .NET Core 2 and C# 7? Evolution of .NET New improvements in .NET Core 2.0 Performance improvements RyuJIT compiler in .NET Core Profile guided optimization Simplified packaging Upgrading path from .NET Core 1.x to 2.0 1. Install .NET Core 2.0 2. Upgrade TargetFramework 3. Update .NET Core SDK version 4. Update .NET Core CLI Changes in ASP.NET Core Identity Exploring .NET Core CLI and New Project Templates Understanding .NET Standard Versioning of .NET Standard New improvements in .NET Standard 2.0 More APIs in .NET Standard 2.0 Compatibility mode Creating a .NET Standard library What comes with ASP.NET Core 2.0 ASP.NET Core Razor Pages Automatic Page and View compilation on publishing Razor support for C# 7.1 Simplified configuration for Application Insights Pooling connections in Entity Framework Core 2.0 New features in C# 7.0 Tuples Patterns Constant pattern Type pattern Var pattern Reference returns Expression bodied member extended Creating Local Functions Out variables Async Main Writing quality code Summary Understanding .NET Core Internals and Measuring Performance .NET Core internals CoreFX CoreCLR Understanding MSIL, CLI, CTS, and CLS How the CLR works From compilation to execution – Under the hood Garbage collection Generations in GC .NET Native and JIT compilation Utilizing multiple cores of the CPU for high performance How releasing builds increases performance Benchmarking .NET Core 2.0 applications Exploring BenchmarkDotNet How it works Setting parameters Memory diagnostics using BenchmarkDotnet Adding configurations Summary Multithreading and Asynchronous Programming in .NET Core Multithreading versus asynchronous programming Multithreading in .NET Core Multithreading caveats Threads in .NET Core Creating threads in .NET Core Thread lifetime The thread pool in .NET Thread synchronization Monitors Task parallel library (TPL) Creating a task using TPL Task-based asynchronous pattern (TAP) Naming convention Return type Parameters Exceptions Task status Task cancellation Task progress reporting Implementing TAP using compilers Implementing TAP with greater control over Task Design patterns for parallel programming Pipeline pattern Dataflow pattern Producer/consumer pattern Parallel.ForEach Parallel LINQ (PLINQ) Summary Securing and Implementing Resilience in .NET Core Applications Introduction to resilient applications Resilient policies Reactive policies Implementing the retry pattern Implementing circuit breaker Wrapping the circuit breaker with retry Fallback policy with circuit breaker and retry Proactive policies Implementing timeout Implementing caching Implementing health checks Storing sensitive information using Application Secrets Protecting ASP.NET Core APIs SSL (Secure Socket Layer) Enabling SSL in an ASP.NET Core application Preventing CSRF (Cross-Site Request Forgery) attacks Reinforcing security headers Adding the HTTP strict transport security header Adding the X-Content-Type-Options header Adding the X-Frame-Options header Adding the X-Xss-Protection header Adding the Content-Security-Policy header Adding the referrer-policy header Enabling CORS in the ASP.NET Core application Authentication and authorization Using ASP.NET Core Identity for authentication and authorization Authentication Authorization Implementing authentication and authorization using the ASP.NET Core Identity framework Adding more properties in the user table Summary Why TDD is Important First, a little background John's story on TDD Clayton's story on TDD So, what is TDD? An approach to TDD  An alternative approach  The process Red, green, and refactor Coder's block Why should we care? Arguments against TDD Testing takes time Testing is expensive Testing is difficult We don't know how Arguments in favor of TDD Reduces the effort of manual testing Reduces bug count Ensures some level of correctness Removes the fear of refactoring A better architecture  Faster development  Different types of test Unit tests  Acceptance tests  Integration tests  End to end tests  Quantity of each test type  Parts of a unit test Arrange Act Assert Requirements  Why are they important?  User stories  Role  Request  Reason  Gherkin  Givens  When  Then  Our first tests in C# Growing the application with tests Our first tests in JavaScript Why does it matter? Summary Setting Up the .NET Test Environment Installing the .NET Core SDK Getting set up with VS Code Downloading the IDE Installing the VS Code Adding extensions Creating a project in VS Code Setting up Visual Studio Community Downloading Visual Studio Community Installing Visual Studio Community Switching to xUnit Code katas FizzBuzz Creating the test project The Given3ThenFizz test The Given5ThenBuzz test The Given15ThenFizzBuzz test The Given1Then1 test Theories Solution to the FizzBuzz Problem What is Speaker Meet? Web API project Listing Speakers (API) Requirements A new test file Summary Setting Up a JavaScript Environment Node.js What is Node? Why do we need Node? Installing Node Linux Mac OSX Windows NPM What is NPM? Why do we need NPM? Installing NPM? A quick introduction to JavaScript IDEs Visual Studio Code Why Visual Studio Code? Installing Visual Studio Code Linux Mac Windows Installing the plugins you will need Configuring the testing environment WebStorm Why WebStorm? Installing WebStorm Linux Mac Windows Installing the plugins you will need Configuring the testing environment Create React App What is Create React App? Installing the global module Creating a React application Running the Create React App script Mocha and Chai Jest Mocha Chai Sinon Enzyme Ejecting the React app Configuring to use Mocha and Chai A quick kata to check our test setup The requirements The execution Starting the kata Summary What to Know Before Getting Started Untestable code Dependency Injection Static Singleton Global state Abstracting third-party software Test doubles Mocking frameworks The SOLID principles The Single Responsibility Principle The Open/Closed principle The Liskov Substitution principle The Interface Segregation Principle The Dependency Inversion principle Timely greeting Fragile tests False positives and false failures Abstract DateTime Test double types Dummies Dummy logger Example in C# Example in JavaScript Stubs Example in C# Example in JavaScript Spies Example in C# Example in JavaScript Mocks Example in C# Example in JavaScript Fakes Example in C# Example in JavaScript N-Tiered example Presentation layer Moq Business layer Summary Tabula Rasa – Approaching an Application with TDD in Mind Where to begin Yak shaving Big design up front A clean slate One bite at a time Minimum Viable Product Different mindset YAGNI – you aren't gonna need it Test small Devil's advocate Test negative cases first When testing is painful A spike Assert first Stay organized Breaking down Speaker Meet Speakers Communities Conferences Technical requirements Summary Testing JavaScript Applications Creating a React app Ejecting the app Configuring Mocha, Chai, Enzyme, and Sinon  The plan Considering the React component Looking at Redux testability The store Actions Reducers Unit-testing an API service Speaker listing A mock API service The Get All Speakers action Testing a standard action Testing a thunk The Get All Speakers reducer The Speaker listing component Speaker detail Adding to the mock API Service The Get Speaker action The Get Speaker reducer The Speaker Detail component Summary Exploring Integrations Implementing a real API service Replacing the mock API with the real API service Using Sinon to mock Ajax responses Fixing existing tests Mocking the server Application configuration End-to-end integration tests Benefits Detriments How much end-to-end testing should you do? Configuring the API project Integration test project Where to begin? Verifying the repository calls into the DB context InMemory database Adding speakers to the InMemory database Verify that the service calls the DB through the repository ContextFixture Verify the API calls into the service TestServer ServerFixture Summary Changes in Requirements Hello World A change in requirements Good evening  FizzBuzz A new feature Number not found TODO app   Mark complete Adding tests Production code But don't remove from the list! Adding tests Production code Changes to Speaker Meet Changes to the back-end Changes to the front-end  Sorted by rating on client side What now? Premature optimization Summary The Legacy Problem What is legacy code? Why does code go bad? When does a project become a legacy? What can be done to prevent legacy decay? Typical issues resulting from legacy code Unintended side effects Open Closed Principle and legacy code Liskov Substitution Principle and legacy code Over-optimization Overly clever code Tight coupling to third-party software Issues that prevent adding tests  Direct dependence on framework and third-party code  Law of Demeter Work in the constructor Global state Static methods Large classes and functions  Dealing with legacy problems Safe refactoring Converting values to variables Extracting a method Extracting a class Abstracting third-party libraries and framework code Early tests Gold standard tests Testing all potential outcomes  Moving forward  Fixing bugs  Free to do unsafe refactoring  Summary Unraveling a Mess Inheriting code The game A change is requested Life sometimes hands you lemons Getting started Abstracting a third-party class Unexpected Input Making sense of the madness Final beautification Ready for enhancements Summary Geometry Problems 1. Monte Carlo π 2. Newton's π 3. Bisection root-finding 4. Newton's method 5. Gaussian elimination 6. Monte Carlo integration 7. Rectangle rule integration 8. Trapezoid rule integration 9. Arrowheads 10. Line-line intersection 11. Point-line distance 12. Point-segment distance 13. Segment-segment distance 14. Circle selection 15. Line-circle intersection 16. Circle-circle intersection 17. Circle-line tangents 18. Polygon area 19. Point in a polygon 20. Convexity testing 21. Stars Solutions 1. Monte Carlo π 2. Newton's π 3. Bisection root-finding 4. Newton's method 5. Gaussian elimination 6. Monte Carlo integration 7. Rectangle rule integration 8. Trapezoid rule integration 9. Arrowheads 10. Line-line intersection 11. Point-line distance 12. Point-segment distance 13. Segment-segment distance 14. Circle selection 15. Line-circle intersection 16. Circle-circle intersection 17. Circle-line tangents 18. Polygon area 19. Point in a polygon 20. Convexity testing 21. Stars Summary Randomization Problems 22. Random doubles 23. Random items 24. Randomize items 25. Random groups 26. Choose items with probabilities 27. Random passwords 28. Random walks Solutions 22. Random doubles 23. Random items 24. Randomize items 25. Random groups 26. Choose items with probabilities 27. Random passwords 28. Random walks Summary Files and Directories Problems 29. Removing blank lines 30. Directory size 31. Finding duplicate files 32. Thumbnails 33. Thumbnail web page 34. Find files 35. Find and Replace 36. Saving images 37. Compressing images Solutions 29. Removing blank lines 30. Directory size 31. Finding duplicate files 32. Thumbnails 33. Thumbnail web page 34. Find files 35. Find and Replace 36. Saving images 37. Compressing images Summary Advanced C# and .NET Features Problems 38. Directory size, LINQ style 39. Directory size, PLINQ style 40. Find files, LINQ style 41. Parallel Monte Carlo π 42. Yielding primes 43. Yielding Fibonacci numbers 44. Complex numbers Solutions 38. Directory size, LINQ style 39. Directory size, PLINQ style 40. Find files, LINQ style 41. Parallel Monte Carlo π 42. Yielding primes 43. Yielding Fibonacci numbers 44. Complex numbers Summary Cryptography Problems 45. Caesar cipher 46. Vigenère cipher 47. Cryptographic pseudorandom numbers 48. Find primes 49. Hash files 50. Steganography 51. Encrypt and decrypt strings 52. Encrypt and decrypt files 53. CryptoPad Solutions 45. Caesar cipher 46. Vigenère cipher 47. Cryptographic random numbers 48. Find primes 49. Hash files 50. Steganography 51. Encrypt and decrypt strings 52. Encrypt and decrypt files 53. CryptoPad Summary Other Books You May Enjoy Leave a review - let other readers know what you think