Added MinOrDefault for IEnumberable<int>

This commit is contained in:
Mark McDowall 2012-05-26 12:15:13 -07:00
parent aa2a3d997a
commit 25aa39e0f3
3 changed files with 41 additions and 5 deletions

View File

@ -125,8 +125,8 @@
<virtualDirectory path="/" physicalPath="%NZBDRONE_PATH%\NZBDrone.Web" /> <virtualDirectory path="/" physicalPath="%NZBDRONE_PATH%\NZBDrone.Web" />
</application> </application>
<bindings> <bindings>
<binding protocol="http" bindingInformation="*:8980:localhost" /> <binding protocol="http" bindingInformation="*:8989:localhost" />
<binding protocol="http" bindingInformation="*:8980:" /> <binding protocol="http" bindingInformation="*:8989:" />
</bindings> </bindings>
</site> </site>
<applicationDefaults applicationPool="IISExpressAppPool" /> <applicationDefaults applicationPool="IISExpressAppPool" />
@ -698,8 +698,8 @@
<system.webServer> <system.webServer>
<security> <security>
<authentication> <authentication>
<anonymousAuthentication enabled="false" /> <anonymousAuthentication enabled="true" />
<windowsAuthentication enabled="true" /> <windowsAuthentication enabled="false" />
</authentication> </authentication>
</security> </security>
</system.webServer> </system.webServer>

View File

@ -219,5 +219,31 @@ namespace NzbDrone.Core.Test
var result = new System.Text.UTF8Encoding().GetBytes(resultString); var result = new System.Text.UTF8Encoding().GetBytes(resultString);
result.Length.Should().Be(11); result.Length.Should().Be(11);
} }
[Test]
public void MinOrDefault_should_return_zero_when_collection_is_empty()
{
//Setup
//Act
var result = (new List<int>()).MinOrDefault();
//Resolve
result.Should().Be(0);
}
[Test]
public void MinOrDefault_should_return_max_when_collection_is_not_empty()
{
//Setup
var list = new List<int> { 6, 4, 5, 3, 8, 10 };
//Act
var result = list.MinOrDefault();
//Resolve
result.Should().Be(3);
}
} }
} }

View File

@ -57,7 +57,7 @@ namespace NzbDrone.Core
{ {
var intList = ints.ToList(); var intList = ints.ToList();
if (intList.Count() == 0) if (!intList.Any())
return 0; return 0;
return intList.Max(); return intList.Max();
@ -142,5 +142,15 @@ namespace NzbDrone.Core
return String.Format("{0:N" + precision + "} {1}", size, suffix); return String.Format("{0:N" + precision + "} {1}", size, suffix);
} }
public static int MinOrDefault(this IEnumerable<int> ints)
{
var intsList = ints.ToList();
if (!intsList.Any())
return 0;
return intsList.Min();
}
} }
} }