|
1 | | -//------------------------------------------------------------------------------ |
| 1 | +//------------------------------------------------------------------------------ |
2 | 2 | // <auto-generated> |
3 | 3 | // This code was generated by AsyncGenerator. |
4 | 4 | // |
|
16 | 16 | using NHibernate.SqlTypes; |
17 | 17 | using NUnit.Framework; |
18 | 18 |
|
19 | | -namespace NHibernate.Test.NHSpecificTest.GH3530 |
| 19 | +namespace NHibernate.Test.NHSpecificTest.GH3530; |
| 20 | +using System.Threading.Tasks; |
| 21 | +using System.Threading; |
| 22 | + |
| 23 | +[TestFixture] |
| 24 | +public class FixtureAsync : BugTestCase |
20 | 25 | { |
21 | | - using System.Threading.Tasks; |
22 | | - using System.Threading; |
23 | | - [TestFixture] |
24 | | - public class FixtureAsync : BugTestCase |
25 | | - { |
26 | | - private CultureInfo initialCulture; |
| 26 | + private CultureInfo initialCulture; |
27 | 27 |
|
28 | | - [OneTimeSetUp] |
29 | | - public void FixtureSetup() |
30 | | - { |
31 | | - initialCulture = CurrentCulture; |
32 | | - } |
| 28 | + [OneTimeSetUp] |
| 29 | + public void FixtureSetup() |
| 30 | + { |
| 31 | + initialCulture = CurrentCulture; |
| 32 | + } |
33 | 33 |
|
34 | | - [OneTimeTearDown] |
35 | | - public void FixtureTearDown() |
36 | | - { |
37 | | - CurrentCulture = initialCulture; |
38 | | - } |
| 34 | + [OneTimeTearDown] |
| 35 | + public void FixtureTearDown() |
| 36 | + { |
| 37 | + CurrentCulture = initialCulture; |
| 38 | + } |
39 | 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(); |
| 40 | + protected override void OnTearDown() |
| 41 | + { |
| 42 | + using var session = OpenSession(); |
| 43 | + using var transaction = session.BeginTransaction(); |
46 | 44 |
|
47 | | - transaction.Commit(); |
48 | | - } |
49 | | - } |
| 45 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
50 | 46 |
|
51 | | - protected override void CreateSchema() |
52 | | - { |
53 | | - CreateTable("Integer"); |
54 | | - CreateTable("DateTime"); |
55 | | - CreateTable("Double"); |
56 | | - CreateTable("Decimal"); |
| 47 | + transaction.Commit(); |
| 48 | + } |
57 | 49 |
|
58 | | - base.CreateSchema(); |
59 | | - } |
| 50 | + protected override void CreateSchema() |
| 51 | + { |
| 52 | + CreateTable("Integer"); |
| 53 | + CreateTable("DateTime"); |
| 54 | + CreateTable("Double"); |
| 55 | + CreateTable("Decimal"); |
60 | 56 |
|
61 | | - /// <summary> |
62 | | - /// This function creates the schema for our custom entities. |
63 | | - /// If the SchemaExporter provided a mechanism to override the database |
64 | | - /// type, this method would not be required. |
65 | | - /// </summary> |
66 | | - /// <param name="name"></param> |
67 | | - private void CreateTable(string name) |
68 | | - { |
69 | | - var sb = new StringBuilder(); |
70 | | - var guidType = Dialect.GetTypeName(SqlTypeFactory.Guid); |
71 | | - var stringType = Dialect.GetTypeName(SqlTypeFactory.GetAnsiString(255)); |
| 57 | + base.CreateSchema(); |
| 58 | + } |
72 | 59 |
|
73 | | - var catalog = GetQuotedDefaultCatalog(); |
74 | | - var schema = GetQuotedDefaultSchema(); |
75 | | - var table = GetQualifiedName(catalog, schema, $"{name}Entity"); |
| 60 | + /// <summary> |
| 61 | + /// This function creates the schema for our custom entities. |
| 62 | + /// If the SchemaExporter provided a mechanism to override the database |
| 63 | + /// type, this method would not be required. |
| 64 | + /// </summary> |
| 65 | + /// <param name="name"></param> |
| 66 | + private void CreateTable(string name) |
| 67 | + { |
| 68 | + var sb = new StringBuilder(); |
| 69 | + var guidType = Dialect.GetTypeName(SqlTypeFactory.Guid); |
| 70 | + var stringType = Dialect.GetTypeName(SqlTypeFactory.GetAnsiString(255)); |
76 | 71 |
|
77 | | - sb.Append($"{Dialect.CreateTableString} {table} ("); |
| 72 | + var catalog = GetQuotedDefaultCatalog(); |
| 73 | + var schema = GetQuotedDefaultSchema(); |
| 74 | + var table = GetQualifiedName(catalog, schema, $"{name}Entity"); |
78 | 75 |
|
79 | | - // Generate columns |
80 | | - sb.Append($"Id {guidType}, "); |
81 | | - sb.Append($"DataValue {stringType}"); |
| 76 | + sb.Append($"{Dialect.CreateTableString} {table} ("); |
82 | 77 |
|
83 | | - // Add the primary key contraint for the identity column |
84 | | - sb.Append($", {Dialect.PrimaryKeyString} ( Id )"); |
85 | | - sb.Append(")"); |
| 78 | + // Generate columns |
| 79 | + sb.Append($"Id {guidType}, "); |
| 80 | + sb.Append($"DataValue {stringType}"); |
86 | 81 |
|
87 | | - using (var cn = Sfi.ConnectionProvider.GetConnection()) |
88 | | - { |
89 | | - try |
90 | | - { |
91 | | - using (var cmd = cn.CreateCommand()) |
92 | | - { |
93 | | - cmd.CommandText = sb.ToString(); |
94 | | - cmd.ExecuteNonQuery(); |
95 | | - } |
96 | | - } |
97 | | - catch (Exception ex) |
98 | | - { |
99 | | - Assert.Warn($"Creating the schema failed, assuming it already exists. {ex}"); |
100 | | - } |
101 | | - finally |
102 | | - { |
103 | | - Sfi.ConnectionProvider.CloseConnection(cn); |
104 | | - } |
105 | | - } |
106 | | - } |
| 82 | + // Add the primary key contraint for the identity column |
| 83 | + sb.Append($", {Dialect.PrimaryKeyString} ( Id )"); |
| 84 | + sb.Append(')'); |
107 | 85 |
|
108 | | - private string GetQuotedDefaultCatalog() |
| 86 | + using var cn = Sfi.ConnectionProvider.GetConnection(); |
| 87 | + try |
109 | 88 | { |
110 | | - var t = cfg.GetType(); |
111 | | - var getQuotedDefaultCatalog = t.GetMethod("GetQuotedDefaultCatalog", BindingFlags.Instance | BindingFlags.NonPublic); |
| 89 | + using var cmd = cn.CreateCommand(); |
112 | 90 |
|
113 | | - return (string) getQuotedDefaultCatalog.Invoke(cfg, [Dialect]); |
| 91 | + cmd.CommandText = sb.ToString(); |
| 92 | + cmd.ExecuteNonQuery(); |
114 | 93 | } |
115 | | - |
116 | | - private string GetQuotedDefaultSchema() |
| 94 | + catch (Exception ex) |
117 | 95 | { |
118 | | - var t = cfg.GetType(); |
119 | | - var getQuotedDefaultSchema = t.GetMethod("GetQuotedDefaultSchema", BindingFlags.Instance | BindingFlags.NonPublic); |
120 | | - |
121 | | - return (string) getQuotedDefaultSchema.Invoke(cfg, [Dialect]); |
| 96 | + Assert.Warn($"Creating the schema failed, assuming it already exists. {ex}"); |
122 | 97 | } |
123 | | - |
124 | | - private string GetQualifiedName(string catalog, string schema, string name) |
| 98 | + finally |
125 | 99 | { |
126 | | - return Dialect.Qualify(catalog, schema, name); |
| 100 | + Sfi.ConnectionProvider.CloseConnection(cn); |
127 | 101 | } |
| 102 | + } |
128 | 103 |
|
129 | | - private async Task PerformTestAsync<T, U>(CultureInfo from, CultureInfo to, T expectedValue, Action<T, T> assert, CancellationToken cancellationToken = default(CancellationToken)) |
130 | | - where T : struct |
131 | | - where U : DataEntity<T>, new() |
132 | | - { |
133 | | - object id; |
| 104 | + private string GetQuotedDefaultCatalog() |
| 105 | + { |
| 106 | + var t = cfg.GetType(); |
| 107 | + var getQuotedDefaultCatalog = t.GetMethod("GetQuotedDefaultCatalog", BindingFlags.Instance | BindingFlags.NonPublic); |
134 | 108 |
|
135 | | - CurrentCulture = from; |
136 | | - using (var session = OpenSession()) |
137 | | - using (var tx = session.BeginTransaction()) |
138 | | - { |
139 | | - var entity = new U() |
140 | | - { |
141 | | - DataValue = expectedValue |
142 | | - }; |
143 | | - |
144 | | - id = await (session.SaveAsync(entity, cancellationToken)); |
145 | | - await (tx.CommitAsync(cancellationToken)); |
146 | | - } |
147 | | - |
148 | | - CurrentCulture = to; |
149 | | - using (var session = OpenSession()) |
150 | | - using (var tx = session.BeginTransaction()) |
151 | | - { |
152 | | - var entity = await (session.GetAsync<U>(id, cancellationToken)); |
| 109 | + return (string) getQuotedDefaultCatalog.Invoke(cfg, [Dialect]); |
| 110 | + } |
153 | 111 |
|
154 | | - assert(expectedValue, entity.DataValue); |
155 | | - } |
156 | | - } |
| 112 | + private string GetQuotedDefaultSchema() |
| 113 | + { |
| 114 | + var t = cfg.GetType(); |
| 115 | + var getQuotedDefaultSchema = t.GetMethod("GetQuotedDefaultSchema", BindingFlags.Instance | BindingFlags.NonPublic); |
157 | 116 |
|
158 | | - [Test, TestCaseSource(nameof(GetTestCases))] |
159 | | - public async Task TestNHDateTimeAsync(CultureInfo from, CultureInfo to) |
160 | | - { |
161 | | - DateTime leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish)); |
| 117 | + return (string) getQuotedDefaultSchema.Invoke(cfg, [Dialect]); |
| 118 | + } |
162 | 119 |
|
163 | | - await (PerformTestAsync<DateTime, NHDateTimeEntity>(from, to, leapDay, (expected, actual) => Assert.AreEqual(expected, actual))); |
164 | | - } |
| 120 | + private string GetQualifiedName(string catalog, string schema, string name) |
| 121 | + { |
| 122 | + return Dialect.Qualify(catalog, schema, name); |
| 123 | + } |
165 | 124 |
|
166 | | - [Test, TestCaseSource(nameof(GetTestCases))] |
167 | | - public async Task TestDateTimeAsync(CultureInfo from, CultureInfo to) |
| 125 | + private async Task PerformTestAsync<T, U>(CultureInfo from, CultureInfo to, T expectedValue, Action<T, T> assert, CancellationToken cancellationToken = default(CancellationToken)) |
| 126 | + where T : struct |
| 127 | + where U : DataEntity<T>, new() |
| 128 | + { |
| 129 | + object id; |
| 130 | + |
| 131 | + CurrentCulture = from; |
| 132 | + using (var session = OpenSession()) |
| 133 | + using (var tx = session.BeginTransaction()) |
168 | 134 | { |
169 | | - DateTime leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish)); |
| 135 | + var entity = new U() |
| 136 | + { |
| 137 | + DataValue = expectedValue |
| 138 | + }; |
170 | 139 |
|
171 | | - await (PerformTestAsync<DateTime, DateTimeEntity>(from, to, leapDay, (expected, actual) => Assert.AreEqual(expected, actual))); |
| 140 | + id = await (session.SaveAsync(entity, cancellationToken)); |
| 141 | + await (tx.CommitAsync(cancellationToken)); |
172 | 142 | } |
173 | 143 |
|
174 | | - [Test, TestCaseSource(nameof(GetTestCases))] |
175 | | - public async Task TestDecimalAsync(CultureInfo from, CultureInfo to) |
| 144 | + CurrentCulture = to; |
| 145 | + using (var session = OpenSession()) |
| 146 | + using (var tx = session.BeginTransaction()) |
176 | 147 | { |
177 | | - decimal decimalValue = 12.3m; |
| 148 | + var entity = await (session.GetAsync<U>(id, cancellationToken)); |
178 | 149 |
|
179 | | - await (PerformTestAsync<decimal, DecimalEntity>(from, to, decimalValue, (expected, actual) => Assert.AreEqual(expected, actual))); |
| 150 | + assert(expectedValue, entity.DataValue); |
180 | 151 | } |
| 152 | + } |
181 | 153 |
|
182 | | - [Test, TestCaseSource(nameof(GetTestCases))] |
183 | | - public async Task TestDoubleAsync(CultureInfo from, CultureInfo to) |
184 | | - { |
185 | | - double doubleValue = 12.3d; |
| 154 | + [Test, TestCaseSource(nameof(GetTestCases))] |
| 155 | + public async Task TestNHDateTimeAsync(CultureInfo from, CultureInfo to) |
| 156 | + { |
| 157 | + var leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish)); |
186 | 158 |
|
187 | | - await (PerformTestAsync<double, DoubleEntity>(from, to, doubleValue, |
188 | | - (expected, actual) => Assert.True(Math.Abs(expected - actual) < double.Epsilon, $"Expected: {expected}\nBut was: {actual}\n") |
189 | | - )); |
190 | | - } |
| 159 | + await (PerformTestAsync<DateTime, NHDateTimeEntity>(from, to, leapDay, (expected, actual) => Assert.AreEqual(expected, actual))); |
| 160 | + } |
191 | 161 |
|
192 | | - [Test, TestCaseSource(nameof(GetTestCases))] |
| 162 | + [Test, TestCaseSource(nameof(GetTestCases))] |
| 163 | + public async Task TestDateTimeAsync(CultureInfo from, CultureInfo to) |
| 164 | + { |
| 165 | + var leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish)); |
193 | 166 |
|
194 | | - public async Task TestIntegerAsync(CultureInfo from, CultureInfo to) |
195 | | - { |
196 | | - int integerValue = 123; |
| 167 | + await (PerformTestAsync<DateTime, DateTimeEntity>(from, to, leapDay, (expected, actual) => Assert.AreEqual(expected, actual))); |
| 168 | + } |
197 | 169 |
|
198 | | - await (PerformTestAsync<int, IntegerEntity>(from, to, integerValue, (expected, actual) => Assert.AreEqual(expected, actual))); |
199 | | - } |
| 170 | + [Test, TestCaseSource(nameof(GetTestCases))] |
| 171 | + public async Task TestDecimalAsync(CultureInfo from, CultureInfo to) |
| 172 | + { |
| 173 | + decimal decimalValue = 12.3m; |
200 | 174 |
|
201 | | - private CultureInfo CurrentCulture |
202 | | - { |
203 | | - get => CultureInfo.CurrentCulture; |
204 | | - set => CultureInfo.CurrentCulture = value; |
205 | | - } |
| 175 | + await (PerformTestAsync<decimal, DecimalEntity>(from, to, decimalValue, (expected, actual) => Assert.AreEqual(expected, actual))); |
| 176 | + } |
206 | 177 |
|
207 | | - public static object[][] GetTestCases() |
208 | | - { |
209 | | - return [ |
210 | | - [new CultureInfo("en-US"), new CultureInfo("de-DE")], |
211 | | - [new CultureInfo("en-US"), new CultureInfo("ar-SA", false)], |
212 | | - [new CultureInfo("en-US"), new CultureInfo("th-TH", false)], |
213 | | - ]; |
214 | | - } |
| 178 | + [Test, TestCaseSource(nameof(GetTestCases))] |
| 179 | + public async Task TestDoubleAsync(CultureInfo from, CultureInfo to) |
| 180 | + { |
| 181 | + double doubleValue = 12.3d; |
| 182 | + |
| 183 | + await (PerformTestAsync<double, DoubleEntity>(from, to, doubleValue, |
| 184 | + (expected, actual) => Assert.True(Math.Abs(expected - actual) < double.Epsilon, $"Expected: {expected}\nBut was: {actual}\n") |
| 185 | + )); |
| 186 | + } |
| 187 | + |
| 188 | + [Test, TestCaseSource(nameof(GetTestCases))] |
| 189 | + |
| 190 | + public async Task TestIntegerAsync(CultureInfo from, CultureInfo to) |
| 191 | + { |
| 192 | + int integerValue = 123; |
| 193 | + |
| 194 | + await (PerformTestAsync<int, IntegerEntity>(from, to, integerValue, (expected, actual) => Assert.AreEqual(expected, actual))); |
| 195 | + } |
| 196 | + |
| 197 | + private CultureInfo CurrentCulture |
| 198 | + { |
| 199 | + get => CultureInfo.CurrentCulture; |
| 200 | + set => CultureInfo.CurrentCulture = value; |
| 201 | + } |
| 202 | + |
| 203 | + public static object[][] GetTestCases() |
| 204 | + { |
| 205 | + return [ |
| 206 | + [new CultureInfo("en-US"), new CultureInfo("de-DE")], |
| 207 | + [new CultureInfo("en-US"), new CultureInfo("ar-SA", false)], |
| 208 | + [new CultureInfo("en-US"), new CultureInfo("th-TH", false)], |
| 209 | + ]; |
215 | 210 | } |
216 | 211 | } |
0 commit comments