Skip to content

Commit

Permalink
Merge pull request #1057 from mikependon/repodb-fixes-1049
Browse files Browse the repository at this point in the history
Fixes for #1049
  • Loading branch information
mikependon authored Aug 15, 2022
2 parents b81c277 + c579f48 commit 1587547
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Microsoft.Data.SqlClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RepoDb.Enumerations;
using RepoDb.Exceptions;
using RepoDb.Extensions;
using RepoDb.IntegrationTests.Models;
using RepoDb.IntegrationTests.Setup;
using System;
using System.Linq;

namespace RepoDb.IntegrationTests.Operations
Expand Down Expand Up @@ -772,6 +775,26 @@ public void TestSqlConnectionBatchQueryViaQueryGroup()
}
}

[TestMethod, ExpectedException(typeof(MissingFieldsException))]
public void ThrowExceptionOnSqlConnectionBatchQueryWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.BatchQuery<IdentityTable>(page: 0,
rowsPerBatch: 10,
orderBy: orderBy.AsEnumerable(),
where: (object)null,
commandTimeout: 0,
transaction: null,
trace: null,
statementBuilder: null);
}
}

#endregion

#region BatchQuery<TEntity>(Extra Fields)
Expand Down Expand Up @@ -1773,6 +1796,27 @@ public void TestSqlConnectionBatchQueryAsyncViaQueryGroup()
}
}

[TestMethod, ExpectedException(typeof(AggregateException))]
public void ThrowExceptionOnSqlConnectionBatchQueryAsyncWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.BatchQueryAsync<IdentityTable>(page: 0,
rowsPerBatch: 10,
orderBy: orderBy.AsEnumerable(),
where: (object)null,
commandTimeout: 0,
transaction: null,
trace: null,
statementBuilder: null).Result;
}
}


#endregion

#region BatchQueryAsync<TEntity>(Extra Fields)
Expand Down Expand Up @@ -2390,6 +2434,27 @@ public void TestSqlConnectionBatchQueryViaTableNameViaQueryGroup()
}
}

[TestMethod, ExpectedException(typeof(MissingFieldsException))]
public void ThrowExceptionOnSqlConnectionBatchQueryViaTableNameWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.BatchQuery<IdentityTable>(ClassMappedNameCache.Get<IdentityTable>(),
page: 0,
rowsPerBatch: 10,
orderBy: orderBy.AsEnumerable(),
where: (object)null,
commandTimeout: 0,
transaction: null,
trace: null,
statementBuilder: null);
}
}

#endregion

#region BatchQueryAsync(TableName)
Expand Down Expand Up @@ -2757,6 +2822,27 @@ public void TestSqlConnectionBatchQueryAsyncViaTableNameViaQueryGroup()
}
}

[TestMethod, ExpectedException(typeof(AggregateException))]
public void ThrowExceptionOnSqlConnectionBatchQueryAsyncViaTableNameWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.BatchQueryAsync<IdentityTable>(ClassMappedNameCache.Get<IdentityTable>(),
page: 0,
rowsPerBatch: 10,
orderBy: orderBy.AsEnumerable(),
where: (object)null,
commandTimeout: 0,
transaction: null,
trace: null,
statementBuilder: null).Result;
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Microsoft.Data.SqlClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RepoDb.Enumerations;
using RepoDb.Exceptions;
using RepoDb.Extensions;
using RepoDb.IntegrationTests.Models;
using RepoDb.IntegrationTests.Setup;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
Expand Down Expand Up @@ -285,6 +287,19 @@ public void TestSqlConnectionQueryAllWithOrderByAndWithHints()
}
}

[TestMethod, ExpectedException(typeof(MissingFieldsException))]
public void ThrowExceptionOnSqlConnectionQueryAllWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.QueryAll<IdentityTable>(orderBy: orderBy.AsEnumerable());
}
}

#endregion

#region QueryAll<TEntity>(Extra Fields)
Expand Down Expand Up @@ -573,6 +588,19 @@ public void TestSqlConnectionQueryAllAsyncWithOrderByAndWithHints()
}
}

[TestMethod, ExpectedException(typeof(AggregateException))]
public void ThrowExceptionOnSqlConnectionQueryAllAsyncWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.QueryAllAsync<IdentityTable>(orderBy: orderBy.AsEnumerable()).Result;
}
}

#endregion

#region QueryAllAsync<TEntity>(Extra Fields)
Expand Down Expand Up @@ -815,6 +843,20 @@ public void TestSqlConnectionQueryAllViaTableNameWithOrderByAndWithHints()
}
}

[TestMethod, ExpectedException(typeof(MissingFieldsException))]
public void ThrowExceptionOnSqlConnectionQueryAllViaTableNameWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.QueryAll<IdentityTable>(ClassMappedNameCache.Get<IdentityTable>(),
orderBy: orderBy.AsEnumerable());
}
}

#endregion

#region QueryAllAsync(TableName)
Expand Down Expand Up @@ -1030,6 +1072,20 @@ public void TestSqlConnectionQueryAllAsyncViaTableNameWithOrderByAndWithHints()
}
}

[TestMethod, ExpectedException(typeof(AggregateException))]
public void ThrowExceptionOnSqlConnectionQueryAllAsyncViaTableNameWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.QueryAllAsync<IdentityTable>(ClassMappedNameCache.Get<IdentityTable>(),
orderBy: orderBy.AsEnumerable()).Result;
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,19 @@ public void TestSqlConnectionQueryViaQueryGroupWithOrderByAndTop()
}
}

[TestMethod, ExpectedException(typeof(MissingFieldsException))]
public void ThrowExceptionOnSqlConnectionQueryWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.Query<IdentityTable>(what: null, orderBy: orderBy.AsEnumerable());
}
}

#endregion

#region Query<TEntity>(Extra Fields)
Expand Down Expand Up @@ -1837,6 +1850,19 @@ public void TestSqlConnectionQueryAsyncViaQueryGroupWithOrderByAndTop()
}
}

[TestMethod, ExpectedException(typeof(AggregateException))]
public void ThrowExceptionOnSqlConnectionQueryAsyncWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.QueryAsync<IdentityTable>(what: null, orderBy: orderBy.AsEnumerable()).Result;
}
}

#endregion

#region QueryAsync<TEntity>(Extra Fields)
Expand Down Expand Up @@ -2923,6 +2949,21 @@ public void ThrowExceptionOnSqlConnectionQueryViaTableNameIfThereIsNoKeyField()
}
}

[TestMethod, ExpectedException(typeof(MissingFieldsException))]
public void ThrowExceptionOnSqlConnectionQueryViaTableNameWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.Query<IdentityTable>(ClassMappedNameCache.Get<IdentityTable>(),
what: null,
orderBy: orderBy.AsEnumerable());
}
}

#endregion

#region QueryAsync(TableName)
Expand Down Expand Up @@ -3470,6 +3511,21 @@ public void ThrowExceptionOnSqlConnectionQueryAsyncViaTableNameIfThereIsNoKeyFie
}
}

[TestMethod, ExpectedException(typeof(AggregateException))]
public void ThrowExceptionOnSqlConnectionQueryAsyncViaTableNameWithInvalidOrderFields()
{
// Setup
var orderBy = new OrderField("InvalidColumn", Order.Descending);

using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Act
var result = connection.QueryAsync<IdentityTable>(ClassMappedNameCache.Get<IdentityTable>(),
what: null,
orderBy: orderBy.AsEnumerable()).Result;
}
}

#endregion
}
}
Loading

0 comments on commit 1587547

Please sign in to comment.