Skip to content

AuthenticationServiceTests

Namespace: UnitTests.Services

Unit tests for the AuthenticationService class, verifying user authentication, registration, and token management functionality.

public class AuthenticationServiceTests

Inheritance ObjectAuthenticationServiceTests

Constructors

AuthenticationServiceTests()

public AuthenticationServiceTests()

Methods

ChangePassword_WithValidData_ShouldChangePasswordSuccessfully()

Changes the password of a user with valid current password and new password, verifying that it changes successfully.

public Task ChangePassword_WithValidData_ShouldChangePasswordSuccessfully()

Returns

Task

ChangeUser_WithValidUser_ShouldUpdateUserSuccessfully()

Changes the password of a user with invalid current password and verifies that it throws an exception.

public Task ChangeUser_WithValidUser_ShouldUpdateUserSuccessfully()

Returns

Task

DeleteUser_WithValidUser_ShouldDeleteUserSuccessfully()

Deletes a user with a valid user object and verifies that the user is deleted successfully.

public Task DeleteUser_WithValidUser_ShouldDeleteUserSuccessfully()

Returns

Task

GetUserById_WithValidId_ShouldReturnUser()

Gets a user by ID with a valid user ID and verifies that the user is returned correctly.

public Task GetUserById_WithValidId_ShouldReturnUser()

Returns

Task

GetUserInformations_ShouldReturnAllUsers()

Gets all user information and verifies that the service can be called without errors.

public void GetUserInformations_ShouldReturnAllUsers()

Login_WithEmptyUsername_ShouldThrowAuthenticationException()

Logs in a user with an empty username, expecting an AuthenticationException to be thrown.

public Task Login_WithEmptyUsername_ShouldThrowAuthenticationException()

Returns

Task

Login_WithInvalidCredentials_ShouldThrowAuthenticationException()

Logs in a user with invalid credentials, expecting an AuthenticationException to be thrown.

public Task Login_WithInvalidCredentials_ShouldThrowAuthenticationException()

Returns

Task

Login_WithNonExistentUser_ShouldThrowAuthenticationException()

Logs in a user with a non-existent username, expecting an AuthenticationException to be thrown.

public Task Login_WithNonExistentUser_ShouldThrowAuthenticationException()

Returns

Task

Login_WithValidCredentials_ShouldReturnJwtToken()

Logs in a user with valid credentials and verifies that it returns a JWT token.

public Task Login_WithValidCredentials_ShouldReturnJwtToken()

Returns

Task

RefreshToken_WithExpiredRefreshToken_ShouldThrowAuthenticationException()

Refreshes a token with an expired refresh token, expecting an AuthenticationException.

public Task RefreshToken_WithExpiredRefreshToken_ShouldThrowAuthenticationException()

Returns

Task

RefreshToken_WithInvalidRefreshToken_ShouldThrowAuthenticationException()

Refreshes a token with an expired JWT token and verifies that it throws an AuthenticationException.

public Task RefreshToken_WithInvalidRefreshToken_ShouldThrowAuthenticationException()

Returns

Task

RefreshToken_WithValidToken_ShouldReturnNewJwtToken()

Refreshes a token with a valid JWT token and refresh token, verifying that it returns a new JWT token.

public Task RefreshToken_WithValidToken_ShouldReturnNewJwtToken()

Returns

Task

Register_WhenUserCreationFails_ShouldThrowException()

Registers a user when user creation fails, expecting an exception.

public Task Register_WhenUserCreationFails_ShouldThrowException()

Returns

Task

Register_WithEmptyPassword_ShouldThrowAuthenticationException()

Registers a user with an empty password, expecting an AuthenticationException.

public Task Register_WithEmptyPassword_ShouldThrowAuthenticationException()

Returns

Task

Register_WithEmptyUsername_ShouldThrowAuthenticationException()

Registers a user with an empty username or password, expecting an AuthenticationException.

public Task Register_WithEmptyUsername_ShouldThrowAuthenticationException()

Returns

Task

Register_WithExistingUsername_ShouldThrowException()

Registers a user with an existing username, expecting an exception.

public Task Register_WithExistingUsername_ShouldThrowException()

Returns

Task

Register_WithValidInput_ShouldCreateUserSuccessfully()

Tests that registration with valid input creates a user successfully.

public Task Register_WithValidInput_ShouldCreateUserSuccessfully()

Returns

Task

Setup()

Sets up test fixtures and initializes mocks before each test execution.

public void Setup()