Permalink
Browse files

Added tests for null list in Min/Max or Default

  • Loading branch information...
markus101 committed Jun 26, 2012
1 parent a42d90f commit a087c899038d8b710bf235b52d6fbf7f28c68913
Showing with 30 additions and 1 deletion.
  1. +27 −1 NzbDrone.Core.Test/FluentTest.cs
  2. +3 −0 NzbDrone.Core/Fluent.cs
@@ -192,6 +192,19 @@ public void MaxOrDefault_should_return_max_when_collection_is_not_empty()
result.Should().Be(10);
}
+ [Test]
+ public void MaxOrDefault_should_return_zero_when_collection_is_null()
+ {
+ //Setup
+ List<int> 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 @@ public void MinOrDefault_should_return_zero_when_collection_is_empty()
}
[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<int> { 6, 4, 5, 3, 8, 10 };
@@ -245,5 +258,18 @@ public void MinOrDefault_should_return_max_when_collection_is_not_empty()
//Resolve
result.Should().Be(3);
}
+
+ [Test]
+ public void MinOrDefault_should_return_zero_when_collection_is_null()
+ {
+ //Setup
+ List<int> list = null;
+
+ //Act
+ var result = list.MinOrDefault();
+
+ //Resolve
+ result.Should().Be(0);
+ }
}
}
View
@@ -55,6 +55,9 @@ public static string ParentUriString(this Uri uri)
public static int MaxOrDefault(this IEnumerable<int> ints)
{
+ if (ints == null)
+ return 0;
+
var intList = ints.ToList();
if (!intList.Any())

0 comments on commit a087c89

Please sign in to comment.