From 372ac79fe62b191c7421f1c7798aa5396ab978e8 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 14 Sep 2013 17:33:19 -0700 Subject: [PATCH] fixed command equality to take type into consideration. --- .../CommandEqualityComparerFixture.cs | 22 +++++++++++++++++++ NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 4 ++++ .../Commands/CommandEqualityComparer.cs | 9 +++----- NzbDrone.SignalR/BroadcastSignalRMessage.cs | 4 +++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs b/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs index f4ffc3614..34d4b1d30 100644 --- a/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs +++ b/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs @@ -1,8 +1,11 @@ using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Update.Commands; +using NzbDrone.SignalR; namespace NzbDrone.Core.Test.Messaging.Commands { @@ -71,5 +74,24 @@ namespace NzbDrone.Core.Test.Messaging.Commands CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse(); } + + + [Test] + public void should_return_false_when_only_one_has_null_property() + { + var command1 = new BroadcastSignalRMessage(null); + var command2 = new BroadcastSignalRMessage(new SignalRMessage()); + + CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse(); + } + + + [Test] + public void should_return_false_when_commands_are_diffrent_types() + { + CommandEqualityComparer.Instance.Equals(new RssSyncCommand(), new ApplicationUpdateCommand()).Should().BeFalse(); + } + + } } diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 38660dd5d..3dd0c3d08 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -232,6 +232,10 @@ {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} NzbDrone.Core + + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36} + NzbDrone.SignalR + {CADDFCE0-7509-4430-8364-2074E1EEFCA2} NzbDrone.Test.Common diff --git a/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs b/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs index d6af0276d..2b24895f1 100644 --- a/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs +++ b/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs @@ -14,6 +14,8 @@ namespace NzbDrone.Core.Messaging.Commands public bool Equals(Command x, Command y) { + if(x.GetType() != y.GetType()) return false; + var xProperties = x.GetType().GetProperties(); var yProperties = y.GetType().GetProperties(); @@ -24,12 +26,7 @@ namespace NzbDrone.Core.Messaging.Commands continue; } - var yProperty = yProperties.SingleOrDefault(p => p.Name == xProperty.Name); - - if (yProperty == null) - { - continue; - } + var yProperty = yProperties.Single(p => p.Name == xProperty.Name); var xValue = xProperty.GetValue(x, null); var yValue = yProperty.GetValue(y, null); diff --git a/NzbDrone.SignalR/BroadcastSignalRMessage.cs b/NzbDrone.SignalR/BroadcastSignalRMessage.cs index d540ab6fc..d989affc3 100644 --- a/NzbDrone.SignalR/BroadcastSignalRMessage.cs +++ b/NzbDrone.SignalR/BroadcastSignalRMessage.cs @@ -1,6 +1,8 @@ +using NzbDrone.Core.Messaging.Commands; + namespace NzbDrone.SignalR { - public class BroadcastSignalRMessage : Core.Messaging.Commands.Command + public class BroadcastSignalRMessage : Command { public SignalRMessage Body { get; private set; }