Skip to content

Commit e65ab36

Browse files
Support an arbitrary length for CultureInfoType (#3481)
1 parent a958ff1 commit e65ab36

22 files changed

+274
-159
lines changed

doc/reference/modules/basic_mapping.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3919,7 +3919,8 @@
39193919
<row>
39203920
<entry><literal>CultureInfo</literal></entry>
39213921
<entry><literal>System.Globalization.CultureInfo</literal></entry>
3922-
<entry><literal>DbType.String</literal> - 5 chars for culture</entry>
3922+
<entry><literal>DbType.String</literal> - 5 chars for culture by default;
3923+
can be modified by the <literal>length</literal> mapping attribute.</entry>
39233924
<entry>Default when no <literal>type</literal> attribute specified.</entry>
39243925
</row>
39253926
<row>

src/NHibernate.Test/Async/TypesTest/AbstractDateTimeTypeFixture.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,10 @@ protected override void OnSetUp()
6969

7070
protected override void OnTearDown()
7171
{
72-
base.OnTearDown();
73-
74-
using (var s = OpenSession())
75-
using (var t = s.BeginTransaction())
76-
{
77-
s.CreateQuery("delete from DateTimeClass").ExecuteUpdate();
78-
t.Commit();
79-
}
72+
using var s = OpenSession();
73+
using var t = s.BeginTransaction();
74+
s.CreateQuery("delete from DateTimeClass").ExecuteUpdate();
75+
t.Commit();
8076
}
8177

8278
protected override void DropSchema()
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.Globalization;
13+
using NHibernate.Dialect;
14+
using NHibernate.Type;
15+
using NUnit.Framework;
16+
17+
namespace NHibernate.Test.TypesTest
18+
{
19+
using System.Threading.Tasks;
20+
[TestFixture]
21+
public class CultureInfoTypeFixtureAsync : TypeFixtureBase
22+
{
23+
protected override string TypeName => "CultureInfo";
24+
25+
[Test]
26+
public async Task ReadWriteBasicCultureAsync()
27+
{
28+
Guid id;
29+
using (var s = OpenSession())
30+
using (var t = s.BeginTransaction())
31+
{
32+
var entity = new CultureInfoClass { BasicCulture = CultureInfo.GetCultureInfo("en-US") };
33+
await (s.SaveAsync(entity));
34+
id = entity.Id;
35+
await (t.CommitAsync());
36+
}
37+
38+
using (var s = OpenSession())
39+
using (var t = s.BeginTransaction())
40+
{
41+
var entity = await (s.GetAsync<CultureInfoClass>(id));
42+
Assert.That(entity.BasicCulture, Is.Not.Null);
43+
Assert.That(entity.BasicCulture.Name, Is.EqualTo("en-US"));
44+
Assert.That(entity.BasicCulture, Is.EqualTo(CultureInfo.GetCultureInfo("en-US")));
45+
entity.BasicCulture = CultureInfo.GetCultureInfo("fr-BE");
46+
await (t.CommitAsync());
47+
}
48+
49+
using (var s = OpenSession())
50+
using (var t = s.BeginTransaction())
51+
{
52+
var entity = await (s.GetAsync<CultureInfoClass>(id));
53+
Assert.That(entity.BasicCulture.Name, Is.EqualTo("fr-BE"));
54+
Assert.That(entity.BasicCulture, Is.EqualTo(CultureInfo.GetCultureInfo("fr-BE")));
55+
entity.BasicCulture = null;
56+
await (t.CommitAsync());
57+
}
58+
59+
using (var s = OpenSession())
60+
using (var t = s.BeginTransaction())
61+
{
62+
var entity = await (s.GetAsync<CultureInfoClass>(id));
63+
Assert.That(entity.BasicCulture, Is.Null);
64+
await (t.CommitAsync());
65+
}
66+
}
67+
68+
[Test]
69+
public async Task ReadWriteExtendedCultureAsync()
70+
{
71+
Guid id;
72+
using (var s = OpenSession())
73+
using (var t = s.BeginTransaction())
74+
{
75+
var entity = new CultureInfoClass { ExtendedCulture = CultureInfo.GetCultureInfo("en-US-posix") };
76+
await (s.SaveAsync(entity));
77+
id = entity.Id;
78+
await (t.CommitAsync());
79+
}
80+
81+
using (var s = OpenSession())
82+
using (var t = s.BeginTransaction())
83+
{
84+
var entity = await (s.GetAsync<CultureInfoClass>(id));
85+
Assert.That(entity.ExtendedCulture, Is.Not.Null);
86+
// Under Windows, it is named en-US-posix, but en-US-POSIX under Linux.
87+
Assert.That(entity.ExtendedCulture.Name, Is.EqualTo("en-US-posix").IgnoreCase);
88+
Assert.That(entity.ExtendedCulture, Is.EqualTo(CultureInfo.GetCultureInfo("en-US-posix")));
89+
await (t.CommitAsync());
90+
}
91+
}
92+
93+
[Test]
94+
public async Task WriteTooLongCultureAsync()
95+
{
96+
if (Dialect is SQLiteDialect)
97+
Assert.Ignore("SQLite has no length limited string type.");
98+
using var s = OpenSession();
99+
using var t = s.BeginTransaction();
100+
var entity = new CultureInfoClass { BasicCulture = CultureInfo.GetCultureInfo("en-US-posix") };
101+
await (s.SaveAsync(entity));
102+
Assert.That(t.Commit, Throws.Exception);
103+
}
104+
}
105+
}

src/NHibernate.Test/Async/TypesTest/DateTimeOffsetTypeFixture.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,6 @@ protected override void OnSetUp()
6969
}
7070
}
7171

