-
Notifications
You must be signed in to change notification settings - Fork 934
Support an arbitrary length for CultureInfoType #3481
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e785755
Support an arbitrary length for CultureInfoType
fredericDelaporte eba0e65
Generate async files
github-actions[bot] b0046cc
Add a dedicated test for CultureInfoType
fredericDelaporte 104f437
Fix test failure on culture casing
fredericDelaporte 6a998c6
Merge branch 'master' into GH3473
fredericDelaporte 6d6eb28
Update documentation about CultureInfoType
fredericDelaporte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/NHibernate.Test/Async/TypesTest/CultureInfoTypeFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using System.Globalization; | ||
using NHibernate.Dialect; | ||
using NHibernate.Type; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.TypesTest | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class CultureInfoTypeFixtureAsync : TypeFixtureBase | ||
{ | ||
protected override string TypeName => "CultureInfo"; | ||
|
||
[Test] | ||
public async Task ReadWriteBasicCultureAsync() | ||
{ | ||
Guid id; | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = new CultureInfoClass { BasicCulture = CultureInfo.GetCultureInfo("en-US") }; | ||
await (s.SaveAsync(entity)); | ||
id = entity.Id; | ||
await (t.CommitAsync()); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = await (s.GetAsync<CultureInfoClass>(id)); | ||
Assert.That(entity.BasicCulture, Is.Not.Null); | ||
Assert.That(entity.BasicCulture.Name, Is.EqualTo("en-US")); | ||
Assert.That(entity.BasicCulture, Is.EqualTo(CultureInfo.GetCultureInfo("en-US"))); | ||
entity.BasicCulture = CultureInfo.GetCultureInfo("fr-BE"); | ||
await (t.CommitAsync()); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = await (s.GetAsync<CultureInfoClass>(id)); | ||
Assert.That(entity.BasicCulture.Name, Is.EqualTo("fr-BE")); | ||
Assert.That(entity.BasicCulture, Is.EqualTo(CultureInfo.GetCultureInfo("fr-BE"))); | ||
entity.BasicCulture = null; | ||
await (t.CommitAsync()); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = await (s.GetAsync<CultureInfoClass>(id)); | ||
Assert.That(entity.BasicCulture, Is.Null); | ||
await (t.CommitAsync()); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ReadWriteExtendedCultureAsync() | ||
{ | ||
Guid id; | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = new CultureInfoClass { ExtendedCulture = CultureInfo.GetCultureInfo("en-US-posix") }; | ||
await (s.SaveAsync(entity)); | ||
id = entity.Id; | ||
await (t.CommitAsync()); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = await (s.GetAsync<CultureInfoClass>(id)); | ||
Assert.That(entity.ExtendedCulture, Is.Not.Null); | ||
// Under Windows, it is named en-US-posix, but en-US-POSIX under Linux. | ||
Assert.That(entity.ExtendedCulture.Name, Is.EqualTo("en-US-posix").IgnoreCase); | ||
Assert.That(entity.ExtendedCulture, Is.EqualTo(CultureInfo.GetCultureInfo("en-US-posix"))); | ||
await (t.CommitAsync()); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task WriteTooLongCultureAsync() | ||
{ | ||
if (Dialect is SQLiteDialect) | ||
Assert.Ignore("SQLite has no length limited string type."); | ||
using var s = OpenSession(); | ||
using var t = s.BeginTransaction(); | ||
var entity = new CultureInfoClass { BasicCulture = CultureInfo.GetCultureInfo("en-US-posix") }; | ||
await (s.SaveAsync(entity)); | ||
Assert.That(t.Commit, Throws.Exception); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace NHibernate.Test.TypesTest | ||
{ | ||
public class CultureInfoClass | ||
{ | ||
public Guid Id { get; set; } | ||
public CultureInfo BasicCulture { get; set; } | ||
public CultureInfo ExtendedCulture { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"> | ||
<class name="NHibernate.Test.TypesTest.CultureInfoClass, NHibernate.Test" table="nh_ci"> | ||
<id name="Id" generator="guid.comb" /> | ||
|
||
<property name="BasicCulture" /> | ||
<property name="ExtendedCulture" length="11" /> | ||
</class> | ||
</hibernate-mapping> |
102 changes: 102 additions & 0 deletions
102
src/NHibernate.Test/TypesTest/CultureInfoTypeFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System; | ||
using System.Globalization; | ||
using NHibernate.Dialect; | ||
using NHibernate.Type; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.TypesTest | ||
{ | ||
[TestFixture] | ||
public class CultureInfoTypeFixture : TypeFixtureBase | ||
{ | ||
protected override string TypeName => "CultureInfo"; | ||
|
||
[Test] | ||
public void ReadWriteBasicCulture() | ||
{ | ||
Guid id; | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = new CultureInfoClass { BasicCulture = CultureInfo.GetCultureInfo("en-US") }; | ||
s.Save(entity); | ||
id = entity.Id; | ||
t.Commit(); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = s.Get<CultureInfoClass>(id); | ||
Assert.That(entity.BasicCulture, Is.Not.Null); | ||
Assert.That(entity.BasicCulture.Name, Is.EqualTo("en-US")); | ||
Assert.That(entity.BasicCulture, Is.EqualTo(CultureInfo.GetCultureInfo("en-US"))); | ||
entity.BasicCulture = CultureInfo.GetCultureInfo("fr-BE"); | ||
t.Commit(); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = s.Get<CultureInfoClass>(id); | ||
Assert.That(entity.BasicCulture.Name, Is.EqualTo("fr-BE")); | ||
Assert.That(entity.BasicCulture, Is.EqualTo(CultureInfo.GetCultureInfo("fr-BE"))); | ||
entity.BasicCulture = null; | ||
t.Commit(); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = s.Get<CultureInfoClass>(id); | ||
Assert.That(entity.BasicCulture, Is.Null); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ReadWriteExtendedCulture() | ||
{ | ||
Guid id; | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = new CultureInfoClass { ExtendedCulture = CultureInfo.GetCultureInfo("en-US-posix") }; | ||
s.Save(entity); | ||
id = entity.Id; | ||
t.Commit(); | ||
} | ||
|
||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
var entity = s.Get<CultureInfoClass>(id); | ||
Assert.That(entity.ExtendedCulture, Is.Not.Null); | ||
// Under Windows, it is named en-US-posix, but en-US-POSIX under Linux. | ||
Assert.That(entity.ExtendedCulture.Name, Is.EqualTo("en-US-posix").IgnoreCase); | ||
Assert.That(entity.ExtendedCulture, Is.EqualTo(CultureInfo.GetCultureInfo("en-US-posix"))); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void WriteTooLongCulture() | ||
{ | ||
if (Dialect is SQLiteDialect) | ||
Assert.Ignore("SQLite has no length limited string type."); | ||
using var s = OpenSession(); | ||
using var t = s.BeginTransaction(); | ||
var entity = new CultureInfoClass { BasicCulture = CultureInfo.GetCultureInfo("en-US-posix") }; | ||
s.Save(entity); | ||
Assert.That(t.Commit, Throws.Exception); | ||
} | ||
|
||
[Test] | ||
public void AutoDiscoverFromNetType() | ||
{ | ||
// integration test to be 100% sure | ||
var propertyType = Sfi.GetEntityPersister(typeof(CultureInfoClass).FullName).GetPropertyType(nameof(CultureInfoClass.BasicCulture)); | ||
Assert.That(propertyType, Is.InstanceOf<CultureInfoType>()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.