.NET

C#, dotNet Core, ASP.NET, Entity Framework, testing, architecture, and everything .NET developers need.

Test-Driven Development (TDD)

Write tests first for better code

Test-Driven Development (TDD) means writing your tests before you write the code. πŸ” The TDD Cycle Write a failing test (it describes what you want) Write just enough code to make the test pa...

Mocking and Test Doubles

Testing in isolation with fakes, stubs, and mocks

Sometimes you want to test a class without using its real dependencies. That’s where test doubles come in. πŸͺ€ Types of Test Doubles Stub: Returns fixed data (no real logic) Fake: Simple worki...

Making API Calls Using HttpClient

Best practices for HTTP requests in C#

For production C# apps, follow these best practices with HttpClient. πŸ—οΈ Use IHttpClientFactory (ASP.NET Core) 1 2 3 4 public void ConfigureServices(IServiceCollection services) { services.Add...

Integrating with the ChatGPT API

Consume OpenAI APIs from your C# app

You can call the OpenAI (ChatGPT) API using HttpClient in C#. πŸ”‘ Get Your API Key Sign up at OpenAI and create a key. πŸš€ Sample POST Request 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20...

Test Organization and Naming Conventions

How to keep your tests tidy and clear

Good test organization makes it easy to find, run, and understand your tests. πŸ“‚ File and Folder Structure Put tests in a separate project or folder (e.g. MyApp.Tests). Mirror your code struc...

JSON Serialization and Deserialization

Convert C# objects to JSON and back

Modern APIs use JSON for data exchange. Here’s how to work with JSON in C#. πŸ”„ Serialize (Object β†’ JSON) 1 2 3 4 5 using System.Text.Json; var user = new User { Name = "Alice", Age = 30 }; string...

Testing with xUnit and NUnit

Popular testing frameworks for .NET

Automated tests help keep your code working as you make changes. The two most popular .NET testing libraries are xUnit and NUnit. πŸ§ͺ xUnit Built-in support with .NET CLI (dotnet new xunit) Te...

Unit Testing Basics

Test your code automatically

Unit tests check that small parts of your code work correctly automatically. πŸ§ͺ Why Test? Catch bugs early Refactor safely Prove your code works πŸ—οΈ Create a Test Project In terminal, ...

Using HttpClient for API Calls

Make HTTP requests in C#

HttpClient is the main way to call REST APIs from C#. πŸš€ Basic Usage 1 2 3 4 5 6 7 using System.Net.Http; using System.Threading.Tasks; var client = new HttpClient(); HttpResponseMessage response...

Async Best Practices

Write safe and efficient async code

Async is powerful, but there are some rules for writing safe, efficient code. βœ… Do Use async and await for slow operations (file/network). Always await async methods, don’t ignore the result...