BaseDaoTest.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.ComponentModel.DataAnnotations.Schema;
  2. using qdr.fnd.core.test;
  3. using Quadarax.Application.QLiberace.Base.Entities;
  4. using Quadarax.Application.QLiberace.Common.Entities.Base;
  5. using Quadarax.Foundation.Core.Reflection;
  6. namespace Quadarax.Application.QLiberace.Base.Tests.Entities.Base
  7. {
  8. public abstract class BaseDaoTest<TDao> : DaoTest<TDao, long> where TDao : QlbrcEntityWithId
  9. {
  10. protected void CheckHasTracked(string customMessage)
  11. {
  12. if (string.IsNullOrEmpty(customMessage))
  13. customMessage = "Has no ITracked implemented";
  14. Assert.IsTrue(typeof(TDao).IsAssignableTo(typeof(ITracked)), customMessage);
  15. }
  16. protected void CheckClassTable(string customMessage)
  17. {
  18. if (string.IsNullOrEmpty(customMessage))
  19. customMessage = "Has no Table attribute";
  20. Assert.IsTrue(AttributeQuery<TableAttribute>.Has(typeof(TDao)), customMessage);
  21. var attr = AttributeQuery<TableAttribute>.Get(typeof(TDao));
  22. Assert.IsFalse(string.IsNullOrEmpty(attr.Schema), "Attribute Table has no Schema set");
  23. }
  24. protected void CheckColumnCode(int? alternativeLength)
  25. {
  26. if (alternativeLength == null)
  27. alternativeLength = 100;
  28. CheckColumnMappings("Code", string.Empty,true, alternativeLength);
  29. }
  30. protected void CheckColumnName(int? alternativeLength)
  31. {
  32. if (alternativeLength == null)
  33. alternativeLength = 200;
  34. CheckColumnMappings("Name", string.Empty,true, alternativeLength);
  35. }
  36. protected void CheckColumnDescription(int? alternativeLength)
  37. {
  38. if (alternativeLength == null)
  39. alternativeLength = 500;
  40. CheckColumnMappings("Description", string.Empty,false, alternativeLength);
  41. }
  42. protected void CheckColumnModuleCode(int? alternativeLength)
  43. {
  44. if (alternativeLength == null)
  45. alternativeLength = 10;
  46. CheckColumnMappings("ModuleCode", string.Empty,true, alternativeLength);
  47. }
  48. protected void CheckColumnEnabled(bool isRequired, bool defaultValue)
  49. {
  50. CheckColumnMappings("IsEnabled", string.Empty,isRequired,null, defaultValue);
  51. }
  52. }
  53. }