Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement equality checks for providers #9941

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Notifications;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
using NzbDrone.Test.Common;

Expand All @@ -15,9 +14,9 @@ namespace NzbDrone.Core.Test.NotificationTests
[TestFixture]
public class NotificationBaseFixture : TestBase
{
private class TestSetting : IProviderConfig
private class TestSetting : NotificationSettingsBase<TestSetting>
{
public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult();
}
Expand Down
7 changes: 3 additions & 4 deletions src/NzbDrone.Core/Download/Clients/Aria2/Aria2Settings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients.Aria2
Expand All @@ -13,9 +12,9 @@ public Aria2SettingsValidator()
}
}

public class Aria2Settings : IProviderConfig
public class Aria2Settings : DownloadClientSettingsBase<Aria2Settings>
{
private static readonly Aria2SettingsValidator Validator = new Aria2SettingsValidator();
private static readonly Aria2SettingsValidator Validator = new ();

public Aria2Settings()
{
Expand Down Expand Up @@ -44,7 +43,7 @@ public Aria2Settings()
[FieldDefinition(5, Label = "Directory", Type = FieldType.Textbox, HelpText = "DownloadClientAriaSettingsDirectoryHelpText")]
public string Directory { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using FluentValidation;
using Newtonsoft.Json;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths;

Expand All @@ -18,15 +17,15 @@ public TorrentBlackholeSettingsValidator()
}
}

public class TorrentBlackholeSettings : IProviderConfig
public class TorrentBlackholeSettings : DownloadClientSettingsBase<TorrentBlackholeSettings>
{
public TorrentBlackholeSettings()
{
MagnetFileExtension = ".magnet";
ReadOnly = true;
}

private static readonly TorrentBlackholeSettingsValidator Validator = new TorrentBlackholeSettingsValidator();
private static readonly TorrentBlackholeSettingsValidator Validator = new ();

[FieldDefinition(0, Label = "TorrentBlackholeTorrentFolder", Type = FieldType.Path, HelpText = "BlackholeFolderHelpText")]
[FieldToken(TokenField.HelpText, "TorrentBlackholeTorrentFolder", "extension", ".torrent")]
Expand All @@ -48,7 +47,7 @@ public TorrentBlackholeSettings()
[FieldDefinition(4, Label = "TorrentBlackholeSaveMagnetFilesReadOnly", Type = FieldType.Checkbox, HelpText = "TorrentBlackholeSaveMagnetFilesReadOnlyHelpText")]
public bool ReadOnly { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths;

Expand All @@ -15,9 +14,9 @@ public UsenetBlackholeSettingsValidator()
}
}

public class UsenetBlackholeSettings : IProviderConfig
public class UsenetBlackholeSettings : DownloadClientSettingsBase<UsenetBlackholeSettings>
{
private static readonly UsenetBlackholeSettingsValidator Validator = new UsenetBlackholeSettingsValidator();
private static readonly UsenetBlackholeSettingsValidator Validator = new ();

[FieldDefinition(0, Label = "UsenetBlackholeNzbFolder", Type = FieldType.Path, HelpText = "BlackholeFolderHelpText")]
[FieldToken(TokenField.HelpText, "UsenetBlackholeNzbFolder", "extension", ".nzb")]
Expand All @@ -26,7 +25,7 @@ public class UsenetBlackholeSettings : IProviderConfig
[FieldDefinition(1, Label = "BlackholeWatchFolder", Type = FieldType.Path, HelpText = "BlackholeWatchFolderHelpText")]
public string WatchFolder { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
7 changes: 3 additions & 4 deletions src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients.Deluge
Expand All @@ -17,9 +16,9 @@ public DelugeSettingsValidator()
}
}

public class DelugeSettings : IProviderConfig
public class DelugeSettings : DownloadClientSettingsBase<DelugeSettings>
{
private static readonly DelugeSettingsValidator Validator = new DelugeSettingsValidator();
private static readonly DelugeSettingsValidator Validator = new ();

public DelugeSettings()
{
Expand Down Expand Up @@ -67,7 +66,7 @@ public DelugeSettings()
[FieldDefinition(11, Label = "DownloadClientDelugeSettingsDirectoryCompleted", Type = FieldType.Textbox, Advanced = true, HelpText = "DownloadClientDelugeSettingsDirectoryCompletedHelpText")]
public string CompletedDirectory { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
30 changes: 30 additions & 0 deletions src/NzbDrone.Core/Download/Clients/DownloadClientSettingsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Equ;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients
{
public abstract class DownloadClientSettingsBase<TSettings> : IProviderConfig, IEquatable<TSettings>
where TSettings : DownloadClientSettingsBase<TSettings>
{
private static readonly MemberwiseEqualityComparer<TSettings> Comparer = MemberwiseEqualityComparer<TSettings>.ByProperties;

public abstract NzbDroneValidationResult Validate();

public bool Equals(TSettings other)
{
return Comparer.Equals(this as TSettings, other);
}

public override bool Equals(object obj)
{
return Equals(obj as TSettings);
}

public override int GetHashCode()
{
return Comparer.GetHashCode(this as TSettings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients.DownloadStation
Expand All @@ -26,9 +25,9 @@ public DownloadStationSettingsValidator()
}
}

public class DownloadStationSettings : IProviderConfig
public class DownloadStationSettings : DownloadClientSettingsBase<DownloadStationSettings>
{
private static readonly DownloadStationSettingsValidator Validator = new DownloadStationSettingsValidator();
private static readonly DownloadStationSettingsValidator Validator = new ();

[FieldDefinition(0, Label = "Host", Type = FieldType.Textbox)]
public string Host { get; set; }
Expand Down Expand Up @@ -58,7 +57,7 @@ public DownloadStationSettings()
Port = 5000;
}

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
7 changes: 3 additions & 4 deletions src/NzbDrone.Core/Download/Clients/Flood/FloodSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Download.Clients.Flood.Models;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients.Flood
Expand All @@ -17,9 +16,9 @@ public FloodSettingsValidator()
}
}

public class FloodSettings : IProviderConfig
public class FloodSettings : DownloadClientSettingsBase<FloodSettings>
{
private static readonly FloodSettingsValidator Validator = new FloodSettingsValidator();
private static readonly FloodSettingsValidator Validator = new ();

public FloodSettings()
{
Expand Down Expand Up @@ -69,7 +68,7 @@ public FloodSettings()
[FieldDefinition(10, Label = "DownloadClientFloodSettingsAddPaused", Type = FieldType.Checkbox)]
public bool AddPaused { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths;

Expand Down Expand Up @@ -34,9 +33,9 @@ public FreeboxDownloadSettingsValidator()
}
}

public class FreeboxDownloadSettings : IProviderConfig
public class FreeboxDownloadSettings : DownloadClientSettingsBase<FreeboxDownloadSettings>
{
private static readonly FreeboxDownloadSettingsValidator Validator = new FreeboxDownloadSettingsValidator();
private static readonly FreeboxDownloadSettingsValidator Validator = new ();

public FreeboxDownloadSettings()
{
Expand Down Expand Up @@ -84,7 +83,7 @@ public FreeboxDownloadSettings()
[FieldDefinition(10, Label = "DownloadClientSettingsAddPaused", Type = FieldType.Checkbox)]
public bool AddPaused { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients.Hadouken
Expand All @@ -22,9 +21,9 @@ public HadoukenSettingsValidator()
}
}

public class HadoukenSettings : IProviderConfig
public class HadoukenSettings : DownloadClientSettingsBase<HadoukenSettings>
{
private static readonly HadoukenSettingsValidator Validator = new HadoukenSettingsValidator();
private static readonly HadoukenSettingsValidator Validator = new ();

public HadoukenSettings()
{
Expand Down Expand Up @@ -57,7 +56,7 @@ public HadoukenSettings()
[FieldDefinition(6, Label = "Category", Type = FieldType.Textbox, HelpText = "DownloadClientSettingsCategoryHelpText")]
public string Category { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients.NzbVortex
Expand All @@ -23,9 +22,9 @@ public NzbVortexSettingsValidator()
}
}

public class NzbVortexSettings : IProviderConfig
public class NzbVortexSettings : DownloadClientSettingsBase<NzbVortexSettings>
{
private static readonly NzbVortexSettingsValidator Validator = new NzbVortexSettingsValidator();
private static readonly NzbVortexSettingsValidator Validator = new ();

public NzbVortexSettings()
{
Expand Down Expand Up @@ -59,7 +58,7 @@ public NzbVortexSettings()
[FieldDefinition(6, Label = "DownloadClientSettingsOlderPriority", Type = FieldType.Select, SelectOptions = typeof(NzbVortexPriority), HelpText = "DownloadClientSettingsOlderPriorityMovieHelpText")]
public int OlderMoviePriority { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
7 changes: 3 additions & 4 deletions src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Download.Clients.Nzbget
Expand All @@ -21,9 +20,9 @@ public NzbgetSettingsValidator()
}
}

public class NzbgetSettings : IProviderConfig
public class NzbgetSettings : DownloadClientSettingsBase<NzbgetSettings>
{
private static readonly NzbgetSettingsValidator Validator = new NzbgetSettingsValidator();
private static readonly NzbgetSettingsValidator Validator = new ();

public NzbgetSettings()
{
Expand Down Expand Up @@ -69,7 +68,7 @@ public NzbgetSettings()
[FieldDefinition(9, Label = "DownloadClientSettingsAddPaused", Type = FieldType.Checkbox, HelpText = "DownloadClientNzbgetSettingsAddPausedHelpText")]
public bool AddPaused { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths;

Expand All @@ -15,17 +14,17 @@ public PneumaticSettingsValidator()
}
}

public class PneumaticSettings : IProviderConfig
public class PneumaticSettings : DownloadClientSettingsBase<PneumaticSettings>
{
private static readonly PneumaticSettingsValidator Validator = new PneumaticSettingsValidator();
private static readonly PneumaticSettingsValidator Validator = new ();

[FieldDefinition(0, Label = "DownloadClientPneumaticSettingsNzbFolder", Type = FieldType.Path, HelpText = "DownloadClientPneumaticSettingsNzbFolderHelpText")]
public string NzbFolder { get; set; }

[FieldDefinition(1, Label = "DownloadClientPneumaticSettingsStrmFolder", Type = FieldType.Path, HelpText = "DownloadClientPneumaticSettingsStrmFolderHelpText")]
public string StrmFolder { get; set; }

public NzbDroneValidationResult Validate()
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
Expand Down