From a087c899038d8b710bf235b52d6fbf7f28c68913 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 26 Jun 2012 11:27:03 -0700 Subject: [PATCH] Added tests for null list in Min/Max or Default --- NzbDrone.Core.Test/FluentTest.cs | 28 +++++++++++++++++++++++++++- NzbDrone.Core/Fluent.cs | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/NzbDrone.Core.Test/FluentTest.cs b/NzbDrone.Core.Test/FluentTest.cs index 3ae39239f..5974ba814 100644 --- a/NzbDrone.Core.Test/FluentTest.cs +++ b/NzbDrone.Core.Test/FluentTest.cs @@ -192,6 +192,19 @@ namespace NzbDrone.Core.Test result.Should().Be(10); } + [Test] + public void MaxOrDefault_should_return_zero_when_collection_is_null() + { + //Setup + List list = null; + + //Act + var result = list.MaxOrDefault(); + + //Resolve + result.Should().Be(0); + } + [Test] public void Truncate_should_truncate_strings_to_max_specified_number_of_bytes() { @@ -234,7 +247,7 @@ namespace NzbDrone.Core.Test } [Test] - public void MinOrDefault_should_return_max_when_collection_is_not_empty() + public void MinOrDefault_should_return_min_when_collection_is_not_empty() { //Setup var list = new List { 6, 4, 5, 3, 8, 10 }; @@ -245,5 +258,18 @@ namespace NzbDrone.Core.Test //Resolve result.Should().Be(3); } + + [Test] + public void MinOrDefault_should_return_zero_when_collection_is_null() + { + //Setup + List list = null; + + //Act + var result = list.MinOrDefault(); + + //Resolve + result.Should().Be(0); + } } } diff --git a/NzbDrone.Core/Fluent.cs b/NzbDrone.Core/Fluent.cs index 8ce8d870a..98e484f1d 100644 --- a/NzbDrone.Core/Fluent.cs +++ b/NzbDrone.Core/Fluent.cs @@ -55,6 +55,9 @@ namespace NzbDrone.Core public static int MaxOrDefault(this IEnumerable ints) { + if (ints == null) + return 0; + var intList = ints.ToList(); if (!intList.Any())