Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining Oracle tests #706

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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