|
| 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 | +} |
0 commit comments