Skip to content

Commit

Permalink
Added test that asserts multiple where call chain with Logical AND
Browse files Browse the repository at this point in the history
  • Loading branch information
mehfuzh committed Dec 8, 2010
1 parent ddf8c4f commit c4e4085
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Source/LinqExtender.Tests/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace LinqExtender.Tests
{
public class BaseFixture
{
protected string ReadTestCase()
protected string ReadExpected()
{
var frame = new StackTrace(1).GetFrame(0);

Expand All @@ -23,7 +23,7 @@ protected string ReadTestCase()
return expected;
}

protected string RemoveEscape(StringBuilder builder)
protected string ReadSource(StringBuilder builder)
{
string content = builder.ToString();
return Regex.Replace(content, "[\r\n\t]", string.Empty);
Expand Down
4 changes: 2 additions & 2 deletions Source/LinqExtender.Tests/CustomAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void ShouldAssertObjectNameAsSpecifiedInNameAttribute()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -35,7 +35,7 @@ public void ShouldAssertPropertyNameAsSpeficiedInNameAttribute()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}
}
}
12 changes: 8 additions & 4 deletions Source/LinqExtender.Tests/LinqExtender.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -31,15 +31,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.5.8.10295, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ThirdParty\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<HintPath>..\ThirdParty\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BaseFixture.cs" />
Expand Down Expand Up @@ -91,6 +92,9 @@
<EmbeddedResource Include="Cases\ShouldAssertSimpleWhereThatHasMethodCall.txt" />
<EmbeddedResource Include="Cases\ShouldAssertPropertyNameAsSpeficiedInNameAttribute.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Cases\ShouldConcatMultipleWhereCallsWithAndOperator.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
33 changes: 24 additions & 9 deletions Source/LinqExtender.Tests/LinqQueryTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using System.Text;
using NUnit.Framework;
using System;

namespace LinqExtender.Tests
{
Expand All @@ -18,7 +19,7 @@ public void ShouldAssertSimpleSelect()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -33,7 +34,7 @@ public void ShouldAssertSimpleWhereClause()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -49,7 +50,7 @@ public void ShouldAssertSimpleWhereWithLogicalExpression()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));

}

Expand All @@ -67,7 +68,7 @@ public void ShouldAssertWhereWithNestedLeftLogicalExpression()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -83,7 +84,7 @@ public void ShouldAssertWhereWithtNestedRightLogicalExpression()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -99,7 +100,7 @@ public void ShouldAssertWhereWithNestedLeftAndRightLogicaExpression()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -114,7 +115,7 @@ orderby book.Author

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -129,7 +130,7 @@ orderby book.Author descending

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
Expand All @@ -144,9 +145,23 @@ public void ShouldAssertSimpleWhereThatHasMethodCall()

query.Count();

Assert.AreEqual(ReadTestCase(), RemoveEscape(builder));
Assert.AreEqual(ReadExpected(), ReadSource(builder));
}

[Test]
public void ShouldConcatMultipleWhereCallsWithLogicalAnd()
{
var builder = new StringBuilder();
var context = new TextContext<Book>(new StringWriter(builder));

var query = context.Where(x => x.Id == 1).Where(x => x.Author == "Scott");

query.FirstOrDefault();

Assert.AreEqual(ReadExpected(), ReadSource(builder));
}


private string GetAuthorName()
{
return "Tom";
Expand Down
17 changes: 16 additions & 1 deletion Source/Queryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,26 @@ public static IQueryable<TSource> OrderBy<TSource, TKey>(this IQueryContext<TSou

public static IQueryable<TSource> OrderByDescending<TSource, TKey>(this IQueryContext<TSource> source, Expression<Func<TSource, TKey>> keySelector)
{
MethodInfo currentMethod = (MethodInfo)MethodInfo.GetCurrentMethod();
var currentMethod = (MethodInfo)MethodInfo.GetCurrentMethod();
var args = new[] { typeof(TSource), typeof(TKey) };
return CreateQuery<TSource, TSource, Func<TSource, TKey>>(source, currentMethod, keySelector, args);
}

public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IQueryContext<TOuter> outer,
IQueryContext<TInner> inner,
Expression<Func<TOuter, TKey>> outerKeySelector,
Expression<Func<TInner, TKey>> innerKeySelector,
Expression<Func<TOuter, TInner, TResult>> resultSelector){

return null;
}


public static IEnumerable<TSource> Intersect<TSource>(this IQueryContext<TSource> first, IEnumerable<TSource> second)
{
return null;
}

private static IQueryable<TResult> CreateQuery<TSource, TResult, TDelegate>(IQueryContext<TSource> source,
MethodInfo methodInfo,
Expression<TDelegate> expression,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqExtender", "..\LinqExtender.csproj", "{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqExtender.Tests", "..\LinqExtender.Tests\LinqExtender.Tests.csproj", "{BA30AD53-4E10-4610-BDD2-BB823DF0325B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Release|Any CPU.Build.0 = Release|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ..\LinqExtender.csproj
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqExtender", "..\LinqExtender.csproj", "{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqExtender.Tests", "..\LinqExtender.Tests\LinqExtender.Tests.csproj", "{BA30AD53-4E10-4610-BDD2-BB823DF0325B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2171F32-6AB4-4BA4-920B-EB1D28F5F7F2}.Release|Any CPU.Build.0 = Release|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA30AD53-4E10-4610-BDD2-BB823DF0325B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ..\LinqExtender.csproj
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file modified Source/ThirdParty/nunit.framework.dll
Binary file not shown.

0 comments on commit c4e4085

Please sign in to comment.