63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using EntKube.Clusters.Domain;
|
|
using EntKube.Clusters.Features.DeleteCluster;
|
|
using EntKube.Clusters.Infrastructure;
|
|
using EntKube.SharedKernel.Domain;
|
|
using FluentAssertions;
|
|
|
|
namespace EntKube.Clusters.Tests.Features;
|
|
|
|
public class DeleteClusterHandlerTests
|
|
{
|
|
private readonly DeleteClusterHandler handler;
|
|
private readonly InMemoryClusterRepository repository;
|
|
|
|
public DeleteClusterHandlerTests()
|
|
{
|
|
repository = new InMemoryClusterRepository();
|
|
handler = new DeleteClusterHandler(repository);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HandleAsync_WithExistingCluster_DeletesAndReturnsSuccess()
|
|
{
|
|
// Arrange — Register a cluster so we have something to delete.
|
|
|
|
KubernetesCluster cluster = KubernetesCluster.Register(
|
|
"staging",
|
|
"https://staging-k8s.example.com:6443",
|
|
"kubeconfig-data",
|
|
Guid.NewGuid(),
|
|
"staging-ctx", Guid.NewGuid());
|
|
|
|
await repository.AddAsync(cluster);
|
|
|
|
// Act — Delete it by ID.
|
|
|
|
Result result = await handler.HandleAsync(cluster.Id);
|
|
|
|
// Assert — The deletion succeeds and the cluster is no longer in the repository.
|
|
|
|
result.IsSuccess.Should().BeTrue();
|
|
|
|
KubernetesCluster? deleted = await repository.GetByIdAsync(cluster.Id);
|
|
deleted.Should().BeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HandleAsync_WithNonExistentId_ReturnsFailure()
|
|
{
|
|
// Arrange — An ID that doesn't exist.
|
|
|
|
Guid unknownId = Guid.NewGuid();
|
|
|
|
// Act
|
|
|
|
Result result = await handler.HandleAsync(unknownId);
|
|
|
|
// Assert
|
|
|
|
result.IsFailure.Should().BeTrue();
|
|
result.Error.Should().Contain("not found");
|
|
}
|
|
}
|