feat(domain): RubroConProductosActivosException + guard en DeactivateRubro (closes #41) #44

Merged
dmolinari merged 4 commits from fix/issue-41-rubro-deactivation-guard into main 2026-04-19 20:09:38 +00:00
2 changed files with 44 additions and 0 deletions
Showing only changes of commit e9d1e3237d - Show all commits

View File

@@ -0,0 +1,17 @@
namespace SIGCM2.Domain.Exceptions;
/// <summary>
/// Thrown when attempting to soft-delete a Rubro that still has active Products referencing it via RubroId. → HTTP 409
/// </summary>
public sealed class RubroConProductosActivosException : DomainException
{
public int RubroId { get; }
public int ProductosActivosCount { get; }
public RubroConProductosActivosException(int rubroId, int productosActivosCount)
: base($"No se puede desactivar el rubro {rubroId}: tiene {productosActivosCount} producto(s) activo(s) referenciándolo.")
{
RubroId = rubroId;
ProductosActivosCount = productosActivosCount;
}
}

View File

@@ -0,0 +1,27 @@
using FluentAssertions;
using SIGCM2.Domain.Exceptions;
namespace SIGCM2.Application.Tests.Domain.Rubros;
public class RubroConProductosActivosExceptionTests
{
[Fact]
public void Constructor_SetsPropertiesAndMessage()
{
var ex = new RubroConProductosActivosException(rubroId: 7, productosActivosCount: 3);
ex.RubroId.Should().Be(7);
ex.ProductosActivosCount.Should().Be(3);
ex.Message.Should().Contain("7");
ex.Message.Should().Contain("3");
ex.Message.Should().Contain("producto");
}
[Fact]
public void Constructor_InheritsFromDomainException()
{
var ex = new RubroConProductosActivosException(1, 2);
ex.Should().BeAssignableTo<DomainException>();
}
}