Skip to content

Commit

Permalink
First phase of Queryable Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jrote1 committed May 12, 2016
1 parent 90734af commit b70c336
Show file tree
Hide file tree
Showing 49 changed files with 3,375 additions and 1 deletion.
137 changes: 137 additions & 0 deletions Source/RethinkDb.Driver.Linq.Tests/AllTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace RethinkDb.Driver.Linq.Tests
{
public class AllTests : BaseLinqTest
{
[Fact]
public void ForAll_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1"
},
new TestObject
{
Name = "TestObject1"
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName ).Filter( x => x["Name"].Eq( "TestObject1" ).Not() ).Count();

var result = GetQueryable<TestObject>( TableName, expected ).All( x => x.Name == "TestObject1" );

Assert.True( result );
}

[Fact]
public void ForAllOnSubProperty_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Information = new Information
{
Name = "TestObject1"
}
},
new TestObject
{
Information = new Information
{
Name = "TestObject1"
}
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName ).Filter( x => x["Information"]["Name"].Eq( "TestObject1" ).Not() ).Count();

var result = GetQueryable<TestObject>( TableName, expected ).All( x => x.Information.Name == "TestObject1" );

Assert.True( result );
}

[Fact]
public void WhenIsFilteredByAllClause_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1",
Locations = new List<string> {"Hello" }
},
new TestObject
{
Name = "TestObject2",
Locations = new List<string> { "Hello2" }
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName )
.Filter( x => x["Locations"].Filter( l => l.Eq( "Hello" ).Not() ).Count().Eq( 0 ) );

var queryable = GetQueryable<TestObject>( TableName, expected );

var result = queryable
.Where( x => x.Locations.All( l => l == "Hello" ) )
.ToList();

Assert.Equal( 1, result.Count );
}

[Fact]
public void WhenIsFilteredByAllClauseNot_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1",
Locations = new List<string> {"Hello" }
},
new TestObject
{
Name = "TestObject2",
Locations = new List<string> { "Hello2" }
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName )
.Filter( x => x["Locations"].Filter( l => l.Eq( "Hello" ).Not() ).Count().Eq( 0 ).Not() );

var queryable = GetQueryable<TestObject>( TableName, expected );

var result = queryable
.Where( x => !x.Locations.All( l => l == "Hello" ) )
.ToList();

Assert.Equal( 1, result.Count );
}

public class TestObject
{
public string Name { get; set; }
public Information Information { get; set; }
public List<string> Locations { get; set; }
}
}

public class Information
{
public string Name { get; set; }
}
}
236 changes: 236 additions & 0 deletions Source/RethinkDb.Driver.Linq.Tests/AnyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace RethinkDb.Driver.Linq.Tests
{
public class AnyTests : BaseLinqTest
{
[Fact]
public void ForSimpleAnyQuery_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1"
},
new TestObject
{
Name = "TestObject2"
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName ).Count();

var result = GetQueryable<TestObject>( TableName, expected ).Any();

Assert.True( result );
}

[Fact]
public void ForSimpleAnyQueryWithCondition_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1"
},
new TestObject
{
Name = "TestObject2"
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName ).Filter( x => x["Name"].Eq( "TestObject1" ) ).Count();

var result = GetQueryable<TestObject>( TableName, expected ).Any( x => x.Name == "TestObject1" );

Assert.True( result );
}

[Fact]
public void WhenIsFilteredByAnyClauseAndNot_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1",
Locations = new List<string> {"Hello" }
},
new TestObject
{
Name = "TestObject2",
Locations = new List<string>()
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName )
.Filter( x => x["Locations"].Count().Gt( 0 ).Not() );

var queryable = GetQueryable<TestObject>( TableName, expected );

var result = queryable
.Where( x => !x.Locations.Any() )
.ToList();

Assert.Equal( 1, result.Count );
}

[Fact]
public void WhenIsFilteredByAnyClauseWithSubAny_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1",
Locations = new List<string> {"Hello"}
},
new TestObject
{
Name = "TestObject2",
Resources = new List<Resource>
{
new Resource
{
Locations = new List<Location>
{
new Location
{
Usages = new List<string>
{
"First usage"
}
}
}
}
}
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName )
.Filter( x => x["Resources"].Filter( resource => resource["Locations"].Filter( location => location["Usages"].Count().Gt( 0 ) ).Count().Gt( 0 ) ).Count().Gt( 0 ) );

var queryable = GetQueryable<TestObject>( TableName, expected );

var result = queryable
.Where( x => x.Resources.Any( resource => resource.Locations.Any( l => l.Usages.Any() ) ) )
.ToList();

Assert.Equal( 1, result.Count );
}

[Fact]
public void WhenIsFilteredByAnyClauseAndEqualsFalse_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1",
Locations = new List<string> {"Hello" }
},
new TestObject
{
Name = "TestObject2",
Locations = new List<string>()
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName )
.Filter( x => x["Locations"].Count().Gt( 0 ).Eq( false ) );

var queryable = GetQueryable<TestObject>( TableName, expected );

var result = queryable
.Where( x => x.Locations.Any() == false )
.ToList();

Assert.Equal( 1, result.Count );
Assert.Equal( 0, result[0].Locations.Count );
}


[Fact]
public void WhenIsFilteredByAnyClause_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1",
Locations = new List<string> {"Hello" }
},
new TestObject
{
Name = "TestObject2",
Locations = new List<string>()
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName )
.Filter( x => x["Locations"].Count().Gt( 0 ) );

var queryable = GetQueryable<TestObject>( TableName, expected );

var result = queryable
.Where( x => x.Locations.Any() )
.ToList();

Assert.Equal( 1, result.Count );
}

[Fact]
public void WhenIsFilteredByAnyClauseWithFilter_GeneratesCorrectReql()
{
var data = new List<TestObject>
{
new TestObject
{
Name = "TestObject1",
Locations = new List<string> {"Hello" }
},
new TestObject
{
Name = "TestObject2",
Locations = new List<string> {"Hello1" }
}
};

SpawnData( data );

var expected = RethinkDB.R.Table( TableName )
.Filter( x => x["Locations"].Filter( l => l.Eq( "Hello" ) ).Count().Gt( 0 ) );

var queryable = GetQueryable<TestObject>( TableName, expected );

var result = queryable
.Where( x => x.Locations.Any( l => l == "Hello" ) )
.ToList();

Assert.Equal( 1, result.Count );
}

public class TestObject
{
public string Name { get; set; }
public List<string> Locations { get; set; }
public List<Resource> Resources { get; set; }
}
}
}
Loading

0 comments on commit b70c336

Please sign in to comment.