GeezerVison is showing github.com — Fix issues #207 and #201 · ThatRendle/Simple.Data@e0c198e
File treeExpand file treeCollapse file tree Open diff view settings Simple.Data.BehaviourTest
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Simple.Data.BehaviourTest/Query/QueryTest.cs -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -228,7 +228,5 @@ public void SpecifyingJoinTableShouldCreateDirectQuery() | 228 | 228 | GeneratedSqlIs("select [dbo].[userbio].[userid],[dbo].[userbio].[text] from [dbo].[userbio]" + | 229 | 229 | " join [dbo].[users] on ([dbo].[users].[id] = [dbo].[userbio].[userid]) where [dbo].[users].[id] = @p1"); | 230 | 230 | } | 231 | | - | 232 | | - | 233 | 231 | } | 234 | 232 | } |
Collapse file Copy file name to clipboard +52Lines changed: 52 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +namespace Simple.Data.IntegrationTest | | 2 | +{ | | 3 | + using System; | | 4 | + using Mocking.Ado; | | 5 | + using NUnit.Framework; | | 6 | + | | 7 | + [TestFixture] | | 8 | + public class WhereTest : DatabaseIntegrationContext | | 9 | + { | | 10 | + [Test] | | 11 | + public void WhereWithNoParametersShouldThrowBadExpressionException() | | 12 | + { | | 13 | + Assert.Throws<BadExpressionException>(() => _db.Users.All().Where()); | | 14 | + } | | 15 | + | | 16 | + [Test] | | 17 | + public void WhereWithStringParameterShouldThrowBadExpressionException() | | 18 | + { | | 19 | + Assert.Throws<BadExpressionException>(() => _db.Users.All().Where("Answers")); | | 20 | + } | | 21 | + | | 22 | + [Test] | | 23 | + public void WhereWithNullParameterShouldThrowArgumentNullException() | | 24 | + { | | 25 | + Assert.Throws<ArgumentNullException>(() => _db.Users.All().Where(null)); | | 26 | + } | | 27 | + | | 28 | + protected override void SetSchema(MockSchemaProvider schemaProvider) | | 29 | + { | | 30 | + schemaProvider.SetTables(new[] { "dbo", "Users", "BASE TABLE" }, | | 31 | + new[] { "dbo", "UserBio", "BASE TABLE" }, | | 32 | + new[] { "dbo", "UserPayment", "BASE TABLE" }, | | 33 | + new[] { "dbo", "Employee", "BASE TABLE" }); | | 34 | + | | 35 | + schemaProvider.SetColumns(new object[] { "dbo", "Users", "Id", true }, | | 36 | + new[] { "dbo", "Users", "Name" }, | | 37 | + new[] { "dbo", "Users", "Password" }, | | 38 | + new[] { "dbo", "Users", "Age" }, | | 39 | + new[] { "dbo", "UserBio", "UserId" }, | | 40 | + new[] { "dbo", "UserBio", "Text" }, | | 41 | + new[] { "dbo", "UserPayment", "UserId" }, | | 42 | + new[] { "dbo", "UserPayment", "Amount" }, | | 43 | + new[] { "dbo", "Employee", "Id" }, | | 44 | + new[] { "dbo", "Employee", "Name" }, | | 45 | + new[] { "dbo", "Employee", "ManagerId" }); | | 46 | + | | 47 | + schemaProvider.SetPrimaryKeys(new object[] { "dbo", "Users", "Id", 0 }); | | 48 | + schemaProvider.SetForeignKeys(new object[] { "FK_Users_UserBio", "dbo", "UserBio", "UserId", "dbo", "Users", "Id", 0 }, | | 49 | + new object[] { "FK_Users_UserPayment", "dbo", "UserPayment", "UserId", "dbo", "Users", "Id", 0 }); | | 50 | + } | | 51 | + } | | 52 | +} |
Collapse file Copy file name to clipboardExpand all lines: Simple.Data.BehaviourTest/Simple.Data.BehaviourTest.csproj +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 78 | 78 | <Compile Include="Query\FunctionTest.cs" /> | 79 | 79 | <Compile Include="Query\HavingTest.cs" /> | 80 | 80 | <Compile Include="Query\QueryTest.cs" /> | | 81 | + <Compile Include="Query\WhereTest.cs" /> | 81 | 82 | <Compile Include="Query\WithCountTest.cs" /> | 82 | 83 | <Compile Include="Query\WithTest.cs" /> | 83 | 84 | <Compile Include="RangeAndArrayFindTest.cs" /> | |
Collapse file Copy file name to clipboardExpand all lines: Simple.Data/SimpleQuery.cs +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,6 +183,7 @@ public SimpleQuery ReplaceWhere(SimpleExpression criteria) | 183 | 183 |
| 184 | 184 | public SimpleQuery Where(SimpleExpression criteria) | 185 | 185 | { | | 186 | + if (criteria == null) throw new ArgumentNullException("criteria"); | 186 | 187 | return new SimpleQuery(this, _clauses.Append(new WhereClause(criteria))); | 187 | 188 | } | 188 | 189 |
| @@ -333,7 +334,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o | 333 | 334 | } | 334 | 335 | try | 335 | 336 | { | 336 | | - var methodInfo = typeof(SimpleQuery).GetMethod(binder.Name); | | 337 | + var methodInfo = typeof(SimpleQuery).GetMethod(binder.Name, args.Select(a => (a ?? new object()).GetType()).ToArray()); | 337 | 338 | if (methodInfo != null) | 338 | 339 | { | 339 | 340 | methodInfo.Invoke(this, args); | @@ -343,6 +344,11 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o | 343 | 344 | { | 344 | 345 | } | 345 | 346 |
| | 347 | + if (binder.Name.Equals("where", StringComparison.InvariantCultureIgnoreCase) || binder.Name.Equals("replacewhere", StringComparison.InvariantCultureIgnoreCase)) | | 348 | + { | | 349 | + throw new BadExpressionException("Where methods require a single criteria expression."); | | 350 | + } | | 351 | + | 346 | 352 | return false; | 347 | 353 | } | 348 | 354 |
| |
|