ModuleSettingFake.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Quadarax.Application.QLiberace.Common.Attributes;
  2. using Quadarax.Application.QLiberace.Common.Settings;
  3. namespace Quadarax.Application.QLiberace.Common.Tests.Settings.Fakes
  4. {
  5. [Module("test")]
  6. public class ModuleSettingFake : ModuleSetting, IEquatable<ModuleSettingFake>
  7. {
  8. public const string DefPropertyString1 = "test1";
  9. public const string? DefPropertyString2 = null;
  10. public const string DefPropertyDateTime1String = "12.3.2022 13:02:54";
  11. public const string? DefPropertyDateTime2String = null;
  12. public const string DefPropertyTimeSpanString = "00:00:35";
  13. public const int DefPropertyInt = 35;
  14. public const bool DefPropertyBool = true;
  15. public string PropertyString1 { get; set; }
  16. public string? PropertyString2 { get; set; }
  17. public DateTime PropertyDateTime1 { get; set; }
  18. public DateTime? PropertyDateTime2 { get; set; }
  19. public TimeSpan? PropertyTimeSpan { get; set; }
  20. public int? PropertyInt { get; set; }
  21. public bool PropertyBool { get; set; }
  22. private bool InvisiblePropertyBool { get; set; }
  23. public ModuleSettingFake()
  24. {
  25. PropertyString1 = string.Empty;
  26. Reset();
  27. }
  28. public void Clear()
  29. {
  30. PropertyString1 = string.Empty;
  31. PropertyString2 = null;
  32. PropertyDateTime1 = DateTime.MinValue;
  33. PropertyDateTime2 = null;
  34. PropertyTimeSpan = null;
  35. PropertyInt = null;
  36. PropertyBool = false;
  37. InvisiblePropertyBool = true;
  38. }
  39. public void Reset()
  40. {
  41. PropertyString1 = DefPropertyString1;
  42. PropertyString2 = DefPropertyString2;
  43. PropertyDateTime1 = DateTime.Parse(DefPropertyDateTime1String);
  44. PropertyDateTime2 = string.IsNullOrEmpty(DefPropertyDateTime2String)
  45. ? (DateTime?)null
  46. : DateTime.Parse(DefPropertyDateTime2String!);
  47. PropertyTimeSpan = string.IsNullOrEmpty(DefPropertyTimeSpanString)
  48. ? (TimeSpan?)null
  49. : TimeSpan.Parse(DefPropertyTimeSpanString);
  50. PropertyInt = DefPropertyInt;
  51. PropertyBool = DefPropertyBool;
  52. InvisiblePropertyBool = true;
  53. }
  54. public bool Equals(ModuleSettingFake? other)
  55. {
  56. if (ReferenceEquals(null, other)) return false;
  57. if (ReferenceEquals(this, other)) return true;
  58. return PropertyString1 == other.PropertyString1 && PropertyString2 == other.PropertyString2 && PropertyDateTime1.Equals(other.PropertyDateTime1) && Nullable.Equals(PropertyDateTime2, other.PropertyDateTime2) && Nullable.Equals(PropertyTimeSpan, other.PropertyTimeSpan) && PropertyInt == other.PropertyInt && PropertyBool == other.PropertyBool && InvisiblePropertyBool == other.InvisiblePropertyBool;
  59. }
  60. public override bool Equals(object? obj)
  61. {
  62. if (ReferenceEquals(null, obj)) return false;
  63. if (ReferenceEquals(this, obj)) return true;
  64. if (obj.GetType() != this.GetType()) return false;
  65. return Equals((ModuleSettingFake)obj);
  66. }
  67. public override int GetHashCode()
  68. {
  69. return HashCode.Combine(PropertyString1, PropertyString2, PropertyDateTime1, PropertyDateTime2, PropertyTimeSpan, PropertyInt, PropertyBool, InvisiblePropertyBool);
  70. }
  71. }
  72. }