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)
6464 }
6565 }
6666
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+
6776 [ TestCaseSource ( nameof ( TestValues ) ) ]
6877 public async Task PassesValueCorrectly ( BigInteger value )
6978 {
@@ -125,4 +134,19 @@ public async Task SimpleSelectSchemaTableTest()
125134 }
126135 }
127136 }
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+ }
128152}
Original file line number Diff line number Diff line change @@ -184,22 +184,38 @@ public bool GetBoolean()
184184
185185 public byte GetByte ( )
186186 {
187- return Convert . ToByte ( _value , CultureInfo . InvariantCulture ) ;
187+ return _value switch
188+ {
189+ BigInteger bi => ( byte ) bi ,
190+ _ => Convert . ToByte ( _value , CultureInfo . InvariantCulture ) ,
191+ } ;
188192 }
189193
190194 public short GetInt16 ( )
191195 {
192- return Convert . ToInt16 ( _value , CultureInfo . InvariantCulture ) ;
196+ return _value switch
197+ {
198+ BigInteger bi => ( short ) bi ,
199+ _ => Convert . ToInt16 ( _value , CultureInfo . InvariantCulture ) ,
200+ } ;
193201 }
194202
195203 public int GetInt32 ( )
196204 {
197- return Convert . ToInt32 ( _value , CultureInfo . InvariantCulture ) ;
205+ return _value switch
206+ {
207+ BigInteger bi => ( int ) bi ,
208+ _ => Convert . ToInt32 ( _value , CultureInfo . InvariantCulture ) ,
209+ } ;
198210 }
199211
200212 public long GetInt64 ( )
201213 {
202- return Convert . ToInt64 ( _value , CultureInfo . InvariantCulture ) ;
214+ return _value switch
215+ {
216+ BigInteger bi => ( long ) bi ,
217+ _ => Convert . ToInt64 ( _value , CultureInfo . InvariantCulture ) ,
218+ } ;
203219 }
204220
205221 public decimal GetDecimal ( )
You can’t perform that action at this time.
0 commit comments