diff --git a/LinqToAnything.Tests/Tests.cs b/LinqToAnything.Tests/Tests.cs index 4c3b253..56a647a 100644 --- a/LinqToAnything.Tests/Tests.cs +++ b/LinqToAnything.Tests/Tests.cs @@ -17,15 +17,17 @@ public class Tests [Test] public void CanSkipAndTake() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); + //When I skip and then take var items = pq.Skip(3).Take(2).ToArray(); + //Then the correct items should be returned Assert.AreEqual(3, Skipped); Assert.AreEqual(2, Taken); - Assert.AreEqual("Item 04,Item 05", string.Join(",", items.Select(i => i.Name))); } @@ -33,19 +35,25 @@ public void CanSkipAndTake() [Test] public void CanDoACountWithAFilter() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); - + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); + + //When a Contains method is called for a specific item var items = pq.Where(s => s.Name.Contains("07")); - var count = items.Count(); + //Then the result should contain a single item + var count = items.Count(); Assert.AreEqual(1, count); + //And the item should be that item + Assert.AreEqual("Item 07", items.Single().Name); } [Test] public void CanDoACountWithANullComparison() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Name != null); @@ -58,7 +66,8 @@ public void CanDoACountWithANullComparison() [Test] public void CanDoACountWithNoIllEffect() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); @@ -70,7 +79,8 @@ public void CanDoACountWithNoIllEffect() [Test] public void CanDoATakeWithNoIllEffectOnOtherQueries() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var somethingElse = pq.Take(5); @@ -83,7 +93,8 @@ public void CanDoATakeWithNoIllEffectOnOtherQueries() [Test] public void CanDoASelectWithNoIllEffectOnOtherQueries() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; var pq = new DelegateQueryable(getPageFromDataSource).Select(e => new SomeEntityVm() { @@ -100,7 +111,8 @@ public void CanDoASelectWithNoIllEffectOnOtherQueries() [Test] public void CanWorkWithoutQuery() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); @@ -116,7 +128,8 @@ public void CanWorkWithoutQuery() [Test] public void CanHandleAProjection() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Select(s => new Projection() { Item = s.Name }); Assert.AreEqual("Item 01", items.ToArray().First().Item); @@ -125,7 +138,8 @@ public void CanHandleAProjection() [Test] public void CanHandleAMethodCallWhereClause() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Name.Contains("07")); Assert.AreEqual("Item 07", items.ToArray().Single().Name); @@ -134,7 +148,8 @@ public void CanHandleAMethodCallWhereClause() [Test] public void CanHandleAnOperatorWhereClause() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Name == "Item 07"); Assert.AreEqual("Item 07", items.ToArray().Single().Name); @@ -144,7 +159,8 @@ public void CanHandleAnOperatorWhereClause() [Test] public void CanHandleAnOperatorWhereClauseAgainstAVariable() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var variable = "Item 07"; var items = pq.Where(s => s.Name == variable); @@ -153,7 +169,8 @@ public void CanHandleAnOperatorWhereClauseAgainstAVariable() [Test] public void CanHandleASecondWhereClauseAfterACount() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Name == "Item 07"); var count = items.Count(); @@ -166,7 +183,8 @@ public void CanHandleASecondWhereClauseAfterACount() [Test] public void CanHandleAnOperatorWhereClauseOnAValueType() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Index != 0 && s.Index == 7); Assert.AreEqual("Item 07", items.ToArray().Single().Name); @@ -177,7 +195,8 @@ public void CanHandleAnOperatorWhereClauseOnAValueType() [Test] public void CanHandleAnAndAlsoWhereClause() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Name == "Item 07" && s.Name == "Item 07"); Assert.AreEqual("Item 07", items.ToArray().Single().Name); @@ -186,7 +205,8 @@ public void CanHandleAnAndAlsoWhereClause() [Test] public void CanHandleAnOrElseWhereClause() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Name == "Item 07" || s.Name == "Item 08"); Assert.AreEqual("Item 07", items.ToArray().First().Name); @@ -197,7 +217,8 @@ public void CanHandleAnOrElseWhereClause() [Test] public void CanHandleAnEndsWithMethodCallWhereClause() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Where(s => s.Name.EndsWith("07")); Assert.AreEqual("Item 07", items.ToArray().Single().Name); @@ -206,7 +227,8 @@ public void CanHandleAnEndsWithMethodCallWhereClause() [Test] public void CanHandleASkipATakeAndAProjection() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Skip(1).Take(1).Select(s => new Projection { Item = s.Name }).ToArray(); Assert.AreEqual(1, Skipped); @@ -217,7 +239,8 @@ public void CanHandleASkipATakeAndAProjection() [Test] public void CanHandleAProjectionASkipAndATake() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var items = pq.Skip(1).Take(1).Select(s => new Projection { Item = s.Name }).ToArray(); Assert.AreEqual(1, Skipped); @@ -229,7 +252,8 @@ public void CanHandleAProjectionASkipAndATake() [Test] public void CanHandleAProjectionAndACount() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; IQueryable pq = new DelegateQueryable(getPageFromDataSource); var someEntities = pq .Where(i => i.Name.Contains("07")); @@ -244,6 +268,7 @@ public void CanHandleAProjectionAndACount() [Test] public void CanHandleAProjectionAndACountAgainstIncompleteProvider() { + //Given an IQueryable made against a simple datasource Func> getPageFromDataSource = (info) => IncompleteDataSource(info); IQueryable pq = new DelegateQueryable(getPageFromDataSource); var someEntities = pq @@ -257,6 +282,7 @@ public void CanHandleAProjectionAndACountAgainstIncompleteProvider() [Test, Ignore("Not implemented")] public void CanHandleAProjectionAndACountAgainstLambdaProvider() { + //Given an IQueryable made against a simple datasource Func> getPageFromDataSource = (info) => LambdaDataSource(info); IQueryable pq = new DelegateQueryable(getPageFromDataSource); var someEntities = pq; @@ -272,7 +298,8 @@ public void CanHandleAProjectionAndACountAgainstLambdaProvider() [Test] public void CanHandleAProjectionASkipAndAnOrderByDesc() { - Func> getPageFromDataSource = (info) => SomeDataSource(info); + //Given an IQueryable made against a simple datasource + Func> getPageFromDataSource = SomeDataAccessMethod; var pq = new DelegateQueryable(getPageFromDataSource); var items = pq.OrderByDescending(e => e.Name).Skip(1).Take(1) .Select(s => new Projection { Item = s.Name }).ToArray(); @@ -322,7 +349,7 @@ public void CanApplyAQueryInfo() // this method could call a sproc, or a webservice etc. - static IEnumerable SomeDataSource(QueryInfo qi) + static IEnumerable SomeDataAccessMethod(QueryInfo qi) { Skipped = qi.Skip; Taken = qi.Take;