Programming Tips 💡
51.6K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips 💡
Articles 📕
Resources 👾
Design Patterns 💎
Software Principles

🇳🇱 Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
Mocking objects with Moq and XUnit in .NET Core 👾

This article explains the step by step process that needed to Moq an object in .NET Core ⚜️

Mocking objects comes in handy when unit testing data store, where a Database can be mocked so that no data is added or modified in Database while unit testing source code. ♻️

https://t.me/pgimg/32

[ Tutorial ] : http://bit.do/moqx


#UnitTest #Mocking #XUnit #Moq
@ProgrammingTip
Write tests,
Not too many,
Mostly integration.


A while back, Guillermo Rauch‏ ( Creator of Socket.io ) tweeted something profound :

Write tests. Not too many. Mostly integration.💎 


This is deep, albeit short, so let’s dive in. 🌀

https://t.me/pgimg/62

[ Article ] : http://bit.do/iut


#UnitTest
@ProgrammingTip
WireMock.NET 😮

WireMock.NET is a .NET library for stubbing and mocking HTTP services. With WireMock.NET, you can define the expected responses for particular requests, and the library will intercept and manage those requests for you. ✔️

This allows for easy testing of the code that makes HTTP requests, without having to rely on the actual external service being available and without hacking HttpClient. 🆒

Sample code snippet:

[Test]
public async Task sample_WireMock_usage()
{
// Setup WireMock.Net server
using var wireMock = WireMockServer.StartWithAdminInterface(port: 1080, ssl: false);

// Setup WebApplicationFactory
await using var appFactory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration(configurationBuilder =>
{
// Override downstream service addresses pointing to WireMock address
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
["ExternalServices:WeatherService"] = "http://localhost:1080"
});
});
});

// Prepare stub for outgoing request
wireMock
.Given(
Request.Create()
.WithPath("/api/v1.0/weather")
.WithParam("lat", "10.99")
.WithParam("lon", "44.34")
.UsingGet()
)
.RespondWith(
Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json; charset=utf-8")
.WithBodyAsJson(new
{
temp = 298.48,
feels_like = 298.74,
temp_min = 297.56,
temp_max = 300.05,
pressure = 1015,
humidity = 64
})
);

// Automate tested app
}


[ Blog ] : https://cezarypiatek.github.io/post/mocking-outgoing-http-requests-p1

〰️〰️〰️〰️〰️〰️
#UnitTest #DotNet #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
A Structured Roadmap to Master Software Testing for Developers 🚀

Struggling to navigate the world of testing? 💭
I’ve compiled a comprehensive roadmap to help developers learn testing concepts systematically—whether you're a beginner or looking to fill gaps in your knowledge.

🔍 What’s Inside?
Core Testing Concepts (White/Gray/Black Box)
Test Design (Equivalence Partitioning, Boundary Analysis, etc.)
Naming Standards
Patterns (AAA, Four-Phase, BDD with Gherkin)
Test Types (Unit, Integration, E2E, Performance, etc.)
Tools & Frameworks (xUnit, Playwright, K6, AutoFixture, etc.)
Best Practices (Clean Test Code, Test Smells, Coverage)
Static Analysis & CI/CD Integration


📌 Highlights
Self-assessment friendly → Track your progress.

Language-agnostic → Examples in .NET, JS, Python, PHP.

Practical focus → From TDD/BDD to CI/CD pipelines.


[GitHub] : https://github.com/hasanxdev/Test-Roadmap-For-Developers

〰️〰️〰️〰️〰️〰️

#Test #Roadmap #UnitTest #IntegrationTest

@ProgrammingTip