too much for one commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using EntKube.Clusters.Domain;
|
||||
using EntKube.Clusters.Features.GetClusterById;
|
||||
using EntKube.Clusters.Infrastructure;
|
||||
using EntKube.SharedKernel.Domain;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace EntKube.Clusters.Tests.Features;
|
||||
|
||||
public class GetClusterByIdHandlerTests
|
||||
{
|
||||
private readonly GetClusterByIdHandler handler;
|
||||
private readonly InMemoryClusterRepository repository;
|
||||
|
||||
public GetClusterByIdHandlerTests()
|
||||
{
|
||||
repository = new InMemoryClusterRepository();
|
||||
handler = new GetClusterByIdHandler(repository);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WithExistingCluster_ReturnsSuccess()
|
||||
{
|
||||
// Arrange — Register a cluster so the repository has something to find.
|
||||
|
||||
KubernetesCluster cluster = KubernetesCluster.Register(
|
||||
"production-eu",
|
||||
"https://k8s.example.com:6443",
|
||||
"kubeconfig-data",
|
||||
Guid.NewGuid(),
|
||||
"prod-ctx", Guid.NewGuid());
|
||||
|
||||
await repository.AddAsync(cluster);
|
||||
|
||||
// Act — Look it up by its ID.
|
||||
|
||||
Result<KubernetesCluster> result = await handler.HandleAsync(cluster.Id);
|
||||
|
||||
// Assert — The handler should return the full cluster aggregate.
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value!.Name.Should().Be("production-eu");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WithNonExistentId_ReturnsFailure()
|
||||
{
|
||||
// Arrange — An ID that doesn't exist in the repository.
|
||||
|
||||
Guid unknownId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
|
||||
Result<KubernetesCluster> result = await handler.HandleAsync(unknownId);
|
||||
|
||||
// Assert
|
||||
|
||||
result.IsFailure.Should().BeTrue();
|
||||
result.Error.Should().Contain("not found");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user