File tree Expand file tree Collapse file tree 2 files changed +44
-4
lines changed
FirebirdSql.Data.FirebirdClient.Tests
FirebirdSql.Data.FirebirdClient/Common Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,15 @@ public async Task ReadsValueCorrectly(BigInteger value)
64
64
}
65
65
}
66
66
67
+ [ Test ]
68
+ public Task CanReadAsByte ( ) => CanReadAsTypeHelper < byte > ( 6 , r => r . GetByte ( 0 ) ) ;
69
+ [ Test ]
70
+ public Task CanReadAsInt16 ( ) => CanReadAsTypeHelper < short > ( 6 , r => r . GetInt16 ( 0 ) ) ;
71
+ [ Test ]
72
+ public Task CanReadAsInt32 ( ) => CanReadAsTypeHelper < int > ( 6 , r => r . GetInt32 ( 0 ) ) ;
73
+ [ Test ]
74
+ public Task CanReadAsInt64 ( ) => CanReadAsTypeHelper < long > ( 6 , r => r . GetInt64 ( 0 ) ) ;
75
+
67
76
[ TestCaseSource ( nameof ( TestValues ) ) ]
68
77
public async Task PassesValueCorrectly ( BigInteger value )
69
78
{
@@ -125,4 +134,19 @@ public async Task SimpleSelectSchemaTableTest()
125
134
}
126
135
}
127
136
}
137
+
138
+ async Task CanReadAsTypeHelper < T > ( T value , Func < FbDataReader , T > getter )
139
+ where T : IFormattable
140
+ {
141
+ await using ( var cmd = Connection . CreateCommand ( ) )
142
+ {
143
+ var svalue = value . ToString ( null , CultureInfo . InvariantCulture ) ;
144
+ cmd . CommandText = $ "select cast({ svalue } as int128) from rdb$database";
145
+ await using ( var reader = await cmd . ExecuteReaderAsync ( ) )
146
+ {
147
+ await reader . ReadAsync ( ) ;
148
+ Assert . AreEqual ( value , getter ( reader ) ) ;
149
+ }
150
+ }
151
+ }
128
152
}
Original file line number Diff line number Diff line change @@ -184,22 +184,38 @@ public bool GetBoolean()
184
184
185
185
public byte GetByte ( )
186
186
{
187
- return Convert . ToByte ( _value , CultureInfo . InvariantCulture ) ;
187
+ return _value switch
188
+ {
189
+ BigInteger bi => ( byte ) bi ,
190
+ _ => Convert . ToByte ( _value , CultureInfo . InvariantCulture ) ,
191
+ } ;
188
192
}
189
193
190
194
public short GetInt16 ( )
191
195
{
192
- return Convert . ToInt16 ( _value , CultureInfo . InvariantCulture ) ;
196
+ return _value switch
197
+ {
198
+ BigInteger bi => ( short ) bi ,
199
+ _ => Convert . ToInt16 ( _value , CultureInfo . InvariantCulture ) ,
200
+ } ;
193
201
}
194
202
195
203
public int GetInt32 ( )
196
204
{
197
- return Convert . ToInt32 ( _value , CultureInfo . InvariantCulture ) ;
205
+ return _value switch
206
+ {
207
+ BigInteger bi => ( int ) bi ,
208
+ _ => Convert . ToInt32 ( _value , CultureInfo . InvariantCulture ) ,
209
+ } ;
198
210
}
199
211
200
212
public long GetInt64 ( )
201
213
{
202
- return Convert . ToInt64 ( _value , CultureInfo . InvariantCulture ) ;
214
+ return _value switch
215
+ {
216
+ BigInteger bi => ( long ) bi ,
217
+ _ => Convert . ToInt64 ( _value , CultureInfo . InvariantCulture ) ,
218
+ } ;
203
219
}
204
220
205
221
public decimal GetDecimal ( )
You can’t perform that action at this time.
0 commit comments