ModuleSettingFake.cs 3.4 KB

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