Permalink
Browse files

Added BadExpressionException in Join.On, fixes #233

  • Loading branch information...
markrendle committed Nov 6, 2012
1 parent 54581ae commit 3299f809cee11e5fa3db95ecd95ecf3f675319c9
Showing with 28 additions and 1 deletion.
  1. +14 −0 Simple.Data.BehaviourTest/Query/ExplicitJoinTest.cs
  2. +14 −1 Simple.Data/SimpleQuery.cs
@@ -276,6 +276,20 @@ public void TwoJoins()
"WHERE (([dbo].[Activity].[ID_Trip] = @p1 AND [dbo].[Activity].[Activity_Time] = @p2) AND [dbo].[Activity].[Is_Public] = @p3)");
}
+ [Test]
+ public void PassingTrueToOnThrowsBadExpressionException()
+ {
+ Assert.Throws<BadExpressionException>(
+ () => _db.Activity.All().Join(_db.Location).On(true));
+ }
+
+ [Test]
+ public void PassingObjectReferenceToOnThrowsBadExpressionException()
+ {
+ Assert.Throws<BadExpressionException>(
+ () => _db.Activity.All().Join(_db.Location).On(_db.Location.ID_Location));
+ }
+
class Activity
{
public int ID_Activity { get; set; }
View
@@ -514,7 +514,13 @@ public SimpleQuery OuterJoin(ObjectReference objectReference, out dynamic queryO
public SimpleQuery On(SimpleExpression joinExpression)
{
if (_tempJoinWaitingForOn == null)
+ {
throw new InvalidOperationException("Call to On must be preceded by call to JoinInfo.");
+ }
+ if (ReferenceEquals(joinExpression, null))
+ {
+ throw new BadExpressionException("On expects an expression or named parameters.");
+ }
return AddNewJoin(new JoinClause(_tempJoinWaitingForOn.Table, _tempJoinWaitingForOn.JoinType, joinExpression));
}
@@ -561,9 +567,16 @@ private SimpleQuery ParseJoin(InvokeMemberBinder binder, object[] args)
private SimpleQuery ParseOn(InvokeMemberBinder binder, IEnumerable<object> args)
{
if (_tempJoinWaitingForOn == null)
+ {
throw new InvalidOperationException("Call to On must be preceded by call to JoinInfo.");
+ }
+ var namedArguments = binder.NamedArgumentsToDictionary(args);
+ if (namedArguments == null || namedArguments.Count == 0)
+ {
+ throw new BadExpressionException("On expects an expression or named parameters.");
+ }
var joinExpression = ExpressionHelper.CriteriaDictionaryToExpression(_tempJoinWaitingForOn.Table,
- binder.NamedArgumentsToDictionary(args));
+ namedArguments);
return AddNewJoin(new JoinClause(_tempJoinWaitingForOn.Table, _tempJoinWaitingForOn.JoinType, joinExpression));
}

0 comments on commit 3299f80

Please sign in to comment.