From ba4193cc463dcab0f8fbb82824f7994534fbb969 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 4 Oct 2013 21:49:54 -0700 Subject: [PATCH] CommandComparer supports IEnumerables now --- .../Commands/CommandEqualityComparerFixture.cs | 11 ++++++----- .../Messaging/Commands/CommandEqualityComparer.cs | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs b/src/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs index 34d4b1d30..24193ac48 100644 --- a/src/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs +++ b/src/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs @@ -1,4 +1,5 @@ -using FluentAssertions; +using System.Collections.Generic; +using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch; @@ -24,8 +25,8 @@ public void should_return_true_when_there_are_no_properties() [Test] public void should_return_true_when_single_property_matches() { - var command1 = new EpisodeSearchCommand { EpisodeId = 1 }; - var command2 = new EpisodeSearchCommand { EpisodeId = 1 }; + var command1 = new EpisodeSearchCommand { EpisodeIds = new List{ 1 } }; + var command2 = new EpisodeSearchCommand { EpisodeIds = new List { 1 } }; CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeTrue(); } @@ -42,8 +43,8 @@ public void should_return_true_when_multiple_properties_match() [Test] public void should_return_false_when_single_property_doesnt_match() { - var command1 = new EpisodeSearchCommand { EpisodeId = 1 }; - var command2 = new EpisodeSearchCommand { EpisodeId = 2 }; + var command1 = new EpisodeSearchCommand { EpisodeIds = new List { 1 } }; + var command2 = new EpisodeSearchCommand { EpisodeIds = new List { 2 } }; CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse(); } diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs b/src/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs index 38017fe4e..5f6ef67be 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections; using System.Collections.Generic; using System.Linq; @@ -46,7 +48,18 @@ public bool Equals(Command x, Command y) return false; } - if (!xValue.Equals(yValue)) + if (typeof(IEnumerable).IsAssignableFrom(xProperty.PropertyType)) + { + var xValueCollection = ((IEnumerable)xValue).Cast().OrderBy(t => t); + var yValueCollection = ((IEnumerable)yValue).Cast().OrderBy(t => t); + + if (!xValueCollection.SequenceEqual(yValueCollection)) + { + return false; + } + } + + else if (!xValue.Equals(yValue)) { return false; }