Files
Entkube/tests/EntKube.Provisioning.Tests/Features/RemoveAppEnvironmentHandlerTests.cs
2026-05-13 14:01:32 +02:00

72 lines
2.1 KiB
C#

using EntKube.Provisioning.Domain;
using EntKube.Provisioning.Features.Apps.RemoveAppEnvironment;
using EntKube.Provisioning.Infrastructure;
using EntKube.SharedKernel.Domain;
using FluentAssertions;
namespace EntKube.Provisioning.Tests.Features;
public class RemoveAppEnvironmentHandlerTests
{
private readonly InMemoryAppRepository repository;
private readonly RemoveAppEnvironmentHandler handler;
public RemoveAppEnvironmentHandlerTests()
{
repository = new InMemoryAppRepository();
handler = new RemoveAppEnvironmentHandler(repository);
}
[Fact]
public async Task HandleAsync_ExistingEnvironment_RemovesSuccessfully()
{
// Arrange — An app with one environment.
App app = App.Create(Guid.NewGuid(), Guid.NewGuid(), "API", "api", AppType.Deployment);
Guid envId = Guid.NewGuid();
app.AddEnvironment(envId, Guid.NewGuid(), "api-dev");
await repository.AddAsync(app);
// Act
Result result = await handler.HandleAsync(new RemoveAppEnvironmentRequest(app.Id, envId));
// Assert — The environment should be removed.
result.IsSuccess.Should().BeTrue();
App? updated = await repository.GetByIdAsync(app.Id);
updated!.Environments.Should().BeEmpty();
}
[Fact]
public async Task HandleAsync_NonexistentApp_ReturnsFailure()
{
// Act
Result result = await handler.HandleAsync(new RemoveAppEnvironmentRequest(Guid.NewGuid(), Guid.NewGuid()));
// Assert
result.IsFailure.Should().BeTrue();
result.Error.Should().Contain("not found");
}
[Fact]
public async Task HandleAsync_NonexistentEnvironment_ReturnsFailure()
{
// Arrange — An app with no environments.
App app = App.Create(Guid.NewGuid(), Guid.NewGuid(), "API", "api", AppType.Deployment);
await repository.AddAsync(app);
// Act
Result result = await handler.HandleAsync(new RemoveAppEnvironmentRequest(app.Id, Guid.NewGuid()));
// Assert
result.IsFailure.Should().BeTrue();
result.Error.Should().Contain("not found");
}
}