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 support for case insensitive dynamic pocos #709

Closed
wants to merge 10 commits into from
Closed
13 changes: 9 additions & 4 deletions PetaPoco.Tests.Integration/Databases/DatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ protected virtual void AfterDbCreate(Database db)
public virtual void Construct_GivenConnection_ShouldBeValid()
{
var factory = DB.Provider.GetFactory();
var ignoreCase = DB.Provider.UseOrdinaryIdentifiers;

using (var connection = factory.CreateConnection())
{
connection.ConnectionString = DB.ConnectionString;
connection.Open();

using (var db = new Database(connection))
using (var db = new Database(connection, ignoreCase: ignoreCase))
{
AfterDbCreate(db);
var key = db.Insert(_note);
Expand All @@ -57,8 +59,9 @@ public virtual void Construct_GivenConnectionStringAndProviderName_ShouldBeValid
{
var providerName = ProviderName;
var connectionString = DB.ConnectionString;
var ignoreCase = DB.Provider.UseOrdinaryIdentifiers;

using (var db = new Database(connectionString, providerName))
using (var db = new Database(connectionString, providerName, ignoreCase: ignoreCase))
{
AfterDbCreate(db);
var key = db.Insert(_note);
Expand All @@ -73,8 +76,9 @@ public virtual void Construct_GivenConnectionStringAndProviderFactory_ShouldBeVa
{
var factory = DB.Provider.GetFactory();
var connectionString = DB.ConnectionString;
var ignoreCase = DB.Provider.UseOrdinaryIdentifiers;

using (var db = new Database(connectionString, factory))
using (var db = new Database(connectionString, factory, ignoreCase: ignoreCase))
{
AfterDbCreate(db);
var key = db.Insert(_note);
Expand All @@ -90,8 +94,9 @@ public virtual void Construct_GivenConnectionStringName_ShouldBeValid()
{
var connectionString = DB.ConnectionString;
var entry = ConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>().FirstOrDefault(c => c.ConnectionString.Equals(connectionString));
var ignoreCase = DB.Provider.UseOrdinaryIdentifiers;

using (var db = new Database(entry.Name))
using (var db = new Database(entry.Name, ignoreCase: ignoreCase))
{
AfterDbCreate(db);
var key = db.Insert(_note);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleDatabaseTests : DatabaseTests
public abstract partial class OracleDatabaseTests : DatabaseTests
{
public OracleDatabaseTests()
: base(new OracleTestProvider())
protected OracleDatabaseTests(TestProvider provider)
: base(provider)
{
}

[Collection("Oracle.Delimited")]
public class Delimited : OracleDatabaseTests
{
public Delimited()
: base(new OracleDelimitedTestProvider())
{
}
}

[Collection("Oracle.Ordinary")]
public class Ordinary : OracleDatabaseTests
{
public Ordinary()
: base(new OracleOrdinaryTestProvider())
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleDeleteTests : DeleteTests
public abstract partial class OracleDeleteTests : DeleteTests
{
public OracleDeleteTests()
: base(new OracleTestProvider())
protected OracleDeleteTests(TestProvider provider)
: base(provider)
{
}

[Collection("Oracle.Delimited")]
public class Delimited : OracleDeleteTests
{
public Delimited()
: base(new OracleDelimitedTestProvider())
{
}
}

[Collection("Oracle.Ordinary")]
public class Ordinary : OracleDeleteTests
{
public Ordinary()
: base(new OracleOrdinaryTestProvider())
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleExecuteTests : ExecuteTests
public abstract partial class OracleExecuteTests : ExecuteTests
{
public OracleExecuteTests()
: base(new OracleTestProvider())
protected OracleExecuteTests(TestProvider provider)
: base(provider)
{
}

[Collection("Oracle.Delimited")]
public class Delimited : OracleExecuteTests
{
public Delimited()
: base(new OracleDelimitedTestProvider())
{
}
}

[Collection("Oracle.Ordinary")]
public class Ordinary : OracleExecuteTests
{
public Ordinary()
: base(new OracleOrdinaryTestProvider())
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,29 @@

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleInsertTests : InsertTests
public abstract partial class OracleInsertTests : InsertTests
{
public OracleInsertTests()
: base(new OracleTestProvider())
protected OracleInsertTests(TestProvider provider)
: base(provider)
{
}

[Collection("Oracle.Delimited")]
public class Delimited : OracleInsertTests
{
public Delimited()
: base(new OracleDelimitedTestProvider())
{
}
}

[Collection("Oracle.Ordinary")]
public class Ordinary : OracleInsertTests
{
public Ordinary()
: base(new OracleOrdinaryTestProvider())
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleMiscellaneousTests : MiscellaneousTests
public abstract partial class OracleMiscellaneousTests : MiscellaneousTests
{
public OracleMiscellaneousTests()
: base(new OracleTestProvider())
protected OracleMiscellaneousTests(TestProvider provider)
: base(provider)
{
}

[Collection("Oracle.Delimited")]
public class Delimited : OracleMiscellaneousTests
{
public Delimited()
: base(new OracleDelimitedTestProvider())
{
}
}

[Collection("Oracle.Ordinary")]
public class Ordinary : OracleMiscellaneousTests
{
public Ordinary()
: base(new OracleOrdinaryTestProvider())
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,79 @@

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

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

protected class PreExecuteTestProvider : OracleTestProvider
[Collection("Oracle.Delimited")]
public class Delimited : OraclePreExecuteTests
{
protected override IDatabase LoadFromConnectionName(string name)
=> BuildFromConnectionName(name).UsingProvider<PreExecuteDatabaseProvider>().Create();
protected override IPreExecuteDatabaseProvider Provider => DB.Provider as PreExecuteDatabaseProvider;

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

protected class PreExecuteTestProvider : OracleDelimitedTestProvider
{
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();
}
}
}
}

protected class PreExecuteDatabaseProvider : PetaPoco.Providers.OracleDatabaseProvider, IPreExecuteDatabaseProvider
[Collection("Oracle.Ordinary")]
public class Ordinary : OraclePreExecuteTests
{
public bool ThrowExceptions { get; set; }
public List<IDataParameter> Parameters { get; set; } = new List<IDataParameter>();
protected override IPreExecuteDatabaseProvider Provider => DB.Provider as PreExecuteDatabaseProvider;

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

public override void PreExecute(IDbCommand cmd)
protected class PreExecuteTestProvider : OracleOrdinaryTestProvider
{
Parameters.Clear();
protected override IDatabase LoadFromConnectionName(string name)
=> BuildFromConnectionName(name).UsingProvider<PreExecuteDatabaseProvider>().Create();
}

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

public override void PreExecute(IDbCommand cmd)
{
Parameters = cmd.Parameters.Cast<IDataParameter>().ToList();
throw new PreExecuteException();
Parameters.Clear();

if (ThrowExceptions)
{
Parameters = cmd.Parameters.Cast<IDataParameter>().ToList();
throw new PreExecuteException();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleQueryLinqTests : QueryLinqTests
public abstract partial class OracleQueryLinqTests : QueryLinqTests
{
public OracleQueryLinqTests()
: base(new OracleTestProvider())
protected OracleQueryLinqTests(TestProvider provider)
: base(provider)
{
}

[Collection("Oracle.Delimited")]
public class Delimited : OracleQueryLinqTests
{
public Delimited()
: base(new OracleDelimitedTestProvider())
{
}
}

[Collection("Oracle.Ordinary")]
public class Ordinary : OracleQueryLinqTests
{
public Ordinary()
: base(new OracleOrdinaryTestProvider())
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,31 @@

namespace PetaPoco.Tests.Integration.Databases.Oracle
{
[Collection("Oracle")]
public class OracleQueryTests : QueryTests
public abstract partial class OracleQueryTests : QueryTests
{
public OracleQueryTests()
: base(new OracleTestProvider())
protected OracleQueryTests(TestProvider provider)
: base(provider)
{
}

[Collection("Oracle.Delimited")]
public class Delimited : OracleQueryTests
{
public Delimited()
: base(new OracleDelimitedTestProvider())
{
}
}

[Collection("Oracle.Ordinary")]
public class Ordinary : OracleQueryTests
{
public Ordinary()
: base(new OracleOrdinaryTestProvider())
{
}
}

[Fact]
public override async Task FetchAsyncWithPaging_ForDynamicTypeGivenSql_ShouldReturnValidDynamicTypeCollection()
{
Expand Down
Loading