generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUsingApiTester.cs
More file actions
39 lines (35 loc) · 2.09 KB
/
UsingApiTester.cs
File metadata and controls
39 lines (35 loc) · 2.09 KB
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
34
35
36
37
38
39
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx
using CoreEx.Http;
using Microsoft.AspNetCore.TestHost;
using System;
using System.Net.Http;
using UnitTestEx.AspNetCore;
namespace UnitTestEx
{
/// <summary>
/// Provides a shared <see cref="ApiTester"/> class to enable usage of the same underlying <see cref="TestServer"/> instance across multiple tests.
/// </summary>
/// <typeparam name="TEntryPoint">The API startup <see cref="Type"/>.</typeparam>
/// <remarks>Implements <see cref="IDisposable"/> so should be automatically disposed off by the test framework host.</remarks>
public abstract class UsingApiTester<TEntryPoint> : ApiTester<TEntryPoint> where TEntryPoint : class
{
/// <summary>
/// Gets the <see cref="ApiTester"/>; i.e. itself.
/// </summary>
/// <remarks>This is provided for backwards compatibility.</remarks>
public UsingApiTester<TEntryPoint> ApiTester => this;
/// <summary>
/// Enables a test <see cref="HttpRequestMessage"/> to be sent to the underlying <see cref="TestServer"/> with a specified <see cref="TypedHttpClientBase">agent</see>.
/// </summary>
/// <typeparam name="TAgent">The <see cref="AgentTester{TAgent}"/>.</typeparam>
/// <returns>The <see cref="AgentTester{TAgent}"/>.</returns>
public AgentTester<TAgent> Agent<TAgent>() where TAgent : CoreEx.Http.TypedHttpClientBase => new(this, GetTestServer());
/// <summary>
/// Enables a test <see cref="HttpRequestMessage"/> to be sent to the underlying <see cref="TestServer"/> with a specified <see cref="TypedHttpClientBase">agent</see>.
/// </summary>
/// <typeparam name="TAgent">The <see cref="AgentTester{TAgent}"/>.</typeparam>
/// <typeparam name="TValue">The response value <see cref="Type"/>.</typeparam>
/// <returns>The <see cref="AgentTester{TAgent, TValue}"/>.</returns>
public AgentTester<TAgent, TValue> Agent<TAgent, TValue>() where TAgent : CoreEx.Http.TypedHttpClientBase => new(this, GetTestServer());
}
}