BaseDaoTest.cs 2.4 KB

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