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

Bug/7 non scalar query in dapper requires access to dbtransaction #8

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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface ISimpleMssqlTestRepository

TestEntity GetEntityByName(string name);

IEnumerable<TestEntity> GetEntities();

void AddWithDifferentContext(TestEntity entity);

int GetEntityCount();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public SimpleMssqlTestRepository(IAmbientAdoContextLocator ambientAdoContextLoca

private IDbConnection SqlConnection2 => ambientAdoContextLocator.GetContext<MssqlContextExample2>().Connection;

private IDbConnection SqlConnection3 => ambientAdoContextLocator.GetContext<MssqlContextExample3>().Connection;

private IDbTransaction SqlTransaction3 => ambientAdoContextLocator.GetContext<MssqlContextExample3>().Transaction;

public void Add(TestEntity entity)
{
const string query = "INSERT INTO TestEntity (Name, Description, Quantity) VALUES (@Name, @Description, @Quantity)";
Expand All @@ -42,6 +46,12 @@ public TestEntity GetEntityByName(string name)
return SqlConnection1.QuerySingleOrDefault<TestEntity>(query, new { Name = name });
}

public IEnumerable<TestEntity> GetEntities()
{
const string query = "SELECT * FROM TestEntity";
return SqlConnection3.Query<TestEntity>(query, transaction: SqlTransaction3);
}

public int GetEntityCount()
{
const string query = "SELECT COUNT(*) FROM TestEntity";
Expand Down
17 changes: 17 additions & 0 deletions Promethix.Framework.Ado/Implementation/AdoContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ public IDbConnection Connection
}
}

/// <summary>
/// Gets the transaction for reference.
/// WARNING: This should not be used to commit or rollback the transaction!
/// </summary>
public IDbTransaction Transaction
{
get
{
if (transaction == null)
{
throw new InvalidOperationException("There is no active transaction.");
}

return transaction;
}
}

protected AdoContext()
{
// No Implementation
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
Loading