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 async support #50

Closed
wants to merge 10 commits into from
Closed
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools":{
"csharpasyncgenerator.tool": {
"version": "0.21.1",
"commands": [
"async-generator"
]
}
}
}
44 changes: 44 additions & 0 deletions .github/workflows/GenerateAsyncCode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Generate Async code

on:
pull_request_target:
paths:
- '**.cs'

permissions: {}

jobs:
generate-async:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.NHIBERNATE_BOT_TOKEN }}

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

- name: Generate Async code
run: |
pushd Src
dotnet tool restore
dotnet restore ./Envers.sln
dotnet async-generator
popd

- name: Push changes
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
if [[ -z "$(git status --porcelain)" ]]; then
echo "No changes to commit"
exit 0
fi
git add -A
git commit -am "Generate async files"
git push
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
hazzik marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- db: MySQL
connectionstring: "Server=localhost;Uid=root;Password=envers;Database=envers;SslMode=none;"
dialect: "NHibernate.Dialect.MySQL8InnoDBDialect"
driverclass: "NHibernate.Driver.MySqlDataDriver"
driverclass: "NHibernate.Driver.MySqlConnector.MySqlConnectorDriver, NHibernate.Driver.MySqlConnector"
- db: Oracle
connectionstring: "User ID=envers;Password=envers;Metadata Pooling=false;Self Tuning=false;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XEPDB1)))"
dialect: "NHibernate.Dialect.Oracle10gDialect"
Expand All @@ -47,7 +47,7 @@ jobs:
if: matrix.db == 'MySQL'
run: |
sudo service mysql stop
docker run --name mysql --tmpfs /var/lib/mysql:rw,noexec,nosuid,size=256m -e MYSQL_ROOT_PASSWORD=envers -e MYSQL_USER=envers -e MYSQL_PASSWORD=envers -e MYSQL_DATABASE=envers -p 3306:3306 --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -d mysql:8.0 mysqld --lower_case_table_names=1 --skip-ssl --default_authentication_plugin=mysql_native_password
docker run --name mysql --tmpfs /var/lib/mysql:rw,noexec,nosuid,size=1024m -e MYSQL_ROOT_PASSWORD=envers -e MYSQL_USER=envers -e MYSQL_PASSWORD=envers -e MYSQL_DATABASE=envers -p 3306:3306 --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -d mysql:8.0 mysqld --lower_case_table_names=1 --skip-ssl --default_authentication_plugin=mysql_native_password
- name: Set up Oracle
if: matrix.db == 'Oracle'
run: |
Expand Down
73 changes: 73 additions & 0 deletions Src/AsyncGenerator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
projects:
- filePath: NHibernate.Envers\NHibernate.Envers.csproj
targetFramework: netcoreapp2.0
concurrentRun: true
applyChanges: true
analyzation:
methodConversion:
- conversion: ToAsync
name: Results
containingTypeName: IEntityAuditQuery
- conversion: ToAsync
name: BuildAndExecuteQuery
containingTypeName: AbstractRevisionsQuery
- conversion: ToAsync
name: Results
containingTypeName: AllEntitiesAtRevisionQuery
- conversion: Ignore
containingTypeName: IPropertyMapper
- conversion: Ignore
containingTypeName: CollectionProxy
typeConversion:
- conversion: Ignore
name: Toolz
callForwarding: true
cancellationTokens:
guards: true
methodParameter:
- parameter: Optional
requiresCancellationToken:
- containingTypeName: IEntityAuditQuery
scanMethodBody: true
searchAsyncCounterpartsInInheritedTypes: true
scanForMissingAsyncMembers:
- all: true
alwaysAwait:
- all: true
transformation:
configureAwaitArgument: false
localFunctions: true
registerPlugin:
- type: AsyncGenerator.Core.Plugins.EmptyRegionRemover
assemblyName: AsyncGenerator.Core
- filePath: NHibernate.Envers.Tests\NHibernate.Envers.Tests.csproj
targetFramework: net6.0
concurrentRun: true
applyChanges: true
analyzation:
callForwarding: true
cancellationTokens:
enabled: true
scanMethodBody: true
searchAsyncCounterpartsInInheritedTypes: true
scanForMissingAsyncMembers:
- all: true
methodConversion:
- conversion: Ignore
name: Initialize
containingTypeName: OneStrategyTestBase
transformation:
configureAwaitArgument: false
localFunctions: true
registerPlugin:
- type: AsyncGenerator.Core.Plugins.NUnitPlugin
parameters:
- name: createNewTypes
value: false
assemblyName: AsyncGenerator.Core
- type: AsyncGenerator.Core.Plugins.TransactionScopeAsyncFlowAdder
assemblyName: AsyncGenerator.Core
methodRules:
- filters:
- containingType: NHibernate.Envers.Synchronization.transactionCompletionProcess
name: TransactionCompletion
6 changes: 5 additions & 1 deletion Src/Build/default.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<MakeDir Directories="$(TempDirectory)"/>
</Target>

<Target Name="BuildRelease" DependsOnTargets="RunBuild;nuget;CopyNuget">
<Target Name="BuildRelease" DependsOnTargets="RunBuild;GenerateAsyncCode;nuget;CopyNuget">
<RemoveDir Directories="$(TempDirectory)"/>
</Target>

Expand All @@ -37,6 +37,10 @@
<Target Name="RunBuild" DependsOnTargets="MakeBuildDirectory">
<MSBuild Projects="$(SourceDir)\NHibernate.Envers\NHibernate.Envers.csproj" Targets="Clean;Build" />
</Target>

