IntegrationTestBase¶
Namespace: IntegrationTests.Infrastructure
Base class for integration tests providing common HTTP client functionality, authentication helpers, and test data
management.
Inheritance Object → IntegrationTestBase
Methods¶
CleanupDatabaseAsync()¶
Cleans up test data by removing all test users from the database.
Returns¶
CreateJsonContent<T>(T)¶
Creates JSON content for HTTP requests from the specified object using camelCase property naming.
Type Parameters¶
T
The type of object to serialize.
Parameters¶
obj T
The object to serialize to JSON.
Returns¶
StringContent containing the JSON representation of the object.
CreateTestUserAsync(String, String, String)¶
Creates a test user with the specified credentials and role for use in integration tests.
Parameters¶
username String
The username for the test user.
password String
The password for the test user.
role String
The role to assign to the test user.
Returns¶
GenerateUniqueUsername(String)¶
Generates a unique username by appending timestamp and counter to the base username to avoid conflicts.
Parameters¶
baseUsername String
The base username to make unique.
Returns¶
A unique username string.
GetJwtTokenAsync(String, String)¶
Gets a valid JWT token by creating a test user and performing authentication.
Parameters¶
baseUsername String
The base username for the test user (default: "admin").
password String
The password for the test user (default: "Admin123!").
Returns¶
A valid JWT token string for API authentication.
GetValidJwtTokenAsync(String, String)¶
Authenticates with the specified credentials and returns a valid JWT token for API requests.
Parameters¶
username String
The username for authentication.
password String
The password for authentication.
Returns¶
A valid JWT token string.
OneTimeSetUp()¶
One-time setup to initialize the test web application factory and HTTP client for all tests in the fixture.
Returns¶
OneTimeTearDown()¶
One-time cleanup to dispose of the HTTP client and web application factory after all tests complete.
SendAsync<T>(HttpRequestMessage)¶
Sends an HTTP request and deserializes the response content to the specified type.
Type Parameters¶
T
The type to deserialize the response content to.
Parameters¶
request HttpRequestMessage
The HTTP request message to send.
Returns¶
The deserialized response content or default value if content is empty.
SetAuthorizationHeader(String)¶
Sets the Authorization header on the HTTP client with the provided JWT token.
Parameters¶
token String
The JWT token to use for authorization.
SetUp()¶
Setup method run before each test to reset the HTTP client authorization header.