Skip to content

Commit 20f3fe7

Browse files
committed
Added BadExpressionException
1 parent bf472b9 commit 20f3fe7

5 files changed

Lines changed: 52 additions & 2 deletions

File tree

Simple.Data.BehaviourTest/FindTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ public void TestFindAllWithLike()
208208
Parameter(0).Is("Foo");
209209
}
210210

211+
[Test]
212+
public void FindAllWithNoParametersThrowsBadExpressionException()
213+
{
214+
Assert.Throws<BadExpressionException>(() => _db.Users.FindAll().ToList());
215+
}
216+
217+
[Test]
218+
public void FindAllWithStringParameterThrowsBadExpressionException()
219+
{
220+
Assert.Throws<BadExpressionException>(() => _db.Users.FindAll("Answer").ToList());
221+
}
222+
211223
[Test]
212224
public void TestFindAllWithNotLike()
213225
{
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.Serialization;
5+
using System.Text;
6+
7+
namespace Simple.Data
8+
{
9+
[Serializable]
10+
public class BadExpressionException : Exception
11+
{
12+
//
13+
// For guidelines regarding the creation of new exception types, see
14+
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
15+
// and
16+
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
17+
//
18+
19+
public BadExpressionException()
20+
{
21+
}
22+
23+
public BadExpressionException(string message) : base(message)
24+
{
25+
}
26+
27+
public BadExpressionException(string message, Exception inner) : base(message, inner)
28+
{
29+
}
30+
31+
protected BadExpressionException(
32+
SerializationInfo info,
33+
StreamingContext context) : base(info, context)
34+
{
35+
}
36+
}
37+
}

Simple.Data/Commands/FindAllCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMembe
3535
return new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where((SimpleExpression)args[0]);
3636
}
3737

38-
return null;
38+
throw new BadExpressionException("FindAll only accepts a criteria expression.");
3939
}
4040
}
4141
}

Simple.Data/Commands/FindCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMembe
3636
return data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null;
3737
}
3838

39-
return null;
39+
throw new BadExpressionException("Find only accepts a criteria expression.");
4040
}
4141

4242
public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args)

Simple.Data/Simple.Data.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="FunctionSignature.cs" />
9393
<Compile Include="InMemoryAdapter.cs" />
9494
<Compile Include="InMemoryAdapterIAdapterWithTransactions.cs" />
95+
<Compile Include="BadExpressionException.cs" />
9596
<Compile Include="JoinType.cs" />
9697
<Compile Include="OfTypeEnumerable.cs" />
9798
<Compile Include="OptimizingDelegateFactory.cs" />

0 commit comments

Comments
 (0)