|
| 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.Collections.Generic; |
| 13 | +using System.Linq; |
| 14 | +using System.Text; |
| 15 | +using System.Threading.Tasks; |
| 16 | +using NUnit.Framework; |
| 17 | +using System.Globalization; |
| 18 | +using System.Threading; |
| 19 | +using System.Web.SessionState; |
| 20 | + |
| 21 | +namespace NHibernate.Test.NHSpecificTest.GH3530 |
| 22 | +{ |
| 23 | + [TestFixture] |
| 24 | + public class FixtureAsync : BugTestCase |
| 25 | + { |
| 26 | + private CultureInfo initialCulture; |
| 27 | + |
| 28 | + [OneTimeSetUp] |
| 29 | + public void FixtureSetup() |
| 30 | + { |
| 31 | + initialCulture = CurrentCulture; |
| 32 | + } |
| 33 | + |
| 34 | + [OneTimeTearDown] |
| 35 | + public void FixtureTearDown() |
| 36 | + { |
| 37 | + CurrentCulture = initialCulture; |
| 38 | + } |
| 39 | + |
| 40 | + protected override void OnTearDown() |
| 41 | + { |
| 42 | + using (var session = OpenSession()) |
| 43 | + using (var transaction = session.BeginTransaction()) |
| 44 | + { |
| 45 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 46 | + |
| 47 | + transaction.Commit(); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + [TestCaseSource(nameof(GenerateAllCultureCombinations))] |
| 52 | + public async Task TestLocalesAsync(CultureInfo from, CultureInfo to) |
| 53 | + { |
| 54 | + DateTime leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish)); |
| 55 | + double doubleValue = 12.3f; |
| 56 | + int intValue = 4; |
| 57 | + object id; |
| 58 | + |
| 59 | + CurrentCulture = from; |
| 60 | + using (var session = OpenSession()) |
| 61 | + using (var tx = session.BeginTransaction()) |
| 62 | + { |
| 63 | + var entity = new LocaleEntity() |
| 64 | + { |
| 65 | + DateTimeValue = leapDay, |
| 66 | + DoubleValue = doubleValue, |
| 67 | + IntegerValue = intValue, |
| 68 | + }; |
| 69 | + |
| 70 | + id = await (session.SaveAsync(entity)); |
| 71 | + await (tx.CommitAsync()); |
| 72 | + } |
| 73 | + |
| 74 | + CurrentCulture = to; |
| 75 | + using (var session = OpenSession()) |
| 76 | + using (var tx = session.BeginTransaction()) |
| 77 | + { |
| 78 | + var entity = await (session.GetAsync<LocaleEntity>(id)); |
| 79 | + |
| 80 | + Assert.AreEqual(leapDay, entity.DateTimeValue); |
| 81 | + Assert.AreEqual(intValue, entity.IntegerValue); |
| 82 | + Assert.True(doubleValue - entity.DoubleValue < double.Epsilon); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + private CultureInfo CurrentCulture |
| 87 | + { |
| 88 | + get |
| 89 | + { |
| 90 | + return Thread.CurrentThread.CurrentCulture; |
| 91 | + } |
| 92 | + set |
| 93 | + { |
| 94 | + Thread.CurrentThread.CurrentCulture = value; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + public static IEnumerable<object> GenerateAllCultureCombinations() |
| 99 | + { |
| 100 | + var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); |
| 101 | + |
| 102 | + for (var i = 0; i < cultures.Length; i++) |
| 103 | + { |
| 104 | + for (var j = 0; j < cultures.Length; j++) |
| 105 | + { |
| 106 | + if (i == j) continue; |
| 107 | + |
| 108 | + yield return new object[] |
| 109 | + { |
| 110 | + cultures[i], |
| 111 | + cultures[j] |
| 112 | + }; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + } |
| 118 | +} |
0 commit comments