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

Unexpected session flush when calling AuditReader.GetCurrentRevision #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -0,0 +1,13 @@
using System;
using NHibernate.Envers.Configuration.Attributes;

namespace NHibernate.Envers.Tests.NetSpecific.Integration.TransactionUnexpectedFlush
{
[Audited]
public class Entity
{
public virtual Guid Id { get; set; }

public virtual string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Envers.Tests"
namespace="NHibernate.Envers.Tests.NetSpecific.Integration.TransactionUnexpectedFlush">
<class name="Entity">
<id name="Id">
<generator class="guid"/>
</id>
<property name="Name"/>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Envers.Tests.NetSpecific.Integration.TransactionUnexpectedFlush
{
public class TransactionUnexpectedFlushTest : TestBase
{
public TransactionUnexpectedFlushTest(AuditStrategyForTest strategyType)
: base(strategyType)
{
}

protected override IEnumerable<string> Mappings => new[] {"NetSpecific.Integration.TransactionUnexpectedFlush.Mapping.hbm.xml"};

protected override void Initialize()
{
}

[Test]
public void GetCurrentRevision_PersistIsTrue_ShouldNotFlushUncommitedChanges()
{
// Arrange
var entity = new Entity { Id = Guid.NewGuid(), Name = "entity name" };

int notCommitedTransactionEntitiesCount = 0;

// Act
using (var tx = Session.BeginTransaction())
{
Session.Save(entity);

AuditReader().GetCurrentRevision(true);

notCommitedTransactionEntitiesCount = Session.Query<DefaultRevisionEntity>().Count();

tx.Commit();
}

// Assert
Assert.Zero(notCommitedTransactionEntitiesCount);
}
}
}