diff --git a/Promethix.Framework.Ado.Tests/IntegrationTests/AdoScopeMssqlTests.cs b/Promethix.Framework.Ado.Tests/IntegrationTests/AdoScopeMssqlTests.cs index 0d5c32b..2b94b53 100644 --- a/Promethix.Framework.Ado.Tests/IntegrationTests/AdoScopeMssqlTests.cs +++ b/Promethix.Framework.Ado.Tests/IntegrationTests/AdoScopeMssqlTests.cs @@ -39,6 +39,14 @@ public void TestInitialize() simpleTestRepository.DeleteAll(); } + [TestCategory("IntegrationTests"), TestMethod] + public void MssqlAdoScopeBasicReadRecordsTest() + { + using IAdoScope adoScope = adoScopeFactory.Create(); + Assert.IsFalse(simpleTestRepository.GetEntities().Any()); + adoScope.Complete(); + } + [TestCategory("IntegrationTests"), TestMethod] public void MssqlAdoScopeBasicTest() { diff --git a/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/ISimpleMssqlTestRepository.cs b/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/ISimpleMssqlTestRepository.cs index 3255e11..04aead6 100644 --- a/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/ISimpleMssqlTestRepository.cs +++ b/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/ISimpleMssqlTestRepository.cs @@ -13,6 +13,8 @@ public interface ISimpleMssqlTestRepository TestEntity GetEntityByName(string name); + IEnumerable GetEntities(); + void AddWithDifferentContext(TestEntity entity); int GetEntityCount(); diff --git a/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/MssqlContextExample3.cs b/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/MssqlContextExample3.cs new file mode 100644 index 0000000..51e5599 --- /dev/null +++ b/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/MssqlContextExample3.cs @@ -0,0 +1,23 @@ +using Promethix.Framework.Ado.Enums; +using Promethix.Framework.Ado.Implementation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Promethix.Framework.Ado.Tests.TestSupport.DataAccess.Mssql +{ + public class MssqlContextExample3 : AdoContext + { + public MssqlContextExample3() + : base( + "MssqlContextExample3", + "Microsoft.Data.SqlClient", + "Server=(local);Database=AdoScopeTest1;Integrated Security=True;TrustServerCertificate=True", + AdoContextExecutionOption.Transactional) + { + // No Implementation + } + } +} diff --git a/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/SimpleMssqlTestRepository.cs b/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/SimpleMssqlTestRepository.cs index 10b828f..f94cb1c 100644 --- a/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/SimpleMssqlTestRepository.cs +++ b/Promethix.Framework.Ado.Tests/TestSupport/DataAccess/Mssql/SimpleMssqlTestRepository.cs @@ -24,6 +24,10 @@ public SimpleMssqlTestRepository(IAmbientAdoContextLocator ambientAdoContextLoca private IDbConnection SqlConnection2 => ambientAdoContextLocator.GetContext().Connection; + private IDbConnection SqlConnection3 => ambientAdoContextLocator.GetContext().Connection; + + private IDbTransaction SqlTransaction3 => ambientAdoContextLocator.GetContext().Transaction; + public void Add(TestEntity entity) { const string query = "INSERT INTO TestEntity (Name, Description, Quantity) VALUES (@Name, @Description, @Quantity)"; @@ -42,6 +46,12 @@ public TestEntity GetEntityByName(string name) return SqlConnection1.QuerySingleOrDefault(query, new { Name = name }); } + public IEnumerable GetEntities() + { + const string query = "SELECT * FROM TestEntity"; + return SqlConnection3.Query(query, transaction: SqlTransaction3); + } + public int GetEntityCount() { const string query = "SELECT COUNT(*) FROM TestEntity"; diff --git a/Promethix.Framework.Ado/Implementation/AdoContext.cs b/Promethix.Framework.Ado/Implementation/AdoContext.cs index f78a8b9..e9873d3 100644 --- a/Promethix.Framework.Ado/Implementation/AdoContext.cs +++ b/Promethix.Framework.Ado/Implementation/AdoContext.cs @@ -38,6 +38,23 @@ public IDbConnection Connection } } + /// + /// Gets the transaction for reference. + /// WARNING: This should not be used to commit or rollback the transaction! + /// + public IDbTransaction Transaction + { + get + { + if (transaction == null) + { + throw new InvalidOperationException("There is no active transaction."); + } + + return transaction; + } + } + protected AdoContext() { // No Implementation diff --git a/README.md b/README.md index 39c5ce3..e14c854 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build and Test 0.1.x-alpha](https://github.com/gentoorax/Promethix.Framework.Ado/actions/workflows/adoscope-nuget-build.yaml/badge.svg)](https://github.com/gentoorax/Promethix.Framework.Ado/actions/workflows/adoscope-nuget-build.yaml) [![Published to nuget.org 0.1.x-x-alpha](https://github.com/gentoorax/Promethix.Framework.Ado/actions/workflows/adoscope-nuget-publish-prerelease.yaml/badge.svg)](https://github.com/gentoorax/Promethix.Framework.Ado/actions/workflows/adoscope-nuget-publish-prerelease.yaml) -**Recently promoted to v1.0.0-rc2. All major features have been implemented.** +**Recently promoted to v1.0.0-rc3. All major features have been implemented.** **Now incldues .NET 8.0 support**