Skip to content

Commit

Permalink
Merge pull request #696 from Ste1io/containerized-tests-fixes
Browse files Browse the repository at this point in the history
Containerized tests fixes
  • Loading branch information
pleb authored Sep 28, 2023
2 parents 35b5286 + 775f68c commit 6f46e44
Show file tree
Hide file tree
Showing 108 changed files with 3,643 additions and 1,307 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "PetaPoco.sln"
}
4 changes: 2 additions & 2 deletions PetaPoco.Tests.Integration/AppSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static AppSetting()
.AddJsonFile("appsettings.json");

var config = builder.Build();

var app = new AppSetting();
config.GetSection("App").Bind(app);
_instance = app;
Expand All @@ -41,4 +41,4 @@ public class ConnectionStringSetting
}
}
}
#endif
#endif
7 changes: 7 additions & 0 deletions PetaPoco.Tests.Integration/CollectionDefinitions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Xunit;

namespace PetaPoco.Tests.Integration
{
[CollectionDefinition("Documentation", DisableParallelization = true)]
public class DocumentationCollectionDefinition { }
}
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion PetaPoco.Tests.Integration/Databases/BaseDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace PetaPoco.Tests.Integration.Databases
public abstract class BaseDatabase : IDisposable
{
private DBTestProvider _provider;

protected IDatabase DB { get; set; }
protected string ProviderName { get; private set; }

Expand All @@ -26,4 +27,4 @@ public void Dispose()
}
}
}
}
}
80 changes: 53 additions & 27 deletions PetaPoco.Tests.Integration/Databases/BaseDatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ namespace PetaPoco.Tests.Integration.Databases
{
public abstract class BaseDatabaseTests : BaseDatabase
{
// TODO: Move to base class, combine with other test data
#region Test Data

private readonly Note _note = new Note
{
Text = "A test note",
CreatedOn = new DateTime(1955, 1, 11, 4, 2, 4, DateTimeKind.Utc)
};

#endregion

protected BaseDatabaseTests(DBTestProvider provider)
: base(provider)
{
Expand All @@ -28,7 +33,7 @@ protected virtual void AfterDbCreate(Database db)
}

[Fact]
public void Construct_GivenConnection_ShouldBeValid()
public virtual void Construct_GivenConnection_ShouldBeValid()
{
var factory = DB.Provider.GetFactory();
using (var connection = factory.CreateConnection())
Expand All @@ -48,7 +53,7 @@ public void Construct_GivenConnection_ShouldBeValid()
}

[Fact]
public void Construct_GivenConnectionStringAndProviderName_ShouldBeValid()
public virtual void Construct_GivenConnectionStringAndProviderName_ShouldBeValid()
{
var providerName = ProviderName;
var connectionString = DB.ConnectionString;
Expand All @@ -64,7 +69,7 @@ public void Construct_GivenConnectionStringAndProviderName_ShouldBeValid()
}

[Fact]
public void Construct_GivenConnectionStringAndProviderFactory_ShouldBeValid()
public virtual void Construct_GivenConnectionStringAndProviderFactory_ShouldBeValid()
{
var factory = DB.Provider.GetFactory();
var connectionString = DB.ConnectionString;
Expand All @@ -81,7 +86,7 @@ public void Construct_GivenConnectionStringAndProviderFactory_ShouldBeValid()

#if !NETCOREAPP
[Fact]
public void Construct_GivenConnectionStringName_ShouldBeValid()
public virtual void Construct_GivenConnectionStringName_ShouldBeValid()
{
var connectionString = DB.ConnectionString;
var entry = ConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>().FirstOrDefault(c => c.ConnectionString.Equals(connectionString));
Expand All @@ -97,7 +102,7 @@ public void Construct_GivenConnectionStringName_ShouldBeValid()
#endif

[Fact]
public void Construct_GivenConnectionStringAndProvider_ShouldBeValid()
public virtual void Construct_GivenConnectionStringAndProvider_ShouldBeValid()
{
var connectionString = DB.ConnectionString;
var provider = DB.Provider;
Expand All @@ -113,7 +118,9 @@ public void Construct_GivenConnectionStringAndProvider_ShouldBeValid()
}

[Fact]
public void IsolationLevel_WhenChangedDuringTransaction_ShouldThrow()
[Trait("DBFeature", "Transaction")]
[Trait("DBFeature", "IsolationLevel")]
public virtual void IsolationLevel_WhenChangedDuringTransaction_ShouldThrow()
{
using (DB.GetTransaction())
{
Expand All @@ -122,6 +129,8 @@ public void IsolationLevel_WhenChangedDuringTransaction_ShouldThrow()
}

[Fact]
[Trait("DBFeature", "Transaction")]
[Trait("DBFeature", "IsolationLevel")]
public virtual void BeginTransaction_WhenIsolationLevelIsSet_ShouldBeOfIsolationLevel()
{
DB.IsolationLevel = IsolationLevel.Serializable;
Expand All @@ -133,7 +142,7 @@ public virtual void BeginTransaction_WhenIsolationLevelIsSet_ShouldBeOfIsolation
}

[Fact]
public void OpenSharedConnection_WhenCalled_ShouldBeValid()
public virtual void OpenSharedConnection_WhenCalled_ShouldBeValid()
{
DB.Connection.ShouldBeNull();
DB.OpenSharedConnection();
Expand All @@ -142,18 +151,17 @@ public void OpenSharedConnection_WhenCalled_ShouldBeValid()
}

[Fact]
public async void OpenSharedConnectionAsync_WhenCalled_ShouldBeValid()
public virtual async Task OpenSharedConnectionAsync_WhenCalled_ShouldBeValid()
{
DB.Connection.ShouldBeNull();
await DB.OpenSharedConnectionAsync();
DB.Connection.State.ShouldBe(ConnectionState.Open);
DB.CloseSharedConnection();
}

#region Events

[Fact]
public void OpenSharedConnection_WhenCalled_ShouldInvokeOnConnectionOpening()
[Trait("LibFeature", "Event")]
public virtual void OpenSharedConnection_WhenCalled_ShouldInvokeOnConnectionOpening()
{
bool eventInvoked = false;
// NOTE: Casting DB to Database, since `ConnectionOpening` is missing in IDatabase
Expand All @@ -167,7 +175,8 @@ public void OpenSharedConnection_WhenCalled_ShouldInvokeOnConnectionOpening()
}

[Fact]
public async Task OpenSharedConnectionAsync_WhenCalled_ShouldInvokeOnConnectionOpening()
[Trait("LibFeature", "Event")]
public virtual async Task OpenSharedConnectionAsync_WhenCalled_ShouldInvokeOnConnectionOpening()
{
bool eventInvoked = false;
// NOTE: Casting DB to Database, since `ConnectionOpening` is missing in IDatabase
Expand All @@ -181,7 +190,8 @@ public async Task OpenSharedConnectionAsync_WhenCalled_ShouldInvokeOnConnectionO
}

[Fact]
public void OpenSharedConnection_AfterBeingCalled_ShouldInvokeOnConnectionOpened()
[Trait("LibFeature", "Event")]
public virtual void OpenSharedConnection_AfterBeingCalled_ShouldInvokeOnConnectionOpened()
{
bool eventInvoked = false;
DB.ConnectionOpened += (_, e) => { eventInvoked = true; e.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -194,7 +204,8 @@ public void OpenSharedConnection_AfterBeingCalled_ShouldInvokeOnConnectionOpened
}

[Fact]
public async Task OpenSharedConnectionAsync_AfterBeingCalled_ShouldInvokeOnConnectionOpened()
[Trait("LibFeature", "Event")]
public virtual async Task OpenSharedConnectionAsync_AfterBeingCalled_ShouldInvokeOnConnectionOpened()
{
bool eventInvoked = false;
DB.ConnectionOpened += (_, e) => { eventInvoked = true; e.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -207,7 +218,8 @@ public async Task OpenSharedConnectionAsync_AfterBeingCalled_ShouldInvokeOnConne
}

[Fact]
public void CloseSharedConnection_WhenCalled_ShouldInvokeOnConnectionClosing()
[Trait("LibFeature", "Event")]
public virtual void CloseSharedConnection_WhenCalled_ShouldInvokeOnConnectionClosing()
{
bool eventInvoked = false;
DB.ConnectionClosing += (_, e) => { eventInvoked = true; e.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -220,7 +232,8 @@ public void CloseSharedConnection_WhenCalled_ShouldInvokeOnConnectionClosing()
}

[Fact]
public void CommandHelper_WhenCalled_ShouldInvokeOnExecutingCommand()
[Trait("LibFeature", "Event")]
public virtual void CommandHelper_WhenCalled_ShouldInvokeOnExecutingCommand()
{
bool eventInvoked = false;
DB.CommandExecuting += (_, e) => { eventInvoked = true; DB.LastSQL.ShouldNotBe(e.Command.CommandText); };
Expand All @@ -233,7 +246,8 @@ public void CommandHelper_WhenCalled_ShouldInvokeOnExecutingCommand()
}

[Fact]
public async Task CommandHelperAsync_WhenCalled_ShouldInvokeOnExecutingCommand()
[Trait("LibFeature", "Event")]
public virtual async Task CommandHelperAsync_WhenCalled_ShouldInvokeOnExecutingCommand()
{
bool eventInvoked = false;
DB.CommandExecuting += (_, e) => { eventInvoked = true; DB.LastSQL.ShouldNotBe(e.Command.CommandText); };
Expand All @@ -246,7 +260,8 @@ public async Task CommandHelperAsync_WhenCalled_ShouldInvokeOnExecutingCommand()
}

[Fact]
public void CommandHelper_AfterBeingCalled_ShouldInvokeOnExecutedCommand()
[Trait("LibFeature", "Event")]
public virtual void CommandHelper_AfterBeingCalled_ShouldInvokeOnExecutedCommand()
{
bool eventInvoked = false;
DB.CommandExecuted += (_, e) => { eventInvoked = true; DB.LastSQL.ShouldBe(e.Command.CommandText); };
Expand All @@ -259,7 +274,8 @@ public void CommandHelper_AfterBeingCalled_ShouldInvokeOnExecutedCommand()
}

[Fact]
public async Task CommandHelperAsync_AfterBeingCalled_ShouldInvokeOnExecutedCommand()
[Trait("LibFeature", "Event")]
public virtual async Task CommandHelperAsync_AfterBeingCalled_ShouldInvokeOnExecutedCommand()
{
bool eventInvoked = false;
DB.CommandExecuted += (_, e) => { eventInvoked = true; DB.LastSQL.ShouldBe(e.Command.CommandText); };
Expand All @@ -272,7 +288,9 @@ public async Task CommandHelperAsync_AfterBeingCalled_ShouldInvokeOnExecutedComm
}

[Fact]
public void BeginTransaction_AfterBeingCalled_ShouldInvokeOnBeginTransaction()
[Trait("LibFeature", "Event")]
[Trait("DBFeature", "Transaction")]
public virtual void BeginTransaction_AfterBeingCalled_ShouldInvokeOnBeginTransaction()
{
bool eventInvoked = false;
DB.TransactionStarted += (_, e) => { eventInvoked = true; e.Transaction.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -283,7 +301,9 @@ public void BeginTransaction_AfterBeingCalled_ShouldInvokeOnBeginTransaction()
}

[Fact]
public async Task BeginTransactionAsync_AfterBeingCalled_ShouldInvokeOnBeginTransaction()
[Trait("LibFeature", "Event")]
[Trait("DBFeature", "Transaction")]
public virtual async Task BeginTransactionAsync_AfterBeingCalled_ShouldInvokeOnBeginTransaction()
{
bool eventInvoked = false;
DB.TransactionStarted += (_, e) => { eventInvoked = true; e.Transaction.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -294,7 +314,9 @@ public async Task BeginTransactionAsync_AfterBeingCalled_ShouldInvokeOnBeginTran
}

[Fact]
public void CompleteTransaction_WhenCalled_ShouldInvokeOnEndTransaction()
[Trait("LibFeature", "Event")]
[Trait("DBFeature", "Transaction")]
public virtual void CompleteTransaction_WhenCalled_ShouldInvokeOnEndTransaction()
{
bool eventInvoked = false;
DB.TransactionEnding += (_, e) => { eventInvoked = true; e.Transaction.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -305,7 +327,9 @@ public void CompleteTransaction_WhenCalled_ShouldInvokeOnEndTransaction()
}

[Fact]
public async Task CompleteTransactionAsync_WhenCalled_ShouldInvokeOnEndTransaction()
[Trait("LibFeature", "Event")]
[Trait("DBFeature", "Transaction")]
public virtual async Task CompleteTransactionAsync_WhenCalled_ShouldInvokeOnEndTransaction()
{
bool eventInvoked = false;
DB.TransactionEnding += (_, e) => { eventInvoked = true; e.Transaction.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -317,7 +341,9 @@ public async Task CompleteTransactionAsync_WhenCalled_ShouldInvokeOnEndTransacti
}

[Fact]
public void AbortTransaction_WhenCalled_ShouldInvokeOnEndTransaction()
[Trait("LibFeature", "Event")]
[Trait("DBFeature", "Transaction")]
public virtual void AbortTransaction_WhenCalled_ShouldInvokeOnEndTransaction()
{
bool eventInvoked = false;
DB.TransactionEnding += (_, e) => { eventInvoked = true; e.Transaction.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -328,7 +354,9 @@ public void AbortTransaction_WhenCalled_ShouldInvokeOnEndTransaction()
}

[Fact]
public async Task AbortTransactionAsync_WhenCalled_ShouldInvokeOnEndTransaction()
[Trait("LibFeature", "Event")]
[Trait("DBFeature", "Transaction")]
public virtual async Task AbortTransactionAsync_WhenCalled_ShouldInvokeOnEndTransaction()
{
bool eventInvoked = false;
DB.TransactionEnding += (_, e) => { eventInvoked = true; e.Transaction.Connection.State.ShouldBe(ConnectionState.Open); };
Expand All @@ -338,7 +366,5 @@ public async Task AbortTransactionAsync_WhenCalled_ShouldInvokeOnEndTransaction(
await (DB as Database).AbortTransactionAsync();
eventInvoked.ShouldBeTrue();
}

#endregion
}
}
Loading

0 comments on commit 6f46e44

Please sign in to comment.