Skip to content

test: Shared test infrastructure — MockHttpMessageHandler, fixtures & helpers #51

Description

@teesofttech

Overview

Before building per-gateway test files, establish the shared test infrastructure that all unit and integration tests will rely on.

What to Build

MockHttpMessageHandler

A reusable DelegatingHandler (or implementation of HttpMessageHandler) that:

  • Accepts a list of (method, url pattern, statusCode, responseBody) tuples to queue up
  • Asserts the correct HTTP method and URL was called
  • Supports multiple sequential responses for multi-call gateways (e.g. Monnify OAuth + init, Interswitch OAuth + pay)
  • Throws InvalidOperationException if an unexpected request is made

TestFixtures

  • PaymentRequestFactory.Build() — returns a valid PaymentRequest with sensible test defaults
  • RefundRequestFactory.Build() — returns a valid RefundRequest
  • GatewayConfigFactory.BuildPaystack(secretKey) — returns a PaymentGatewayConfig with Paystack configured (one per gateway)

IntegrationTestBase

  • Abstract base class that checks for required env vars and calls Skip.IfNot() (or Assert.Skip()) when missing
  • Reads env vars from .env.test via dotenv or directly from environment
  • Logs which env vars are missing so CI output is clear

Test Category Traits

  • [Trait("Category", "Unit")] on all unit test classes
  • [Trait("Category", "Integration")] on all integration test classes
  • Add .runsettings to allow running only unit tests with dotnet test --filter Category=Unit

Directory Structure

PayBridge.SDK.Test/
  Unit/
    PaystackGatewayTests.cs
    FlutterwaveGatewayTests.cs
    ... (one per gateway)
  Integration/
    PaystackIntegrationTests.cs
    ... (one per gateway)
  Helpers/
    MockHttpMessageHandler.cs
    PaymentRequestFactory.cs
    GatewayConfigFactory.cs
    IntegrationTestBase.cs
  PayBridgeTests.cs   (existing smoke tests)

Acceptance Criteria

  • MockHttpMessageHandler can intercept and respond to HTTP calls without hitting the network
  • All factory helpers produce valid objects accepted by gateway constructors
  • IntegrationTestBase correctly skips tests when env vars are not set
  • dotnet test --filter Category=Unit runs only unit tests
  • dotnet test --filter Category=Integration runs only integration tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    testingTest coverage and test suite work

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions