using WildPlumContracts.DataModels; using WildPlumContracts.Exceptions; namespace WildPlumTests.DataModelTests; [TestFixture] public class EmployeeDataModelTests { [Test] public void Validate_ThrowsException_WhenIdIsNullOrEmpty() { Assert.Multiple(() => { Assert.That(() => CreateDataModel(null!, "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(string.Empty, "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); }); } [Test] public void Validate_ThrowsException_WhenIdIsNotGuid() { Assert.That(() => CreateDataModel("invalid-guid", "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); } [Test] public void Validate_ThrowsException_WhenFullNameIsNullOrEmpty() { Assert.Multiple(() => { Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null!, "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); }); } [Test] public void Validate_ThrowsException_WhenEmailIsNullOrEmpty() { Assert.Multiple(() => { Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Jhon Doe", null!, Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Jhon Doe", string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); }); } [Test] public void Validate_ThrowsException_WhenEmailIsNotInCorrectFormat() { Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John doe", "test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "john doe", "test@", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "john doe", "test@gmail", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); } [Test] public void Validate_ThrowsException_WhenRoleIdIsNullOrEmpty() { Assert.Multiple(() => { Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", null!, DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", string.Empty, DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); }); } [Test] public void Validate_ThrowsException_WhenRoleIdIsNotGuid() { Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", "invalid-guid", DateTime.UtcNow, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); } [Test] public void Validate_ThrowsException_WhenBirthDateIsLessThan16YearsAgo() { var birthDate = DateTime.Now.AddYears(-15); // less than 16 years ago Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), birthDate, DateTime.UtcNow, false).Validate(), Throws.TypeOf()); } [Test] public void Validate_ThrowsException_WhenEmploymentDateIsBeforeBirthDate() { var birthDate = DateTime.Now.AddYears(-18); // valid birth date var employmentDate = DateTime.Now.AddYears(-19); // employment date before birth date Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), birthDate, employmentDate, false).Validate(), Throws.TypeOf()); } [Test] public void Validate_ThrowsException_WhenEmploymentDateIsLessThan16YearsAfterBirthDate() { var birthDate = DateTime.Now.AddYears(-17); // birth date more than 16 years ago var employmentDate = DateTime.Now.AddYears(-16); // employment date less than 16 years after birth date Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com" , Guid.NewGuid().ToString(), birthDate, employmentDate, false).Validate(), Throws.TypeOf()); } [Test] public void AllFieldsAreCorrectTest() { var id = Guid.NewGuid().ToString(); var fullName = "John Doe"; var email = "bbbbb@gmail.com"; var roleId = Guid.NewGuid().ToString(); var birthDate = DateTime.Now.AddYears(-20); var employmentDate = DateTime.Now.AddYears(-2); var employeeData = CreateDataModel(id, fullName, email, roleId, birthDate, employmentDate, false); Assert.That(() => employeeData.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(employeeData.Id, Is.EqualTo(id)); Assert.That(employeeData.FullName, Is.EqualTo(fullName)); Assert.That(employeeData.Email, Is.EqualTo(email)); Assert.That(employeeData.RoleId, Is.EqualTo(roleId)); Assert.That(employeeData.BirthDate, Is.EqualTo(birthDate)); Assert.That(employeeData.EmploymentDate, Is.EqualTo(employmentDate)); }); } private static EmployeeDataModel CreateDataModel(string id, string fullName, string email, string roleId, DateTime birthDate, DateTime employmentDate, bool isDeleted) => new(id, fullName, email, roleId, birthDate, employmentDate, isDeleted); }