Skip to content

Commit 668c29e

Browse files
committed
Cleanup test & fix
1 parent 87cce36 commit 668c29e

File tree

4 files changed

+49
-114
lines changed

4 files changed

+49
-114
lines changed
Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
1-

1+
using System;
22

3-
using System;
4-
using System.Collections.Generic;
53
namespace NHibernate.Test.NHSpecificTest.NH3898
64
{
75
public class Employee
86
{
9-
private Int32 id;
10-
public virtual Int32 Id
11-
{
12-
get { return id; }
13-
set { id = value; }
14-
}
7+
public virtual int Id { get; set; }
158

16-
private String name;
17-
public virtual String Name
18-
{
19-
get { return name; }
20-
set { name = value; }
21-
}
9+
public virtual string Name { get; set; }
2210

23-
private Int32 promotionCount;
24-
25-
public virtual Int32 PromotionCount
26-
{
27-
get { return promotionCount; }
28-
set { promotionCount = value; }
29-
}
11+
public virtual int PromotionCount { get; set; }
3012
}
31-
}
13+
}
Lines changed: 31 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,61 @@
1-
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using System.Text;
5-
using NHibernate.Dialect;
6-
using NUnit.Framework;
7-
using NHibernate.Test.NHSpecificTest;
8-
using Iesi.Collections.Generic;
9-
using NHibernate;
10-
using System.Data;
11-
using NHibernate.Criterion;
1+
using NUnit.Framework;
122

133
namespace NHibernate.Test.NHSpecificTest.NH3898
144
{
15-
/// <summary>
16-
/// <para>
17-
/// </para>
18-
/// </remarks>
195
[TestFixture]
206
public class Fixture : BugTestCase
217
{
22-
protected override void Configure(NHibernate.Cfg.Configuration configuration)
8+
protected override void Configure(Cfg.Configuration configuration)
239
{
24-
#region removing possible second-level-cache configs
25-
configuration.Properties.Remove(NHibernate.Cfg.Environment.CacheProvider);
26-
configuration.Properties.Remove(NHibernate.Cfg.Environment.UseQueryCache);
27-
configuration.Properties.Add(NHibernate.Cfg.Environment.UseQueryCache, "true");
28-
configuration.Properties.Remove(NHibernate.Cfg.Environment.UseSecondLevelCache);
29-
#endregion
30-
31-
base.Configure(configuration);
10+
configuration.SetProperty(Cfg.Environment.UseQueryCache, "false");
11+
configuration.SetProperty(Cfg.Environment.UseSecondLevelCache, "false");
3212
}
3313

3414
protected override void OnTearDown()
3515
{
36-
base.OnTearDown();
37-
using (ISession s = OpenSession())
16+
using (var s = OpenSession())
17+
using (var tx = s.BeginTransaction())
3818
{
39-
int countUpdate = 0;
40-
41-
countUpdate =
42-
s
43-
.CreateSQLQuery("DELETE FROM T_EMPLOYEE")
44-
.ExecuteUpdate();
45-
Assert.AreEqual(1, countUpdate);
19+
s.CreateQuery("delete from Employee").ExecuteUpdate();
4620

47-
s.Flush();
21+
tx.Commit();
4822
}
4923
}
5024

51-
protected override void OnSetUp()
52-
{
53-
base.OnSetUp();
54-
}
55-
56-
protected override bool AppliesTo(global::NHibernate.Dialect.Dialect dialect)
57-
{
58-
//return dialect as MsSql2005Dialect != null;
59-
return base.AppliesTo(dialect);
60-
}
61-
62-
/// <summary>
63-
/// Test that reproduces the problem.
64-
/// </summary>
6525
[Test]
6626
public void GeneratedInsertUpdateTrue()
6727
{
68-
using (ISession session = this.OpenSession())
28+
object id;
29+
using (var session = OpenSession())
30+
using (var tx = session.BeginTransaction())
6931
{
70-
using (ITransaction tx = session.BeginTransaction())
32+
var employee = new Employee
7133
{
72-
Employee employee = new Employee();
73-
employee.Id = 1;
74-
employee.Name = "Employee 1";
75-
employee.PromotionCount = 9999999;
76-
session.Save(employee);
77-
Assert.AreEqual(0, employee.PromotionCount);
78-
tx.Commit();
79-
}
34+
Name = "Employee 1",
35+
PromotionCount = 9999999
36+
};
37+
id = session.Save(employee);
38+
Assert.That(employee.PromotionCount, Is.EqualTo(0));
39+
tx.Commit();
8040
}
8141

82-
using (ISession session = this.OpenSession())
42+
using (var session = OpenSession())
43+
using (var tx = session.BeginTransaction())
8344
{
84-
using (ITransaction tx = session.BeginTransaction())
85-
{
86-
Employee employee = session.Get<Employee>(1);
87-
employee.Name = "Employee 1 changed";
88-
employee.PromotionCount++;
89-
Assert.AreEqual(1, employee.PromotionCount);
90-
tx.Commit();
91-
}
45+
var employee = session.Get<Employee>(id);
46+
employee.Name = "Employee 1 changed";
47+
employee.PromotionCount++;
48+
Assert.That(employee.PromotionCount, Is.EqualTo(1));
49+
tx.Commit();
9250
}
9351

94-
using (ISession session = this.OpenSession())
52+
using (var session = OpenSession())
53+
using (session.BeginTransaction())
9554
{
96-
Employee employee = session.Get<Employee>(1);
97-
Assert.AreEqual("Employee 1 changed", employee.Name);
98-
Assert.AreEqual(1, employee.PromotionCount);
55+
var employee = session.Get<Employee>(id);
56+
Assert.That(employee.Name, Is.EqualTo("Employee 1 changed"));
57+
Assert.That(employee.PromotionCount, Is.EqualTo(1));
9958
}
10059
}
10160
}
102-
}
61+
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3-
namespace="NHibernate.Test.NHSpecificTest.NH3898" default-access="field.camelcase"
4-
default-lazy="true" default-cascade="none">
3+
namespace="NHibernate.Test.NHSpecificTest.NH3898">
54

