Class Test_OrganizationService
Comprehensive test suite for the OrganizationService class, testing organization management functionality.
Inherited Members
Namespace: OEMS.UnitTests.Application
Assembly: OEMS.UnitTests.dll
Syntax
[TestClass]
public sealed class Test_OrganizationService
Remarks
This test class verifies organization creation, validation of domain formats, handling of duplicate domains, file attachments, and error conditions during registration. Following the test concept, we focus on testing both valid and invalid inputs, as well as edge cases for each method, with appropriate code coverage.
Methods
CreateOrganizationAsync_WhenDatabaseCreateThrowsException_ReturnsErrorResult()
Tests organization creation when database create operation throws an exception.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WhenDatabaseCreateThrowsException_ReturnsErrorResult()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly handles database exceptions during the create operation. Tests exception handling during the final database insertion step.
CreateOrganizationAsync_WhenDatabaseOperationFails_ReturnsErrorResult()
Tests organization creation when database operation fails.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WhenDatabaseOperationFails_ReturnsErrorResult()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly handles database errors during organization creation and returns an appropriate error result. Tests error handling when the database operation returns false.
CreateOrganizationAsync_WhenDomainCheckThrowsException_ReturnsErrorResult()
Tests organization creation when domain check throws an exception.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WhenDomainCheckThrowsException_ReturnsErrorResult()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly handles exceptions from the repository during domain checks and returns an appropriate error result. Tests exception handling in the domain validation step.
CreateOrganizationAsync_WithCaseInsensitiveDomainMatch_ReturnsErrorResult()
Tests organization creation with case-insensitive domain matching.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WithCaseInsensitiveDomainMatch_ReturnsErrorResult()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that domain checking is case-insensitive, as per domain name standards. This is a boundary test checking a specific edge case of domain validation.
CreateOrganizationAsync_WithDuplicateDomain_ReturnsErrorResult()
Tests organization creation with a domain that already exists.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WithDuplicateDomain_ReturnsErrorResult()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly checks for duplicate domains and returns an error when attempting to register a domain that is already in use. This tests the domain uniqueness constraint, an important business rule.
CreateOrganizationAsync_WithInvalidDomain_ReturnsErrorResult()
Tests organization creation with an invalid domain format.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WithInvalidDomain_ReturnsErrorResult()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly validates domain format and returns an error when the domain does not match the required pattern. This is a negative test case with invalid input to verify input validation.
CreateOrganizationAsync_WithNonExistentFileId_ResetToEmptyGuid()
Tests organization creation with a non-existent file ID.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WithNonExistentFileId_ResetToEmptyGuid()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service gracefully handles the case when a file ID is provided but the file does not exist in the database. This is an edge case to ensure robust error handling.
CreateOrganizationAsync_WithValidData_ReturnsSuccessResult()
Tests successful organization creation with valid data (common case).
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WithValidData_ReturnsSuccessResult()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly processes a valid organization creation request and returns a successful result with the expected data. This is a positive test case with valid inputs representing the most common usage pattern.
CreateOrganizationAsync_WithValidFileId_LinksFileToOrganization()
Tests organization creation with a valid file reference.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WithValidFileId_LinksFileToOrganization()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly processes a file ID provided with the organization creation request and links it to the organization. This tests file attachment functionality, a key business requirement.
CreateOrganizationAsync_WithVariousInvalidDomains_AllReturnErrors()
Tests organization creation with various invalid domain formats.
Declaration
[TestMethod]
public Task CreateOrganizationAsync_WithVariousInvalidDomains_AllReturnErrors()
Returns
Type | Description |
---|---|
Task |
Remarks
Tests multiple invalid domain formats to ensure comprehensive validation. This boundary test checks edge cases of domain validation.
GetOrganizationBrandingAsync_WithEmptyGuid_ReturnsNull()
Tests retrieval of organization branding with empty GUID.
Declaration
[TestMethod]
public Task GetOrganizationBrandingAsync_WithEmptyGuid_ReturnsNull()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service handles empty GUID input gracefully. This is a boundary test with edge case input.
GetOrganizationBrandingAsync_WithNonExistentOrganizationId_ReturnsNull()
Tests retrieval of organization branding with non-existent organization ID.
Declaration
[TestMethod]
public Task GetOrganizationBrandingAsync_WithNonExistentOrganizationId_ReturnsNull()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service returns null when attempting to retrieve branding for an organization that does not exist. This is a negative test case with invalid input.
GetOrganizationBrandingAsync_WithValidOrganizationId_ReturnsOrganizationDto()
Tests successful retrieval of organization branding settings (common case).
Declaration
[TestMethod]
public Task GetOrganizationBrandingAsync_WithValidOrganizationId_ReturnsOrganizationDto()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly retrieves an organization's branding settings and returns the expected OrganizationDto with all properties mapped correctly. This is a positive test case with valid inputs representing normal usage.
SetUp()
Initializes test dependencies before each test method execution.
Declaration
[TestInitialize]
public void SetUp()
Remarks
Sets up mock repositories and context with test values to isolate the organization service for unit testing.
UpdateOrganizationBrandingAsync_WhenRepositoryThrowsException_PropagatesException()
Tests update when repository throws exception during update operation.
Declaration
[TestMethod]
[ExpectedException(typeof(Exception))]
public Task UpdateOrganizationBrandingAsync_WhenRepositoryThrowsException_PropagatesException()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that exceptions from the repository layer are properly propagated and not swallowed by the service layer. This tests error handling during the database update operation.
UpdateOrganizationBrandingAsync_WithEmptyLogoGuid_PreservesExistingLogo()
Tests update with empty logo GUID (should not change existing logo).
Declaration
[TestMethod]
public Task UpdateOrganizationBrandingAsync_WithEmptyLogoGuid_PreservesExistingLogo()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that when an empty GUID is provided for the logo, the existing logo is preserved and only branding settings are updated. This is a boundary test with edge case input.
UpdateOrganizationBrandingAsync_WithNewLogo_UpdatesBrandingAndLogo()
Tests successful update of organization branding with new logo.
Declaration
[TestMethod]
public Task UpdateOrganizationBrandingAsync_WithNewLogo_UpdatesBrandingAndLogo()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly updates both branding settings and logo when a new logo file ID is provided. This tests the complete branding update functionality.
UpdateOrganizationBrandingAsync_WithNonExistentOrganizationId_ThrowsException()
Tests update with non-existent organization ID.
Declaration
[TestMethod]
[ExpectedException(typeof(KeyNotFoundException))]
public Task UpdateOrganizationBrandingAsync_WithNonExistentOrganizationId_ThrowsException()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service throws the expected exception when attempting to update branding for an organization that does not exist. This is a negative test case with invalid input.
UpdateOrganizationBrandingAsync_WithNullLogoFileId_PreservesExistingLogo()
Tests update with null logo file ID (should not change existing logo).
Declaration
[TestMethod]
public Task UpdateOrganizationBrandingAsync_WithNullLogoFileId_PreservesExistingLogo()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that when null is provided for the logo file ID, the existing logo is preserved. This tests the optional parameter behavior. This is a boundary test with null input.
UpdateOrganizationBrandingAsync_WithOnlyBrandingSettings_UpdatesSuccessfully()
Tests successful update of organization branding settings without logo change.
Declaration
[TestMethod]
public Task UpdateOrganizationBrandingAsync_WithOnlyBrandingSettings_UpdatesSuccessfully()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service correctly updates organization branding settings when only color changes are provided (no new logo). This is a positive test case for the most common branding update scenario.
UpdateOrganizationBrandingAsync_WithVariousValidBrandingFormats_UpdatesSuccessfully()
Tests update with various valid branding JSON formats.
Declaration
[TestMethod]
public Task UpdateOrganizationBrandingAsync_WithVariousValidBrandingFormats_UpdatesSuccessfully()
Returns
Type | Description |
---|---|
Task |
Remarks
Verifies that the service accepts different valid JSON branding configurations and updates them correctly without validation errors. This is a boundary test checking various valid input formats.