-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHasLess.cs
32 lines (29 loc) · 1.33 KB
/
HasLess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace AssertLibrary
{
using System;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
public static partial class Assert
{
/// <summary>
/// Asserts that the given collection has less than n elements.
/// </summary>
/// <param name="n">Number of elements to be less than</param>
/// <param name="collection">Collection to check</param>
/// <param name="variableName">Variable name to include in the error message (optional)</param>
public static void HasLess(int n, IEnumerable collection, string variableName = null)
{
if (collection == null)
throw new ArgumentNullException("collection");
var count = Count(collection);
Check(count < n, HasLessMessage(variableName, n, count));
}
private static string HasLessMessage(string variableName, int n, int count)
{
return variableName == null ?
string.Format(CultureInfo.CurrentCulture, "Should have less than \"{0}\" element(s) at this point but found \"{1}\" element(s).", n, count) :
string.Format(CultureInfo.CurrentCulture, "\"{0}\" should have less than \"{1}\" element(s) at this point but found \"{2}\" element(s).", variableName, n, count);
}
}
}