1
1

TestEnum.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Masuit.Tools.Core.Validator;
  2. using Xunit;
  3. namespace Masuit.Tools.Abstractions.Test.Validator;
  4. public enum TestEnum
  5. {
  6. Value1,
  7. Value2,
  8. Value3
  9. }
  10. public class EnumOfAttributeTests
  11. {
  12. [Theory]
  13. [InlineData(TestEnum.Value1, true)]
  14. [InlineData(TestEnum.Value2, true)]
  15. [InlineData("InvalidValue", false)]
  16. [InlineData(null, true)]
  17. public void EnumOfAttribute_ShouldValidateEnumValues(object value, bool expected)
  18. {
  19. // Arrange
  20. var attribute = new EnumOfAttribute(typeof(TestEnum));
  21. // Act
  22. var result = attribute.IsValid(value);
  23. // Assert
  24. Assert.Equal(expected, result);
  25. }
  26. [Theory]
  27. [InlineData("NotEmpty", true)]
  28. [InlineData("", false)]
  29. [InlineData(null, false)]
  30. public void NotNullOrEmptyAttribute_ShouldValidateNonEmptyValues(object value, bool expected)
  31. {
  32. // Arrange
  33. var attribute = new NotNullOrEmptyAttribute();
  34. // Act
  35. var result = attribute.IsValid(value);
  36. // Assert
  37. Assert.Equal(expected, result);
  38. }
  39. }