Skip to content

Commit

Permalink
Commenting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre321 committed Jul 3, 2015
1 parent fca12dc commit 8b9bb32
Showing 1 changed file with 51 additions and 24 deletions.
75 changes: 51 additions & 24 deletions LinqToAnything.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,43 @@ public class Tests
[Test]
public void CanSkipAndTake()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;

IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(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)));

}

[Test]
public void CanDoACountWithAFilter()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);

//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(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<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;

IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Name != null);
Expand All @@ -58,7 +66,8 @@ public void CanDoACountWithANullComparison()
[Test]
public void CanDoACountWithNoIllEffect()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;

IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);

Expand All @@ -70,7 +79,8 @@ public void CanDoACountWithNoIllEffect()
[Test]
public void CanDoATakeWithNoIllEffectOnOtherQueries()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;

IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var somethingElse = pq.Take(5);
Expand All @@ -83,7 +93,8 @@ public void CanDoATakeWithNoIllEffectOnOtherQueries()
[Test]
public void CanDoASelectWithNoIllEffectOnOtherQueries()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;

var pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource).Select(e => new SomeEntityVm()
{
Expand All @@ -100,7 +111,8 @@ public void CanDoASelectWithNoIllEffectOnOtherQueries()
[Test]
public void CanWorkWithoutQuery()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;

IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);

Expand All @@ -116,7 +128,8 @@ public void CanWorkWithoutQuery()
[Test]
public void CanHandleAProjection()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Select(s => new Projection() { Item = s.Name });
Assert.AreEqual("Item 01", items.ToArray().First().Item);
Expand All @@ -125,7 +138,8 @@ public void CanHandleAProjection()
[Test]
public void CanHandleAMethodCallWhereClause()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Name.Contains("07"));
Assert.AreEqual("Item 07", items.ToArray().Single().Name);
Expand All @@ -134,7 +148,8 @@ public void CanHandleAMethodCallWhereClause()
[Test]
public void CanHandleAnOperatorWhereClause()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Name == "Item 07");
Assert.AreEqual("Item 07", items.ToArray().Single().Name);
Expand All @@ -144,7 +159,8 @@ public void CanHandleAnOperatorWhereClause()
[Test]
public void CanHandleAnOperatorWhereClauseAgainstAVariable()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var variable = "Item 07";
var items = pq.Where(s => s.Name == variable);
Expand All @@ -153,7 +169,8 @@ public void CanHandleAnOperatorWhereClauseAgainstAVariable()
[Test]
public void CanHandleASecondWhereClauseAfterACount()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Name == "Item 07");
var count = items.Count();
Expand All @@ -166,7 +183,8 @@ public void CanHandleASecondWhereClauseAfterACount()
[Test]
public void CanHandleAnOperatorWhereClauseOnAValueType()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Index != 0 && s.Index == 7);
Assert.AreEqual("Item 07", items.ToArray().Single().Name);
Expand All @@ -177,7 +195,8 @@ public void CanHandleAnOperatorWhereClauseOnAValueType()
[Test]
public void CanHandleAnAndAlsoWhereClause()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Name == "Item 07" && s.Name == "Item 07");
Assert.AreEqual("Item 07", items.ToArray().Single().Name);
Expand All @@ -186,7 +205,8 @@ public void CanHandleAnAndAlsoWhereClause()
[Test]
public void CanHandleAnOrElseWhereClause()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Name == "Item 07" || s.Name == "Item 08");
Assert.AreEqual("Item 07", items.ToArray().First().Name);
Expand All @@ -197,7 +217,8 @@ public void CanHandleAnOrElseWhereClause()
[Test]
public void CanHandleAnEndsWithMethodCallWhereClause()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Where(s => s.Name.EndsWith("07"));
Assert.AreEqual("Item 07", items.ToArray().Single().Name);
Expand All @@ -206,7 +227,8 @@ public void CanHandleAnEndsWithMethodCallWhereClause()
[Test]
public void CanHandleASkipATakeAndAProjection()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Skip(1).Take(1).Select(s => new Projection { Item = s.Name }).ToArray();
Assert.AreEqual(1, Skipped);
Expand All @@ -217,7 +239,8 @@ public void CanHandleASkipATakeAndAProjection()
[Test]
public void CanHandleAProjectionASkipAndATake()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.Skip(1).Take(1).Select(s => new Projection { Item = s.Name }).ToArray();
Assert.AreEqual(1, Skipped);
Expand All @@ -229,7 +252,8 @@ public void CanHandleAProjectionASkipAndATake()
[Test]
public void CanHandleAProjectionAndACount()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var someEntities = pq
.Where(i => i.Name.Contains("07"));
Expand All @@ -244,6 +268,7 @@ public void CanHandleAProjectionAndACount()
[Test]
public void CanHandleAProjectionAndACountAgainstIncompleteProvider()
{
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => IncompleteDataSource(info);
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var someEntities = pq
Expand All @@ -257,6 +282,7 @@ public void CanHandleAProjectionAndACountAgainstIncompleteProvider()
[Test, Ignore("Not implemented")]
public void CanHandleAProjectionAndACountAgainstLambdaProvider()
{
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => LambdaDataSource(info);
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var someEntities = pq;
Expand All @@ -272,7 +298,8 @@ public void CanHandleAProjectionAndACountAgainstLambdaProvider()
[Test]
public void CanHandleAProjectionASkipAndAnOrderByDesc()
{
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = (info) => SomeDataSource(info);
//Given an IQueryable made against a simple datasource
Func<QueryInfo, IEnumerable<SomeEntity>> getPageFromDataSource = SomeDataAccessMethod;
var pq = new DelegateQueryable<SomeEntity>(getPageFromDataSource);
var items = pq.OrderByDescending(e => e.Name).Skip(1).Take(1)
.Select(s => new Projection { Item = s.Name }).ToArray();
Expand Down Expand Up @@ -322,7 +349,7 @@ public void CanApplyAQueryInfo()


// this method could call a sproc, or a webservice etc.
static IEnumerable<SomeEntity> SomeDataSource(QueryInfo qi)
static IEnumerable<SomeEntity> SomeDataAccessMethod(QueryInfo qi)
{
Skipped = qi.Skip;
Taken = qi.Take;
Expand Down

0 comments on commit 8b9bb32

Please sign in to comment.