6-
<class name="Employee" table="T_EMPLOYEE" mutable="true">
7-
<id name="Id" column="C_E_ID">
5+
<class name="Employee">
6+
<id name="Id">
87
<generator class="native" />
98
</id>
10-
<property name="Name" column="C_E_NAME"/>
9+
<property name="Name"/>
1110
<property name="PromotionCount" insert="false" generated="insert">
12-
<column name="C_E_PROMOTION_COUNT" default="0"/>
11+
<column name="PromotionCount" default="0"/>
1312
</property>
1413
</class>
15-
</hibernate-mapping>
14+
</hibernate-mapping>

src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,24 +289,19 @@ private void BindValueProperty(HbmProperty propertyMapping, Property property)
289289
throw new MappingException("cannot specify both insert=\"true\" and generated=\"" + generation
290290
+ "\" for property: " + propertyMapping.Name);
291291
}
292-
else
293-
{
294-
property.IsInsertable = false;
295-
}
296-
292+
property.IsInsertable = false;
293+
}
294+
if (generation == PropertyGeneration.Always)
295+
{
297296
// properties generated on update can never be updateable...
298-
if (propertyMapping.updateSpecified && property.IsUpdateable && generation == PropertyGeneration.Always)
297+
if (propertyMapping.updateSpecified && property.IsUpdateable)
299298
{
300299
// the user specifically supplied update="true",
301300
// which constitutes an illegal combo
302301
throw new MappingException("cannot specify both update=\"true\" and generated=\"" + generation
303302
+ "\" for property: " + propertyMapping.Name);
304303
}
305-
//Fix for NH-3898
306-
else if (generation == PropertyGeneration.Always)
307-
{
308-
property.IsUpdateable = false;
309-
}
304+
property.IsUpdateable = false;
310305
}
311306
}
312307

@@ -422,4 +417,4 @@ private string GetPropertyAccessorName(string propertyMappedAccessor)
422417
return propertyMappedAccessor ?? Mappings.DefaultAccess;
423418
}
424419
}
425-
}
420+
}

0 commit comments

Comments
 (0)