summaryrefslogtreecommitdiffstats
path: root/tests/Cepis.Tests/HttpTestBase.cs
blob: 115ceef0a56332ef1eae167bb74d893e52e6d696 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
namespace Cepis.Tests;

/// <summary>A fake API and a real client pointed at it, torn down per test.</summary>
public abstract class HttpTestBase : IDisposable
{
    /// <summary>The fake API.</summary>
    protected FakeServer Server { get; } = new();

    /// <summary>
    /// A client whose backoff is shortened so the suite stays fast, and whose
    /// per-attempt timeout is deliberately generous: a loaded machine must not
    /// be able to turn a passing test into a spurious network failure.
    /// </summary>
    protected CepisClient Client { get; }

    /// <summary>Start the server and point a client at it.</summary>
    protected HttpTestBase() =>
        Client = new CepisClient(new CepisClientOptions
        {
            BaseUrl = Server.Url,
            Timeout = TimeSpan.FromSeconds(30),
            BackoffBase = TimeSpan.FromMilliseconds(1),
            BackoffMax = TimeSpan.FromMilliseconds(20),
        });

    /// <summary>Stop the server and release the client.</summary>
    public void Dispose()
    {
        Client.Dispose();
        Server.Dispose();
        GC.SuppressFinalize(this);
    }
}