@@ -132,7 +132,7 @@ public void EmptyArray()
132132 }
133133
134134 [ Test , Description ( "Verifies that the array type returned from NpgsqlDataReader.GetValue() is always compatible with null values." ) ]
135- public void GetValueArrayTypeForValueTypesDependsOnActualValue ( )
135+ public void GetValueArrayTypeForValueTypesIsNullable ( )
136136 {
137137 using ( var conn = OpenConnection ( ) )
138138 using ( var cmd = new NpgsqlCommand ( @"
@@ -157,6 +157,25 @@ INSERT into GetValueArrayTypeForValueTypesDependsOnActualValue VALUES
157157 }
158158 }
159159
160+ [ Test , Description ( "Verifies that the array type returned from NpgsqlDataReader.GetValue() handles NOT NULL constraints on domains correctly." ) ]
161+ public void GetValueRespectsNotNullConstraintsOnDomainsInArrays ( )
162+ {
163+ using var conn = OpenConnection ( ) ;
164+ conn . ExecuteNonQuery ( "CREATE DOMAIN pg_temp.int_not_null AS integer NOT NULL;" ) ;
165+ conn . ExecuteNonQuery ( "CREATE DOMAIN pg_temp.int_null AS integer;" ) ;
166+ conn . ReloadTypes ( ) ;
167+
168+ using var cmd = new NpgsqlCommand ( @"SELECT '{1,2,3,4}'::pg_temp.int_not_null[], '{1,2,3,4}'::pg_temp.int_null[];" , conn ) ;
169+ var reader = cmd . ExecuteReader ( ) ;
170+ reader . Read ( ) ;
171+ Assert . That ( reader . GetFieldType ( 0 ) , Is . EqualTo ( typeof ( Array ) ) ) ;
172+ Assert . That ( reader . GetValue ( 0 ) , Is . TypeOf < int [ ] > ( ) ) ;
173+ Assert . That ( reader . GetFieldValue < int ? [ ] > ( 0 ) , Is . TypeOf < int ? [ ] > ( ) ) ;
174+
175+ Assert . That ( reader . GetFieldType ( 1 ) , Is . EqualTo ( typeof ( Array ) ) ) ;
176+ Assert . That ( reader . GetValue ( 1 ) , Is . TypeOf < int ? [ ] > ( ) ) ;
177+ Assert . That ( reader . GetFieldValue < int [ ] > ( 1 ) , Is . TypeOf < int [ ] > ( ) ) ;
178+ }
160179
161180 [ Test , Description ( "Verifies that an attempt to read an Array of value types that contains null values as array of a non-nullable type fails." ) ]
162181 public void GetFieldValueNonNullableValueTypeArrayFailsOnArrayContainingNull ( )
0 commit comments