Tests : Application Layer¶
-
Do create a unit tests for only
AppService
suffixed services.- Do create AppServices and Integrations folders in GridLab.PSSX.<ModuleName>.Application.Tests project.
- Do create an unit test for each application service with <DomainModelName>AppService_Tests name.
In this case it is
IdentityClaimTypeAppService_Tests
.public class IdentityClaimTypeAppService_Tests : IdentityApplicationTestBase { private readonly IIdentityClaimTypeAppService _identityClaimTypeAppService; private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; public IdentityClaimTypeAppService_Tests() { _identityClaimTypeAppService = GetRequiredService<IIdentityClaimTypeAppService>(); _identityClaimTypeRepository = GetRequiredService<IIdentityClaimTypeRepository>(); } [Fact] public async Task CreateAsync_Should_Create_ClaimType() { // Arrange var input = new CreateClaimTypeInput { Name = "TestClaim", Required = true, Regex = ".*", RegexDescription = "Any value", Description = "Test description", ValueType = IdentityClaimValueType.String }; // Act var result = await _identityClaimTypeAppService.CreateAsync(input); // Assert result.ShouldNotBeNull(); result.Name.ShouldBe(input.Name); result.Required.ShouldBe(input.Required); result.Regex.ShouldBe(input.Regex); } ... add more unit test depending on your application service behaviour. }
The tests should cover the key functionalities of the
IModelAppService
interface. -
Do not use constructor injection for tests.
Using
GetRequiredService
provides more flexibility in setting up the test environment. It allows the test class to resolve services at runtime, which can be useful if the services need to be configured or modified before being used in tests. -
Do not create unit test for private and protected methods of class. You should test behaviour not the methods.