Add unit tests for KubernetesCluster, Tenant, ServiceInstance, and RegisterClusterHandler
- Implement tests for KubernetesCluster including registration, connectivity status, and error handling. - Create tests for Tenant creation, member management, and status changes. - Add tests for ServiceInstance provisioning and state management. - Introduce RegisterClusterHandler tests to validate registration requests and error scenarios. - Set up project files for new test projects with necessary dependencies.
This commit is contained in:
103
tests/EntKube.Identity.Tests/Domain/TenantTests.cs
Normal file
103
tests/EntKube.Identity.Tests/Domain/TenantTests.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using EntKube.Identity.Domain;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace EntKube.Identity.Tests.Domain;
|
||||
|
||||
public class TenantTests
|
||||
{
|
||||
[Fact]
|
||||
public void Create_WithValidInputs_CreatesTenantWithAdminMember()
|
||||
{
|
||||
// Arrange & Act — An admin creates a new tenant organization.
|
||||
|
||||
Guid userId = Guid.NewGuid();
|
||||
Tenant tenant = Tenant.Create("Acme Corp", "acme-corp", userId);
|
||||
|
||||
// Assert — The tenant should be active and the creator should be admin.
|
||||
|
||||
tenant.Id.Should().NotBe(Guid.Empty);
|
||||
tenant.Name.Should().Be("Acme Corp");
|
||||
tenant.Slug.Should().Be("acme-corp");
|
||||
tenant.Status.Should().Be(TenantStatus.Active);
|
||||
tenant.Members.Should().HaveCount(1);
|
||||
tenant.Members[0].UserId.Should().Be(userId);
|
||||
tenant.Members[0].Role.Should().Be(TenantRole.Admin);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WithEmptyName_ThrowsArgumentException()
|
||||
{
|
||||
// Arrange & Act
|
||||
|
||||
Action act = () => Tenant.Create("", "slug", Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
|
||||
act.Should().Throw<ArgumentException>()
|
||||
.WithParameterName("name");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WithEmptySlug_ThrowsArgumentException()
|
||||
{
|
||||
// Arrange & Act
|
||||
|
||||
Action act = () => Tenant.Create("Acme", "", Guid.NewGuid());
|
||||
|
||||
// Assert
|
||||
|
||||
act.Should().Throw<ArgumentException>()
|
||||
.WithParameterName("slug");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMember_NewUser_AddsMemberToTenant()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Tenant tenant = Tenant.Create("Acme", "acme", Guid.NewGuid());
|
||||
Guid newUserId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
|
||||
tenant.AddMember(newUserId, TenantRole.Member);
|
||||
|
||||
// Assert
|
||||
|
||||
tenant.Members.Should().HaveCount(2);
|
||||
tenant.Members.Should().Contain(m => m.UserId == newUserId && m.Role == TenantRole.Member);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMember_ExistingUser_DoesNotDuplicate()
|
||||
{
|
||||
// Arrange — Create a tenant (creator is already a member).
|
||||
|
||||
Guid userId = Guid.NewGuid();
|
||||
Tenant tenant = Tenant.Create("Acme", "acme", userId);
|
||||
|
||||
// Act — Try adding the same user again.
|
||||
|
||||
tenant.AddMember(userId, TenantRole.Viewer);
|
||||
|
||||
// Assert — Still only one member.
|
||||
|
||||
tenant.Members.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Suspend_SetsStatusToSuspended()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Tenant tenant = Tenant.Create("Acme", "acme", Guid.NewGuid());
|
||||
|
||||
// Act
|
||||
|
||||
tenant.Suspend();
|
||||
|
||||
// Assert
|
||||
|
||||
tenant.Status.Should().Be(TenantStatus.Suspended);
|
||||
}
|
||||
}
|
||||
28
tests/EntKube.Identity.Tests/EntKube.Identity.Tests.csproj
Normal file
28
tests/EntKube.Identity.Tests/EntKube.Identity.Tests.csproj
Normal file
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="FluentAssertions" Version="8.9.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\EntKube.Identity\EntKube.Identity.csproj" />
|
||||
<ProjectReference Include="..\..\src\EntKube.SharedKernel\EntKube.SharedKernel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user