72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
using EntKube.Provisioning.Domain;
|
|
using EntKube.Provisioning.Features.Apps.SuspendActivateApp;
|
|
using EntKube.Provisioning.Infrastructure;
|
|
using EntKube.SharedKernel.Domain;
|
|
using FluentAssertions;
|
|
|
|
namespace EntKube.Provisioning.Tests.Features;
|
|
|
|
public class SuspendActivateAppHandlerTests
|
|
{
|
|
private readonly InMemoryAppRepository repository;
|
|
private readonly SuspendActivateAppHandler handler;
|
|
|
|
public SuspendActivateAppHandlerTests()
|
|
{
|
|
repository = new InMemoryAppRepository();
|
|
handler = new SuspendActivateAppHandler(repository);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SuspendAsync_ActiveApp_SuspendsSuccessfully()
|
|
{
|
|
// Arrange — An active app.
|
|
|
|
App app = App.Create(Guid.NewGuid(), Guid.NewGuid(), "API", "api", AppType.Deployment);
|
|
await repository.AddAsync(app);
|
|
|
|
// Act
|
|
|
|
Result result = await handler.SuspendAsync(app.Id);
|
|
|
|
// Assert
|
|
|
|
result.IsSuccess.Should().BeTrue();
|
|
App? updated = await repository.GetByIdAsync(app.Id);
|
|
updated!.Status.Should().Be(AppStatus.Suspended);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ActivateAsync_SuspendedApp_ActivatesSuccessfully()
|
|
{
|
|
// Arrange — A suspended app.
|
|
|
|
App app = App.Create(Guid.NewGuid(), Guid.NewGuid(), "API", "api", AppType.Deployment);
|
|
app.Suspend();
|
|
await repository.AddAsync(app);
|
|
|
|
// Act
|
|
|
|
Result result = await handler.ActivateAsync(app.Id);
|
|
|
|
// Assert
|
|
|
|
result.IsSuccess.Should().BeTrue();
|
|
App? updated = await repository.GetByIdAsync(app.Id);
|
|
updated!.Status.Should().Be(AppStatus.Active);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SuspendAsync_NonexistentApp_ReturnsFailure()
|
|
{
|
|
// Act
|
|
|
|
Result result = await handler.SuspendAsync(Guid.NewGuid());
|
|
|
|
// Assert
|
|
|
|
result.IsFailure.Should().BeTrue();
|
|
result.Error.Should().Contain("not found");
|
|
}
|
|
}
|