diff options
Diffstat (limited to 'tests/Cepis.Tests/HttpTestBase.cs')
| -rw-r--r-- | tests/Cepis.Tests/HttpTestBase.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/Cepis.Tests/HttpTestBase.cs b/tests/Cepis.Tests/HttpTestBase.cs new file mode 100644 index 0000000..115ceef --- /dev/null +++ b/tests/Cepis.Tests/HttpTestBase.cs @@ -0,0 +1,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); + } +} |