File tree Expand file tree Collapse file tree 3 files changed +64
-2
lines changed
Tests/ksqlDB.RestApi.Client.Tests Expand file tree Collapse file tree 3 files changed +64
-2
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,37 @@ public void Headers()
234
234
235
235
metadata . HasHeaders . Should ( ) . BeTrue ( ) ;
236
236
}
237
+
238
+ private record KeyValuePair
239
+ {
240
+ public string Key { get ; set ; } = null ! ;
241
+ public byte [ ] Value { get ; set ; } = null ! ;
242
+ }
243
+
244
+ private record Record
245
+ {
246
+ public KeyValuePair [ ] Headers { get ; init ; } = null ! ;
247
+ }
248
+
249
+ [ Test ]
250
+ public void AsStruct ( )
251
+ {
252
+ //Arrange
253
+
254
+ //Act
255
+ var fieldTypeBuilder = builder . Entity < Record > ( )
256
+ . Property ( b => b . Headers )
257
+ . AsStruct ( ) ;
258
+
259
+ //Assert
260
+ fieldTypeBuilder . Should ( ) . NotBeNull ( ) ;
261
+
262
+ var entityMetadata = ( ( IMetadataProvider ) builder ) . GetEntities ( ) . FirstOrDefault ( c => c . Type == typeof ( Record ) ) ;
263
+ entityMetadata . Should ( ) . NotBeNull ( ) ;
264
+
265
+ var metadata = entityMetadata ! . FieldsMetadata . First ( c => c . IsStruct && c . Path == "Headers" ) ;
266
+ metadata . IsStruct . Should ( ) . BeTrue ( ) ;
267
+ }
237
268
}
238
269
239
270
internal record Payment
Original file line number Diff line number Diff line change 1
1
using FluentAssertions ;
2
+ using ksqlDb . RestApi . Client . FluentAPI . Builders ;
2
3
using ksqlDB . RestApi . Client . KSql . RestApi . Enums ;
3
4
using ksqlDB . RestApi . Client . KSql . RestApi . Generators ;
4
5
using ksqlDB . RestApi . Client . KSql . RestApi . Serialization ;
@@ -162,6 +163,36 @@ public void CreateOrReplaceTableWithEnumProperty()
162
163
//Assert
163
164
statement . Should ( ) . Contain ( $ "{ nameof ( PortType ) } VARCHAR") ;
164
165
}
166
+ private record KeyValuePair
167
+ {
168
+ public string Key { get ; set ; } = null ! ;
169
+ public byte [ ] Value { get ; set ; } = null ! ;
170
+ }
171
+
172
+ private record Record
173
+ {
174
+ public KeyValuePair [ ] Headers { get ; init ; } = null ! ;
175
+ }
176
+
177
+ [ Test ]
178
+ public void CreateTable_UseModelBuilder_WithFieldAsStruct ( )
179
+ {
180
+ //Arrange
181
+ var modelBuilder = new ModelBuilder ( ) ;
182
+ modelBuilder . Entity < Record > ( )
183
+ . Property ( b => b . Headers )
184
+ . AsStruct ( ) ;
185
+
186
+ var creationMetadata = new EntityCreationMetadata ( "my_topic" , partitions : 3 ) ;
187
+
188
+ //Act
189
+ var statement = new StatementGenerator ( modelBuilder ) . CreateTable < Record > ( creationMetadata , ifNotExists : true ) ;
190
+
191
+ //Assert
192
+ statement . Should ( ) . Be ( @"CREATE TABLE IF NOT EXISTS Records (
193
+ Headers ARRAY<STRUCT<Key VARCHAR, Value BYTES>>
194
+ ) WITH ( KAFKA_TOPIC='my_topic', VALUE_FORMAT='Json', PARTITIONS='3' );" . ReplaceLineEndings ( ) ) ;
195
+ }
165
196
}
166
197
167
198
internal class Port
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ namespace ksqlDb.RestApi.Client.Tests.KSql.RestApi.Statements
12
12
public class KSqlTypeTranslatorTests
13
13
{
14
14
private ModelBuilder modelBuilder = null ! ;
15
- private KSqlTypeTranslator kSqlTypeTranslator = null ! ;
15
+ private KSqlTypeTranslator < Poco > kSqlTypeTranslator = null ! ;
16
16
17
17
[ SetUp ]
18
18
public void Init ( )
@@ -396,7 +396,7 @@ public void Translate_UseModelBuilderConfiguration()
396
396
. Decimal ( 10 , 2 ) ;
397
397
398
398
//Act
399
- string ksqlType = kSqlTypeTranslator . Translate ( type ) ;
399
+ string ksqlType = kSqlTypeTranslator . Translate ( type , type . GetMember ( nameof ( Poco . Amount ) ) [ 0 ] ) ;
400
400
401
401
//Assert
402
402
ksqlType . Should ( ) . Be ( $ "{ KSqlTypes . Struct } <{ nameof ( Poco . Amount ) } { KSqlTypes . Decimal } (10,2)>") ;
You can’t perform that action at this time.
0 commit comments