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:
ใฐ๏ธใฐ๏ธใฐ๏ธใฐ๏ธใฐ๏ธใฐ๏ธ
#UnitTest #DotNet #CSharp
@ProgrammingTip
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][ Blog ] : https://cezarypiatek.github.io/post/mocking-outgoing-http-requests-p1
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
}
ใฐ๏ธใฐ๏ธใฐ๏ธใฐ๏ธใฐ๏ธใฐ๏ธ
#UnitTest #DotNet #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
Programming Tips Resources
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
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
GitHub
GitHub - hasanxdev/Test-Roadmap-For-Developers: The Complete Learning Path to Mastering Software Testing as a Developer
The Complete Learning Path to Mastering Software Testing as a Developer - hasanxdev/Test-Roadmap-For-Developers