Roger Kratz avatar Roger Kratz committed 7da2699

NHE-93 fixed

Comments (0)

Files changed (3)

Src/NHibernate.Envers.Tests/Integration/Basic/TransactionRollbackBehaviourTest.cs

+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Envers.Tests.Entities;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Envers.Tests.Integration.Basic
+{
+	public class TransactionRollbackBehaviourTest : TestBase
+	{
+		private int rollbackId;
+		private int committedId;
+
+		public TransactionRollbackBehaviourTest(string strategyType) : base(strategyType)
+		{
+		}
+
+		protected override void Initialize()
+		{
+			using (var tx = Session.BeginTransaction())
+			{
+				var iteRollback = new IntTestEntity {Number = 30};
+				rollbackId = (int) Session.Save(iteRollback);
+				tx.Rollback();
+			}
+			using (var tx = Session.BeginTransaction())
+			{
+				var iteCommitted = new IntTestEntity {Number = 50};
+				committedId = (int) Session.Save(iteCommitted);
+				tx.Commit();
+			}
+		}
+
+		[Test]
+		public void VerifyAuditRecordsRollback()
+		{
+			AuditReader().GetRevisions(typeof (IntTestEntity), committedId).Count().Should().Be.EqualTo(1);
+			AuditReader().GetRevisions(typeof (IntTestEntity), rollbackId).Should().Be.Empty();
+		}
+
+		protected override IEnumerable<string> Mappings
+		{
+			get { return new[] {"Entities.Mapping.hbm.xml"}; }
+		}
+	}
+}

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

     <Compile Include="Entities\Ids\ManyToOneNotAuditedEmbId.cs" />
     <Compile Include="Integration\Basic\EmptyStringTest.cs" />
     <Compile Include="Integration\Basic\OutsideTransactionTest.cs" />
+    <Compile Include="Integration\Basic\TransactionRollbackBehaviourTest.cs" />
     <Compile Include="Integration\Ids\CompositeDateIdTest.cs" />
     <Compile Include="Integration\Ids\DateIdTest.cs" />
     <Compile Include="Integration\Ids\ManyToOneIdNotAuditedTest.cs" />

Src/NHibernate.Envers/Synchronization/AuditProcessManager.cs

 	[Serializable]
 	public class AuditProcessManager
 	{
-		private readonly IDictionary<ITransaction, AuditProcess> auditProcesses;
-		private readonly IRevisionInfoGenerator revisionInfoGenerator;
+		private readonly IDictionary<ITransaction, AuditProcess> _auditProcesses;
+		private readonly IRevisionInfoGenerator _revisionInfoGenerator;
 
 		public AuditProcessManager(IRevisionInfoGenerator revisionInfoGenerator)
 		{
-			auditProcesses = new ThreadSafeDictionary<ITransaction, AuditProcess>(new Dictionary<ITransaction, AuditProcess>());
-			this.revisionInfoGenerator = revisionInfoGenerator;
+			_auditProcesses = new ThreadSafeDictionary<ITransaction, AuditProcess>(new Dictionary<ITransaction, AuditProcess>());
+			_revisionInfoGenerator = revisionInfoGenerator;
 		}
 
 		public AuditProcess Get(IEventSource session)
 			var transaction = session.Transaction;
 
 			AuditProcess auditProcess;
-			if (!auditProcesses.TryGetValue(transaction, out auditProcess))
+			if (!_auditProcesses.TryGetValue(transaction, out auditProcess))
 			{
 				// No worries about registering a transaction twice - a transaction is single thread
-				auditProcess = new AuditProcess(revisionInfoGenerator, session);
-				auditProcesses[transaction] = auditProcess;
+				auditProcess = new AuditProcess(_revisionInfoGenerator, session);
+				_auditProcesses[transaction] = auditProcess;
 
-				session.ActionQueue.RegisterProcess(auditProcess.DoBeforeTransactionCompletion);
-				session.ActionQueue.RegisterProcess(success => auditProcesses.Remove(transaction));
+				session.ActionQueue.RegisterProcess(() =>
+				                                    	{
+				                                    		AuditProcess currentProcess;
+																		if(_auditProcesses.TryGetValue(transaction, out currentProcess))
+																		{
+																			currentProcess.DoBeforeTransactionCompletion();
+																		}
+				                                    	});
+				session.ActionQueue.RegisterProcess(success => _auditProcesses.Remove(transaction));
 			}
 
 			return auditProcess;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.