Skip to content

Commit

Permalink
Merge pull request #706 from Curlack/feature/oracle-support
Browse files Browse the repository at this point in the history
Merging changes from private feature branch to collaboratively address known failing integration tests. See #699 (comment) for details.
  • Loading branch information
Ste1io authored Oct 21, 2023
2 parents eaf8e5f + 67f0dc3 commit 7975531
Show file tree
Hide file tree
Showing 13 changed files with 384 additions and 17 deletions.
24 changes: 12 additions & 12 deletions PetaPoco.Tests.Integration/Databases/ExecuteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public virtual void Execute_GivenSqlAndParameterAffectsOneRow_ShouldReturnOne()
InsertNotes(5);

var beforeCount = CountNotes();
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} = @0", 1);
var afterCount = CountNotes();

Expand All @@ -60,7 +60,7 @@ public virtual void Execute_GivenSqlAndParametersAffectsTwoRows_ShouldReturnTwo(
InsertNotes(5);

var beforeCount = CountNotes();
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} IN(@0,@1)", 1, 2);
var afterCount = CountNotes();

Expand All @@ -75,7 +75,7 @@ public virtual void Execute_GivenSqlAffectsOneRow_ShouldReturnOne()
InsertNotes(5);

var beforeCount = CountNotes();
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} = 1");
var afterCount = CountNotes();

Expand All @@ -90,7 +90,7 @@ public virtual void Execute_GivenSqlAffectsTwoRows_ShouldReturnTwo()
InsertNotes(5);

var beforeCount = CountNotes();
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = DB.Execute($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} IN(1,2)");
var afterCount = CountNotes();

Expand All @@ -105,7 +105,7 @@ public virtual async Task ExecuteAsync_GivenSqlAndParameterAffectsOneRow_ShouldR
InsertNotes(5);

var beforeCount = CountNotes();
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} = @0", 1);
var afterCount = CountNotes();

Expand All @@ -120,7 +120,7 @@ public virtual async Task ExecuteAsync_GivenSqlAndParametersAffectsTwoRows_Shoul
InsertNotes(5);

var beforeCount = CountNotes();
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} IN(@0,@1)", 1, 2);
var afterCount = CountNotes();

Expand All @@ -135,7 +135,7 @@ public virtual async Task ExecuteAsync_GivenSqlAffectsOneRow_ShouldReturnOne()
InsertNotes(5);

var beforeCount = CountNotes();
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} = 1");
var afterCount = CountNotes();

Expand All @@ -150,7 +150,7 @@ public virtual async Task ExecuteAsync_GivenSqlAffectsTwoRows_ShouldReturnTwo()
InsertNotes(5);

var beforeCount = CountNotes();
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
var result = await DB.ExecuteAsync($"DELETE FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} IN(1,2)");
var afterCount = CountNotes();

Expand All @@ -172,7 +172,7 @@ public virtual void ExecuteScalar_GivenSqlAndParameter_ReturnShouldBeValid()
{
InsertNotes(4);

DB.ExecuteScalar<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
DB.ExecuteScalar<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} <= @0", 2)
.ShouldBe(2);
}
Expand All @@ -182,7 +182,7 @@ public virtual void ExecuteScalar_GivenSqlAndParameters_ReturnShouldBeValid()
{
InsertNotes(5);

DB.ExecuteScalar<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
DB.ExecuteScalar<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} IN(@0, @1)", 1, 2)
.ShouldBe(2);
}
Expand All @@ -200,7 +200,7 @@ public virtual async Task ExecuteScalarAsync_GivenSqlAndParameter_ReturnShouldBe
{
InsertNotes(4);

(await DB.ExecuteScalarAsync<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
(await DB.ExecuteScalarAsync<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} <= @0", 2))
.ShouldBe(2);
}
Expand All @@ -210,7 +210,7 @@ public virtual async Task ExecuteScalarAsync_GivenSqlAndParameters_ReturnShouldB
{
InsertNotes(5);

(await DB.ExecuteScalarAsync<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)}" +
(await DB.ExecuteScalarAsync<int>($"SELECT COUNT(*) FROM {DB.Provider.EscapeTableName(_pd.TableInfo.TableName)} " +
$"WHERE {DB.Provider.EscapeSqlIdentifier(_pd.TableInfo.PrimaryKey)} IN(@0, @1)", 1, 2))
.ShouldBe(2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using PetaPoco.Tests.Integration.Providers;
using Xunit;

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleDeleteTests : DeleteTests
{
public OracleDeleteTests()
: base(new OracleTestProvider())
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using PetaPoco.Tests.Integration.Providers;
using Xunit;

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleExecuteTests : ExecuteTests
{
public OracleExecuteTests()
: base(new OracleTestProvider())
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using PetaPoco.Tests.Integration.Models.Postgres;
using PetaPoco.Tests.Integration.Providers;
using Shouldly;
using Xunit;

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleInsertTests : InsertTests
{
public OracleInsertTests()
: base(new OracleTestProvider())
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using PetaPoco.Tests.Integration.Providers;
using Xunit;

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleMiscellaneousTests : MiscellaneousTests
{
public OracleMiscellaneousTests()
: base(new OracleTestProvider())
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using PetaPoco.Tests.Integration.Providers;
using Xunit;

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OraclePreExecuteTests : PreExecuteTests
{
protected override IPreExecuteDatabaseProvider Provider => DB.Provider as PreExecuteDatabaseProvider;

public OraclePreExecuteTests()
: base(new PreExecuteTestProvider())
{
Provider.ThrowExceptions = true;
}

protected class PreExecuteTestProvider : OracleTestProvider
{
protected override IDatabase LoadFromConnectionName(string name)
=> BuildFromConnectionName(name).UsingProvider<PreExecuteDatabaseProvider>().Create();
}

protected class PreExecuteDatabaseProvider : PetaPoco.Providers.OracleDatabaseProvider, IPreExecuteDatabaseProvider
{
public bool ThrowExceptions { get; set; }
public List<IDataParameter> Parameters { get; set; } = new List<IDataParameter>();

public override void PreExecute(IDbCommand cmd)
{
Parameters.Clear();

if (ThrowExceptions)
{
Parameters = cmd.Parameters.Cast<IDataParameter>().ToList();
throw new PreExecuteException();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using PetaPoco.Tests.Integration.Providers;
using Xunit;

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleQueryLinqTests : QueryLinqTests
{
public OracleQueryLinqTests()
: base(new OracleTestProvider())
{
}
}
}
Loading

0 comments on commit 7975531

Please sign in to comment.