Permalink
Browse files

Refactoring of Linq where sub-query and Any() tests

  • Loading branch information...
1 parent e0d4d45 commit 69a71b3b1f13b07bc9d014df6d751e603b6deb98 @hazzik hazzik committed Oct 11, 2012
@@ -10,21 +10,22 @@ public class AnyTests : LinqTestCase
public void AnySublist()
{
var orders = db.Orders.Where(o => o.OrderLines.Any(ol => ol.Quantity == 5)).ToList();
- Assert.AreEqual(61, orders.Count);
+ Assert.That(orders.Count, Is.EqualTo(61));
orders = db.Orders.Where(o => o.OrderLines.Any(ol => ol.Order == null)).ToList();
- Assert.AreEqual(0, orders.Count);
+ Assert.That(orders.Count, Is.EqualTo(0));
}
[Test]
public void NestedAny()
{
var test = (from c in db.Customers
- where c.ContactName == "Bob" &&
- (c.CompanyName == "NormalooCorp" ||
- c.Orders.Any(o => o.OrderLines.Any(ol => ol.Discount < 20 && ol.Discount >= 10)))
- select c).ToList();
- Assert.AreEqual(0, test.Count);
+ where c.ContactName == "Bob" &&
+ (c.CompanyName == "NormalooCorp" ||
+ c.Orders.Any(o => o.OrderLines.Any(ol => ol.Discount < 20 && ol.Discount >= 10)))
+ select c).ToList();
+
+ Assert.That(test.Count, Is.EqualTo(0));
}
[Test]
@@ -33,17 +34,16 @@ public void ManyToManyAny()
var test = db.Orders.Where(o => o.Employee.FirstName == "test");
var result = test.Where(o => o.Employee.Territories.Any(t => t.Description == "test")).ToList();
- Assert.AreEqual(0, result.Count);
+ Assert.That(result.Count, Is.EqualTo(0));
}
- [Test]
+ [Test(Description = "NH-2654")]
public void AnyWithCount()
{
- //NH-2654
var result = db.Orders
.Any(p => p.OrderLines.Count == 0);
- Assert.IsFalse(result);
+ Assert.That(result, Is.False);
}
}
}
@@ -9,22 +9,22 @@ public static class AssertOrderedBy
public static void Ascending<T>(IList<T> result, Func<T, IComparable> keySelector)
{
if (result == null) throw new ArgumentNullException("result");
- for (int i = 0; i < result.Count - 1; i++)
+ for (var i = 0; i < result.Count - 1; i++)
{
var first = result[i];
var second = result[i + 1];
- Assert.LessOrEqual(keySelector(first), keySelector(second));
+ Assert.That(keySelector(first), Is.LessThanOrEqualTo(keySelector(second)));
}
}
public static void Descending<T>(IList<T> result, Func<T, IComparable> keySelector)
{
if (result == null) throw new ArgumentNullException("result");
- for (int i = 0; i < result.Count - 1; i++)
+ for (var i = 0; i < result.Count - 1; i++)
{
var first = result[i];
var second = result[i + 1];
- Assert.GreaterOrEqual(keySelector(first), keySelector(second));
+ Assert.That(keySelector(first), Is.GreaterThanOrEqualTo(keySelector(second)));
}
}
}
Oops, something went wrong.

0 comments on commit 69a71b3

Please sign in to comment.