1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

CommandComparer supports IEnumerables now

This commit is contained in:
Mark McDowall 2013-10-04 21:49:54 -07:00
parent 7798e8b591
commit ba4193cc46
2 changed files with 20 additions and 6 deletions

View File

@ -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<int>{ 1 } };
var command2 = new EpisodeSearchCommand { EpisodeIds = new List<int> { 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<int> { 1 } };
var command2 = new EpisodeSearchCommand { EpisodeIds = new List<int> { 2 } };
CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse();
}

View File

@ -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<object>().OrderBy(t => t);
var yValueCollection = ((IEnumerable)yValue).Cast<object>().OrderBy(t => t);
if (!xValueCollection.SequenceEqual(yValueCollection))
{
return false;
}
}
else if (!xValue.Equals(yValue))
{
return false;
}