From 25aa39e0f398357c73eec504d018b51eb548b389 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 26 May 2012 12:15:13 -0700 Subject: [PATCH] Added MinOrDefault for IEnumberable --- IISExpress/AppServer/applicationhost.config | 8 +++---- NzbDrone.Core.Test/FluentTest.cs | 26 +++++++++++++++++++++ NzbDrone.Core/Fluent.cs | 12 +++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/IISExpress/AppServer/applicationhost.config b/IISExpress/AppServer/applicationhost.config index 90fe09269..93879e48b 100644 --- a/IISExpress/AppServer/applicationhost.config +++ b/IISExpress/AppServer/applicationhost.config @@ -125,8 +125,8 @@ - - + + @@ -698,8 +698,8 @@ - - + + diff --git a/NzbDrone.Core.Test/FluentTest.cs b/NzbDrone.Core.Test/FluentTest.cs index d6dd891bf..3ae39239f 100644 --- a/NzbDrone.Core.Test/FluentTest.cs +++ b/NzbDrone.Core.Test/FluentTest.cs @@ -219,5 +219,31 @@ namespace NzbDrone.Core.Test var result = new System.Text.UTF8Encoding().GetBytes(resultString); result.Length.Should().Be(11); } + + [Test] + public void MinOrDefault_should_return_zero_when_collection_is_empty() + { + //Setup + + + //Act + var result = (new List()).MinOrDefault(); + + //Resolve + result.Should().Be(0); + } + + [Test] + public void MinOrDefault_should_return_max_when_collection_is_not_empty() + { + //Setup + var list = new List { 6, 4, 5, 3, 8, 10 }; + + //Act + var result = list.MinOrDefault(); + + //Resolve + result.Should().Be(3); + } } } diff --git a/NzbDrone.Core/Fluent.cs b/NzbDrone.Core/Fluent.cs index a66ccbe20..618c47983 100644 --- a/NzbDrone.Core/Fluent.cs +++ b/NzbDrone.Core/Fluent.cs @@ -57,7 +57,7 @@ namespace NzbDrone.Core { var intList = ints.ToList(); - if (intList.Count() == 0) + if (!intList.Any()) return 0; return intList.Max(); @@ -142,5 +142,15 @@ namespace NzbDrone.Core return String.Format("{0:N" + precision + "} {1}", size, suffix); } + + public static int MinOrDefault(this IEnumerable ints) + { + var intsList = ints.ToList(); + + if (!intsList.Any()) + return 0; + + return intsList.Min(); + } } }