feat(domain): RubroConProductosActivosException + test (closes #41)

Co-authored-by: fix/issue-41-rubro-deactivation-guard
This commit is contained in:
2026-04-19 17:08:23 -03:00
parent e33e9f332e
commit e9d1e3237d
2 changed files with 44 additions and 0 deletions

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>();
}
}