Skip to content

Commit 52e3798

Browse files
Fix unsaved-value for assigned identifiers
Revert NH-1914 (partially revert 3ccc965)
1 parent 3adcfa7 commit 52e3798

File tree

11 files changed

+219
-507
lines changed

11 files changed

+219
-507
lines changed

src/NHibernate.Test/Async/Extralazy/ExtraLazyFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by AsyncGenerator.
44
//
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Linq;
13+
using NUnit.Framework;
14+
using NHibernate.Linq;
15+
16+
namespace NHibernate.Test.NHSpecificTest.GH1756
17+
{
18+
using System.Threading.Tasks;
19+
[TestFixture]
20+
public class UnsavedValueNoneFixtureAsync : BugTestCase
21+
{
22+
// disable second level cache enabled by default by the base class.
23+
protected override string CacheConcurrencyStrategy => null;
24+
25+
protected override void OnSetUp()
26+
{
27+
using (var session = OpenSession())
28+
using (var transaction = session.BeginTransaction())
29+
{
30+
var e1 = new Entity { Id = Guid.NewGuid(), Name = "Bob"};
31+
session.Save(e1);
32+
33+
transaction.Commit();
34+
}
35+
Sfi.Statistics.IsStatisticsEnabled = true;
36+
}
37+
38+
protected override void OnTearDown()
39+
{
40+
using (var session = OpenSession())
41+
using (var transaction = session.BeginTransaction())
42+
{
43+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
44+
45+
transaction.Commit();
46+
}
47+
}
48+
49+
[Test]
50+
public async Task ShouldUpdateByDefaultAsync()
51+
{
52+
Entity e;
53+
using (var session = OpenSession())
54+
using (var tx = session.BeginTransaction())
55+
{
56+
e = await (session.Query<Entity>().FirstAsync());
57+
await (tx.CommitAsync());
58+
}
59+
60+
e.Name = "Sally";
61+
Sfi.Statistics.Clear();
62+
63+
using (var session = OpenSession())
64+
using (var tx = session.BeginTransaction())
65+
{
66+
await (session.SaveOrUpdateAsync(e));
67+
await (tx.CommitAsync());
68+
}
69+
70+
// Checks that no select has been done for verifying the entity state.
71+
Assert.That(Sfi.Statistics.PrepareStatementCount, Is.EqualTo(1));
72+
}
73+
74+
[Test]
75+
public async Task ShouldFailByTryingToUpdateAsync()
76+
{
77+
var e = new Entity { Id = Guid.NewGuid(), Name = "Sally"};
78+
79+
using (var session = OpenSession())
80+
using (var tx = session.BeginTransaction())
81+
{
82+
await (session.SaveOrUpdateAsync(e));
83+
Assert.That(tx.Commit, Throws.InstanceOf<StaleStateException>());
84+
}
85+
}
86+
}
87+
}

src/NHibernate.Test/Async/NHSpecificTest/NH1914/Fixture.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH1756
4+
{
5+
class Entity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH1756">
4+
5+
<class name="Entity">
6+
<id name="Id" generator="assigned" unsaved-value="none"/>
7+
<property name="Name"/>
8+
</class>
9+
10+
</hibernate-mapping>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Linq;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.GH1756
6+
{
7+
[TestFixture]
8+
public class UnsavedValueNoneFixture : BugTestCase
9+
{
10+
// disable second level cache enabled by default by the base class.
11+
protected override string CacheConcurrencyStrategy => null;
12+
13+
protected override void OnSetUp()
14+
{
15+
using (var session = OpenSession())
16+
using (var transaction = session.BeginTransaction())
17+
{
18+
var e1 = new Entity { Id = Guid.NewGuid(), Name = "Bob"};
19+
session.Save(e1);
20+
21+
transaction.Commit();
22+
}
23+
Sfi.Statistics.IsStatisticsEnabled = true;
24+
}
25+
26+
protected override void OnTearDown()
27+
{
28+
using (var session = OpenSession())
29+
using (var transaction = session.BeginTransaction())
30+
{
31+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
32+
33+
transaction.Commit();
34+
}
35+
}
36+
37+
[Test]
38+
public void ShouldUpdateByDefault()
39+
{
40+
Entity e;
41+
using (var session = OpenSession())
42+
using (var tx = session.BeginTransaction())
43+
{
44+
e = session.Query<Entity>().First();
45+
tx.Commit();
46+
}
47+
48+
e.Name = "Sally";
49+
Sfi.Statistics.Clear();
50+
51+
using (var session = OpenSession())
52+
using (var tx = session.BeginTransaction())
53+
{
54+
session.SaveOrUpdate(e);
55+
tx.Commit();
56+
}
57+
58+
// Checks that no select has been done for verifying the entity state.
59+
Assert.That(Sfi.Statistics.PrepareStatementCount, Is.EqualTo(1));
60+
}
61+
62+
[Test]
63+
public void ShouldFailByTryingToUpdate()
64+
{
65+
var e = new Entity { Id = Guid.NewGuid(), Name = "Sally"};
66+
67+
using (var session = OpenSession())
68+
using (var tx = session.BeginTransaction())
69+
{
70+
session.SaveOrUpdate(e);
71+
Assert.That(tx.Commit, Throws.InstanceOf<StaleStateException>());
72+
}
73+
}
74+
}
75+
}

src/NHibernate.Test/NHSpecificTest/NH1914/Fixture.cs

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/NHibernate.Test/NHSpecificTest/NH1914/Mappings.hbm.xml

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)