72-
protected override void OnTearDown()
73-
{
74-
base.OnTearDown();
75-
76-
using (var s = OpenSession())
77-
using (var t = s.BeginTransaction())
78-
{
79-
s.CreateQuery("delete from DateTimeOffsetClass").ExecuteUpdate();
80-
t.Commit();
81-
}
82-
}
83-
8472
protected override void DropSchema()
8573
{
8674
(Sfi.ConnectionProvider.Driver as ClientDriverWithParamsStats)?.CleanUp();
@@ -354,6 +342,14 @@ public class DateTimeOffsetTypeWithScaleFixtureAsync : DateTimeOffsetTypeFixture
354342
// The timestamp rounding in seeding does not account scale.
355343
protected override bool RevisionCheck => false;
356344

345+
protected override void OnTearDown()
346+
{
347+
using var s = OpenSession();
348+
using var t = s.BeginTransaction();
349+
s.CreateQuery("delete DateTimeOffsetClass").ExecuteUpdate();
350+
t.Commit();
351+
}
352+
357353
[Test]
358354
public async Task LowerDigitsAreIgnoredAsync()
359355
{

src/NHibernate.Test/Async/TypesTest/DecimalTypeFixture.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ protected override void OnSetUp()
5454
}
5555
}
5656

57-
protected override void OnTearDown()
58-
{
59-
base.OnTearDown();
60-
61-
using (var s = OpenSession())
62-
using (var t = s.BeginTransaction())
63-
{
64-
s.CreateQuery("delete from DecimalClass").ExecuteUpdate();
65-
t.Commit();
66-
}
67-
}
68-
6957
[Test]
7058
public async Task ReadWriteAsync()
7159
{

src/NHibernate.Test/Async/TypesTest/EnumStringTypeFixture.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ protected override void OnSetUp()
4040
s.Close();
4141
}
4242

43-
protected override void OnTearDown()
44-
{
45-
ISession s = OpenSession();
46-
s.Delete("from EnumStringClass");
47-
s.Flush();
48-
s.Close();
49-
}
50-
5143
[Test]
5244
public async Task ReadFromLoadAsync()
5345
{

src/NHibernate.Test/Async/TypesTest/GenericEnumStringTypeFixture.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ protected override void OnSetUp()
4242
s.Close();
4343
}
4444

45-
protected override void OnTearDown()
46-
{
47-
ISession s = OpenSession();
48-
s.Delete("from GenericEnumStringClass");
49-
s.Flush();
50-
s.Close();
51-
}
52-
5345
[Test]
5446
public async Task ReadFromLoadAsync()
5547
{

src/NHibernate.Test/Async/TypesTest/StringTypeFixture.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ protected override string TypeName
2626
get { return "String"; }
2727
}
2828

29-
protected override void OnTearDown()
30-
{
31-
using (var s = OpenSession())
32-
{
33-
s.CreateQuery("delete from StringClass").ExecuteUpdate();
34-
}
35-
}
36-
3729
[Test]
3830
public async Task InsertNullValueAsync()
3931
{

src/NHibernate.Test/Async/TypesTest/TimeAsTimeSpanTypeFixture.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ protected override string TypeName
5050
get { return "TimeAsTimeSpan"; }
5151
}
5252

53-
protected override void OnTearDown()
54-
{
55-
base.OnTearDown();
56-
57-
using (var s = OpenSession())
58-
using (var tx = s.BeginTransaction())
59-
{
60-
s.CreateQuery("delete from TimeAsTimeSpanClass").ExecuteUpdate();
61-
tx.Commit();
62-
}
63-
}
64-
6553
[Test]
6654
public async Task SavingAndRetrievingAsync()
6755
{

src/NHibernate.Test/TypesTest/AbstractDateTimeTypeFixture.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,10 @@ protected override void OnSetUp()
5757

5858
protected override void OnTearDown()
5959
{
60-
base.OnTearDown();
61-
62-
using (var s = OpenSession())
63-
using (var t = s.BeginTransaction())
64-
{
65-
s.CreateQuery("delete from DateTimeClass").ExecuteUpdate();
66-
t.Commit();
67-
}
60+
using var s = OpenSession();
61+
using var t = s.BeginTransaction();
62+
s.CreateQuery("delete from DateTimeClass").ExecuteUpdate();
63+
t.Commit();
6864
}
6965

7066
protected override void DropSchema()

0 commit comments

Comments
 (0)