Skip to content

Commit 786de9b

Browse files
committed
Implemting async methods on AuditEventListener (sync for now)
1 parent dd61836 commit 786de9b

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed

Src/NHibernate.Envers.Tests/NHibernate.Envers.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="NetSpecific\Integration\Access\None\ManyToOne\Model.cs" />
125125
<Compile Include="NetSpecific\Integration\Access\None\SimpleProperty\Fixture.cs" />
126126
<Compile Include="NetSpecific\Integration\Access\None\SimpleProperty\Entity.cs" />
127+
<Compile Include="NetSpecific\Integration\Async\AuditEventListenerAsyncTest.cs" />
127128
<Compile Include="NetSpecific\Integration\Component\BaseClassComponent.cs" />
128129
<Compile Include="NetSpecific\Integration\Component\BaseClassOwner.cs" />
129130
<Compile Include="NetSpecific\Integration\Component\DerivedClassComponent.cs" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NHibernate.Envers.Tests.NetSpecific.Integration.BidirectionalList;
5+
using NUnit.Framework;
6+
using SharpTestsEx;
7+
8+
namespace NHibernate.Envers.Tests.NetSpecific.Integration.Async
9+
{
10+
public class AuditEventListenerAsyncTest : TestBase
11+
{
12+
public AuditEventListenerAsyncTest(string strategyType) : base(strategyType)
13+
{
14+
}
15+
16+
protected override void Initialize()
17+
{
18+
}
19+
20+
[Test]
21+
public async void AsyncImplementationOfAuditEventListenerWorks()
22+
{
23+
var parent = new Parent();
24+
var child = new Child { Parent = parent };
25+
using (var tx = Session.BeginTransaction())
26+
{
27+
await Session.SaveAsync(parent);
28+
await tx.CommitAsync();
29+
}
30+
using (var tx = Session.BeginTransaction())
31+
{
32+
parent.Children.Add(child);
33+
await tx.CommitAsync();
34+
}
35+
using (var tx = Session.BeginTransaction())
36+
{
37+
parent.Name = Guid.NewGuid().ToString();
38+
await tx.CommitAsync();
39+
}
40+
using (var tx = Session.BeginTransaction())
41+
{
42+
await Session.DeleteAsync(parent);
43+
await tx.CommitAsync();
44+
}
45+
AuditReader().GetRevisions(typeof(Parent), parent.Id).Count()
46+
.Should().Be.EqualTo(4);
47+
}
48+
49+
protected override IEnumerable<string> Mappings { get; } = new[]{ "NetSpecific.Integration.BidirectionalList.Mapping.hbm.xml" };
50+
}
51+
}

Src/NHibernate.Envers.Tests/NetSpecific/Integration/BidirectionalList/Mapping.hbm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<index column ="IndexOrder" />
1515
<one-to-many class="Child"/>
1616
</list>
17+
<property name="Name"/>
1718
</class>
1819
<class name="Child">
1920
<id name="Id">

Src/NHibernate.Envers.Tests/NetSpecific/Integration/BidirectionalList/Parent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public virtual IList<Child> Children
1818
{
1919
get { return _children; }
2020
}
21+
public virtual string Name { get; set; }
2122

2223
public override bool Equals(object obj)
2324
{

Src/NHibernate.Envers/Event/AuditEventListener.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ private void addCollectionChangeWorkUnit(AuditProcess auditProcess, ISessionImpl
106106

107107
public Task OnPostInsertAsync(PostInsertEvent @event, CancellationToken cancellationToken)
108108
{
109-
throw new NotImplementedException();
109+
OnPostInsert(@event);
110+
return Task.CompletedTask;
110111
}
111112

112113
public virtual void OnPostInsert(PostInsertEvent evt)
@@ -128,7 +129,8 @@ public virtual void OnPostInsert(PostInsertEvent evt)
128129

129130
public Task OnPostUpdateAsync(PostUpdateEvent @event, CancellationToken cancellationToken)
130131
{
131-
throw new NotImplementedException();
132+
OnPostUpdate(@event);
133+
return Task.CompletedTask;
132134
}
133135

134136
public virtual void OnPostUpdate(PostUpdateEvent evt)
@@ -174,7 +176,8 @@ private static object[] postUpdateDbState(PostUpdateEvent evt)
174176

175177
public Task OnPostDeleteAsync(PostDeleteEvent @event, CancellationToken cancellationToken)
176178
{
177-
throw new NotImplementedException();
179+
OnPostDelete(@event);
180+
return Task.CompletedTask;
178181
}
179182

180183
public virtual void OnPostDelete(PostDeleteEvent evt)
@@ -334,7 +337,8 @@ private static CollectionEntry getCollectionEntry(AbstractCollectionEvent evt)
334337

335338
public Task OnPreUpdateCollectionAsync(PreCollectionUpdateEvent @event, CancellationToken cancellationToken)
336339
{
337-
throw new NotImplementedException();
340+
OnPreUpdateCollection(@event);
341+
return Task.CompletedTask;
338342
}
339343

340344
public virtual void OnPreUpdateCollection(PreCollectionUpdateEvent evt)
@@ -348,7 +352,8 @@ public virtual void OnPreUpdateCollection(PreCollectionUpdateEvent evt)
348352

349353
public Task OnPreRemoveCollectionAsync(PreCollectionRemoveEvent @event, CancellationToken cancellationToken)
350354
{
351-
throw new NotImplementedException();
355+
OnPreRemoveCollection(@event);
356+
return Task.CompletedTask;
352357
}
353358

354359
public virtual void OnPreRemoveCollection(PreCollectionRemoveEvent evt)
@@ -375,7 +380,8 @@ public virtual void OnPreRemoveCollection(PreCollectionRemoveEvent evt)
375380

376381
public Task OnPostRecreateCollectionAsync(PostCollectionRecreateEvent @event, CancellationToken cancellationToken)
377382
{
378-
throw new NotImplementedException();
383+
OnPostRecreateCollection(@event);
384+
return Task.CompletedTask;
379385
}
380386

381387
public virtual void OnPostRecreateCollection(PostCollectionRecreateEvent evt)

0 commit comments

Comments
 (0)