diff --git a/API_SQLuedo/Model/BlackList.cs b/API_SQLuedo/Model/BlackList.cs index 002b5ba..bce0cf0 100644 --- a/API_SQLuedo/Model/BlackList.cs +++ b/API_SQLuedo/Model/BlackList.cs @@ -7,6 +7,9 @@ public class BlackList public BlackList(string email, DateOnly expirationDate) { + if (email is null or "") + throw new ArgumentException("Email cannot be null or empty"); + ArgumentOutOfRangeException.ThrowIfLessThan(expirationDate, DateOnly.FromDateTime(DateTime.Now)); Email = email; ExpirationDate = expirationDate; } diff --git a/API_SQLuedo/TestEF/EntitiesTests/TestBlackListEntity.cs b/API_SQLuedo/TestEF/EntitiesTests/TestBlackListEntity.cs new file mode 100644 index 0000000..abc2ad6 --- /dev/null +++ b/API_SQLuedo/TestEF/EntitiesTests/TestBlackListEntity.cs @@ -0,0 +1,54 @@ +using Model; + +namespace TestEF.EntitiesTests; + +public class TestBlackListEntity +{ + [Fact] + public void Constructor_ShouldSetProperties_WhenCalledWithTwoParameters() + { + // Arrange + string email = "test@example.com"; + DateOnly expirationDate = DateOnly.FromDateTime(DateTime.Now.AddDays(10)); + + // Act + var blackList = new BlackList(email, expirationDate); + + // Assert + Assert.Equal(email, blackList.Email); + Assert.Equal(expirationDate, blackList.ExpirationDate); + } + + [Fact] + public void Constructor_ShouldThrowArgumentException_WhenEmailIsEmpty() + { + // Arrange + string email = string.Empty; + DateOnly expirationDate = DateOnly.FromDateTime(DateTime.Now.AddDays(10)); + + // Act & Assert + Assert.Throws(() => new BlackList(email, expirationDate)); + } + + [Fact] + public void Constructor_ShouldThrowArgumentException_WhenEmailIsNull() + { + // Arrange + string email = null; + DateOnly expirationDate = DateOnly.FromDateTime(DateTime.Now.AddDays(10)); + + // Act & Assert + Assert.Throws(() => new BlackList(email, expirationDate)); + } + + [Fact] + public void Constructor_ShouldThrowArgumentOutOfRangeException_WhenExpirationDateIsInThePast() + { + // Arrange + string email = "test@example.com"; + DateOnly expirationDate = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)); + + // Act & Assert + Assert.Throws(() => new BlackList(email, expirationDate)); + } +} \ No newline at end of file