Skip to content

Commit c02468c

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

File tree

4 files changed

+68
-133
lines changed

4 files changed

+68
-133
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: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
186186
property.LogMapped(log);
187187
addToModelAction(property);
188188
}
189-
}
189+
}
190190
}
191191

192192
private Component CreateNewComponent(Table table)
@@ -197,7 +197,7 @@ private Component CreateNewComponent(Table table)
197197

198198
private System.Type GetPropertyType(string classMapping, System.Type containingType, string propertyName, string propertyAccess)
199199
{
200-
if(!string.IsNullOrEmpty(classMapping))
200+
if (!string.IsNullOrEmpty(classMapping))
201201
return ClassForNameChecked(classMapping, mappings, "could not find class: {0}");
202202
else if (containingType == null)
203203
return null;
@@ -235,7 +235,7 @@ private void BindManyToOne(HbmManyToOne manyToOneMapping, ManyToOne model, strin
235235
{
236236
AddManyToOneSecondPass(model);
237237
}
238-
238+
239239
if (manyToOneMapping.unique)
240240
{
241241
model.IsLogicalOneToOne = true;
@@ -260,8 +260,8 @@ private void AddManyToOneSecondPass(ManyToOne manyToOne)
260260

261261
private void BindValueProperty(HbmProperty propertyMapping, Property property)
262262
{
263-
property.IsUpdateable = propertyMapping.updateSpecified ? propertyMapping.update:true;
264-
property.IsInsertable = propertyMapping.insertSpecified ? propertyMapping.insert:true;
263+
property.IsUpdateable = propertyMapping.updateSpecified ? propertyMapping.update : true;
264+
property.IsInsertable = propertyMapping.insertSpecified ? propertyMapping.insert : true;
265265
PropertyGeneration generation;
266266
switch (propertyMapping.generated)
267267
{
@@ -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
303-
+ "\" for property: " + propertyMapping.Name);
304-
}
305-
//Fix for NH-3898
306-
else if (generation == PropertyGeneration.Always)
307-
{
308-
property.IsUpdateable = false;
302+
+ "\" for property: " + propertyMapping.Name);
309303
}
304+
property.IsUpdateable = false;
310305
}
311306
}
312307

@@ -363,11 +358,11 @@ private void BindComponentProperty(HbmComponent componentMapping, Property prope
363358
if (tuplizers != null)
364359
{
365360
Array.ForEach(tuplizers.Select(tuplizer => new
366-
{
367-
TuplizerClassName = FullQualifiedClassName(tuplizer.@class, mappings),
368-
Mode = tuplizer.entitymode.ToEntityMode()
369-
}).ToArray(),
370-
x => model.AddTuplizer(x.Mode, x.TuplizerClassName));
361+
{
362+
TuplizerClassName = FullQualifiedClassName(tuplizer.@class, mappings),
363+
Mode = tuplizer.entitymode.ToEntityMode()
364+
}).ToArray(),
365+
x => model.AddTuplizer(x.Mode, x.TuplizerClassName));
371366
}
372367
}
373368

@@ -405,14 +400,14 @@ private Property CreateProperty(IEntityPropertyMapping propertyMapping, string p
405400
value.SetTypeUsingReflection(propertyOwnerClassName, propertyMapping.Name, propertyAccessorName);
406401

407402
var property = new Property
408-
{
409-
Name = propertyMapping.Name,
410-
PropertyAccessorName = propertyAccessorName,
411-
Value = value,
412-
IsLazy = propertyMapping.IsLazyProperty,
413-
IsOptimisticLocked = propertyMapping.OptimisticLock,
414-
MetaAttributes = GetMetas(propertyMapping, inheritedMetas)
415-
};
403+
{
404+
Name = propertyMapping.Name,
405+
PropertyAccessorName = propertyAccessorName,
406+
Value = value,
407+
IsLazy = propertyMapping.IsLazyProperty,
408+
IsOptimisticLocked = propertyMapping.OptimisticLock,
409+
MetaAttributes = GetMetas(propertyMapping, inheritedMetas)
410+
};
416411

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

0 commit comments

Comments
 (0)