<Target Name="GenerateAsyncCode" DependsOnTargets="RunBuild">
<Exec Command="dotnet async-generator" WorkingDirectory="$(SourceDir)" />
</Target>

<!-- Documentation build steps/targets-->
<Target Name="BuildDocs" DependsOnTargets="RunPdfBuild;RunHtmlBuild">
Expand Down
8 changes: 5 additions & 3 deletions Src/Envers.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{34BA8295-3EBE-47B0-ABBF-0A7E9A8E6B35}"
ProjectSection(SolutionItems) = preProject
AsyncGenerator.yml = AsyncGenerator.yml
Build\buildDoc.bat = Build\buildDoc.bat
Build\buildRelease.bat = Build\buildRelease.bat
Build\default.msbuild = Build\default.msbuild
ReleaseNotes.txt = ReleaseNotes.txt
..\.github\workflows\dotnet.yml = ..\.github\workflows\dotnet.yml
..\.github\workflows\GenerateAsyncCode.yml = ..\.github\workflows\GenerateAsyncCode.yml
ReleaseNotes.txt = ReleaseNotes.txt
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Doc", "Doc", "{C9C74EFE-506E-41A8-8359-88AB303E60DA}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using NUnit.Framework;

namespace NHibernate.Envers.Tests.Integration.AccessType
{
using System.Threading.Tasks;
public partial class FieldAccessTest : TestBase
{

[Test]
public async Task VerifyRevisionCountAsync()
{
CollectionAssert.AreEquivalent(new[] { 1, 2 }, await (AuditReader().GetRevisionsAsync(typeof(FieldAccessEntity), id)).ConfigureAwait(false));
}

[Test]
public async Task VerifyHistoryAsync()
{
var ver1 = new FieldAccessEntity { Id = id };
ver1.SetData("first");
var ver2 = new FieldAccessEntity { Id = id };
ver2.SetData("second");

Assert.AreEqual(ver1, await (AuditReader().FindAsync<FieldAccessEntity>(id, 1)).ConfigureAwait(false));
Assert.AreEqual(ver2, await (AuditReader().FindAsync<FieldAccessEntity>(id, 2)).ConfigureAwait(false));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using NUnit.Framework;

namespace NHibernate.Envers.Tests.Integration.AccessType
{
using System.Threading.Tasks;
public partial class ImmutableClassAccessTest : TestBase
{

[Test]
public async Task VerifyRevisionCountAsync()
{
CollectionAssert.AreEquivalent(new[] { 1 }, await (AuditReader().GetRevisionsAsync(typeof(Country), country.Code)).ConfigureAwait(false));
}

[Test]
public async Task VerifyHistoryAsync()
{
var country1 = await (Session.GetAsync<Country>(country.Code)).ConfigureAwait(false);
Assert.AreEqual(country, country1);

var history = await (AuditReader().FindAsync<Country>(country1.Code, 1)).ConfigureAwait(false);
Assert.AreEqual(country, history);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using NUnit.Framework;

namespace NHibernate.Envers.Tests.Integration.AccessType
{
using System.Threading.Tasks;
public partial class MixedAccessTest : TestBase
{

[Test]
public async Task VerifyRevisionCountAsync()
{
CollectionAssert.AreEquivalent(new[] { 1, 2 }, await (AuditReader().GetRevisionsAsync(typeof(MixedAccessEntity), id1)).ConfigureAwait(false));
}

[Test]
public async Task VerifyHistoryAsync()
{
var ver1 = new MixedAccessEntity(id1, "data");
var ver2 = new MixedAccessEntity(id1, "data2");

var rev1 = await (AuditReader().FindAsync<MixedAccessEntity>(id1, 1)).ConfigureAwait(false);
var rev2 = await (AuditReader().FindAsync<MixedAccessEntity>(id1, 2)).ConfigureAwait(false);

Assert.IsTrue(rev1.IsDataSet);
Assert.IsTrue(rev2.IsDataSet);

Assert.AreEqual(ver1, rev1);
Assert.AreEqual(ver2, rev2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using NUnit.Framework;

namespace NHibernate.Envers.Tests.Integration.AccessType
{
using System.Threading.Tasks;
public partial class NoSetterTest : TestBase
{

[Test]
public async Task VerifyRevisionCountAsync()
{
CollectionAssert.AreEquivalent(new[] { 1, 2 }, await (AuditReader().GetRevisionsAsync(typeof(NoSetterEntity), id1)).ConfigureAwait(false));
}

[Test]
public async Task VerifyHistoryAsync()
{
var rev1 = await (AuditReader().FindAsync<NoSetterEntity>(id1, 1)).ConfigureAwait(false);
var rev2 = await (AuditReader().FindAsync<NoSetterEntity>(id1, 2)).ConfigureAwait(false);

Assert.AreEqual("data", rev1.Data);
Assert.AreEqual("data2", rev2.Data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using NUnit.Framework;

namespace NHibernate.Envers.Tests.Integration.AccessType
{
using System.Threading.Tasks;
public partial class PropertyAccessTest : TestBase
{

[Test]
public async Task VerifyRevisionCountAsync()
{
CollectionAssert.AreEquivalent(new[] { 1, 2 }, await (AuditReader().GetRevisionsAsync(typeof(PropertyAccessEntity), id)).ConfigureAwait(false));
}

[Test]
public async Task VerifyHistoryAsync()
{
Assert.AreEqual("first", (await (AuditReader().FindAsync<PropertyAccessEntity>(id, 1)).ConfigureAwait(false)).Data);
Assert.AreEqual("second", (await (AuditReader().FindAsync<PropertyAccessEntity>(id, 2)).ConfigureAwait(false)).Data);
}
}
}
Loading
Loading