@@ -277,8 +277,114 @@ public void TestDictionaryDatabaseObjectSerializationDeserialization()
277277 VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . TableDefinition , _databaseTable . TableDefinition , "FirstName" ) ;
278278 }
279279
280- private void InitializeObjects ( )
280+ /// <summary>
281+ /// Validates serialization and deserialization of Dictionary containing DatabaseTable
282+ /// The table will have dollar sign prefix ($) in the column name
283+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
284+ /// </summary>
285+ [ TestMethod ]
286+ public void TestDictionaryDatabaseObjectSerializationDeserialization_WithDollarColumn ( )
287+ {
288+ InitializeObjects ( generateDollaredColumn : true ) ;
289+
290+ _options = new ( )
291+ {
292+ Converters = {
293+ new DatabaseObjectConverter ( ) ,
294+ new TypeConverter ( )
295+ } ,
296+ ReferenceHandler = ReferenceHandler . Preserve
297+ } ;
298+
299+ Dictionary < string , DatabaseObject > dict = new ( ) { { "person" , _databaseTable } } ;
300+
301+ string serializedDict = JsonSerializer . Serialize ( dict , _options ) ;
302+ // Assert that the serialized JSON contains the escaped dollar sign in column name
303+ Assert . IsTrue ( serializedDict . Contains ( "DAB_ESCAPE$FirstName" ) ,
304+ "Serialized JSON should contain the dollar-prefixed column name in SourceDefinition's Columns." ) ;
305+
306+ Dictionary < string , DatabaseObject > deserializedDict = JsonSerializer . Deserialize < Dictionary < string , DatabaseObject > > ( serializedDict , _options ) ! ;
307+ DatabaseTable deserializedDatabaseTable = ( DatabaseTable ) deserializedDict [ "person" ] ;
308+
309+ Assert . AreEqual ( deserializedDatabaseTable . SourceType , _databaseTable . SourceType ) ;
310+ Assert . AreEqual ( deserializedDatabaseTable . FullName , _databaseTable . FullName ) ;
311+ deserializedDatabaseTable . Equals ( _databaseTable ) ;
312+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . SourceDefinition , _databaseTable . SourceDefinition , "$FirstName" ) ;
313+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . TableDefinition , _databaseTable . TableDefinition , "$FirstName" ) ;
314+ }
315+
316+ /// <summary>
317+ /// Validates serialization and deserialization of Dictionary containing DatabaseView
318+ /// The table will have dollar sign prefix ($) in the column name
319+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
320+ /// </summary>
321+ [ TestMethod ]
322+ public void TestDatabaseViewSerializationDeserialization_WithDollarColumn ( )
323+ {
324+ InitializeObjects ( generateDollaredColumn : true ) ;
325+
326+ TestTypeNameChanges ( _databaseView , "DatabaseView" ) ;
327+
328+ Dictionary < string , DatabaseObject > dict = new ( ) ;
329+ dict . Add ( "person" , _databaseView ) ;
330+
331+ // Test to catch if there is change in number of properties/fields
332+ // Note: On Addition of property make sure it is added in following object creation _databaseView and include in serialization
333+ // and deserialization test.
334+ int fields = typeof ( DatabaseView ) . GetProperties ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) . Length ;
335+ Assert . AreEqual ( fields , 6 ) ;
336+
337+ string serializedDatabaseView = JsonSerializer . Serialize ( dict , _options ) ;
338+ // Assert that the serialized JSON contains the escaped dollar sign in column name
339+ Assert . IsTrue ( serializedDatabaseView . Contains ( "DAB_ESCAPE$FirstName" ) ,
340+ "Serialized JSON should contain the dollar-prefixed column name in SourceDefinition's Columns." ) ;
341+ Dictionary < string , DatabaseObject > deserializedDict = JsonSerializer . Deserialize < Dictionary < string , DatabaseObject > > ( serializedDatabaseView , _options ) ! ;
342+
343+ DatabaseView deserializedDatabaseView = ( DatabaseView ) deserializedDict [ "person" ] ;
344+
345+ Assert . AreEqual ( deserializedDatabaseView . SourceType , _databaseView . SourceType ) ;
346+ deserializedDatabaseView . Equals ( _databaseView ) ;
347+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseView . SourceDefinition , _databaseView . SourceDefinition , "$FirstName" ) ;
348+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseView . ViewDefinition , _databaseView . ViewDefinition , "$FirstName" ) ;
349+ }
350+
351+ /// <summary>
352+ /// Validates serialization and deserialization of Dictionary containing DatabaseStoredProcedure
353+ /// The table will have dollar sign prefix ($) in the column name
354+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
355+ /// </summary>
356+ [ TestMethod ]
357+ public void TestDatabaseStoredProcedureSerializationDeserialization_WithDollarColumn ( )
281358 {
359+ InitializeObjects ( generateDollaredColumn : true ) ;
360+
361+ TestTypeNameChanges ( _databaseStoredProcedure , "DatabaseStoredProcedure" ) ;
362+
363+ Dictionary < string , DatabaseObject > dict = new ( ) ;
364+ dict . Add ( "person" , _databaseStoredProcedure ) ;
365+
366+ // Test to catch if there is change in number of properties/fields
367+ // Note: On Addition of property make sure it is added in following object creation _databaseStoredProcedure and include in serialization
368+ // and deserialization test.
369+ int fields = typeof ( DatabaseStoredProcedure ) . GetProperties ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) . Length ;
370+ Assert . AreEqual ( fields , 6 ) ;
371+
372+ string serializedDatabaseSP = JsonSerializer . Serialize ( dict , _options ) ;
373+ // Assert that the serialized JSON contains the escaped dollar sign in column name
374+ Assert . IsTrue ( serializedDatabaseSP . Contains ( "DAB_ESCAPE$FirstName" ) ,
375+ "Serialized JSON should contain the dollar-prefixed column name in SourceDefinition's Columns." ) ;
376+ Dictionary < string , DatabaseObject > deserializedDict = JsonSerializer . Deserialize < Dictionary < string , DatabaseObject > > ( serializedDatabaseSP , _options ) ! ;
377+ DatabaseStoredProcedure deserializedDatabaseSP = ( DatabaseStoredProcedure ) deserializedDict [ "person" ] ;
378+
379+ Assert . AreEqual ( deserializedDatabaseSP . SourceType , _databaseStoredProcedure . SourceType ) ;
380+ deserializedDatabaseSP . Equals ( _databaseStoredProcedure ) ;
381+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseSP . SourceDefinition , _databaseStoredProcedure . SourceDefinition , "$FirstName" , true ) ;
382+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseSP . StoredProcedureDefinition , _databaseStoredProcedure . StoredProcedureDefinition , "$FirstName" , true ) ;
383+ }
384+
385+ private void InitializeObjects ( bool generateDollaredColumn = false )
386+ {
387+ string columnName = generateDollaredColumn ? "$FirstName" : "FirstName" ;
282388 _options = new ( )
283389 {
284390 // ObjectConverter behavior different in .NET8 most likely due to
@@ -290,10 +396,11 @@ private void InitializeObjects()
290396 new DatabaseObjectConverter ( ) ,
291397 new TypeConverter ( )
292398 }
399+
293400 } ;
294401
295402 _columnDefinition = GetColumnDefinition ( typeof ( string ) , DbType . String , true , false , false , new string ( "John" ) , false ) ;
296- _sourceDefinition = GetSourceDefinition ( false , false , new List < string > ( ) { "FirstName" } , _columnDefinition ) ;
403+ _sourceDefinition = GetSourceDefinition ( false , false , new List < string > ( ) { columnName } , _columnDefinition ) ;
297404
298405 _databaseTable = new DatabaseTable ( )
299406 {
@@ -312,10 +419,10 @@ private void InitializeObjects()
312419 {
313420 IsInsertDMLTriggerEnabled = false ,
314421 IsUpdateDMLTriggerEnabled = false ,
315- PrimaryKey = new List < string > ( ) { "FirstName" } ,
422+ PrimaryKey = new List < string > ( ) { columnName } ,
316423 } ,
317424 } ;
318- _databaseView . ViewDefinition . Columns . Add ( "FirstName" , _columnDefinition ) ;
425+ _databaseView . ViewDefinition . Columns . Add ( columnName , _columnDefinition ) ;
319426
320427 _parameterDefinition = new ( )
321428 {
@@ -332,10 +439,10 @@ private void InitializeObjects()
332439 SourceType = EntitySourceType . StoredProcedure ,
333440 StoredProcedureDefinition = new ( )
334441 {
335- PrimaryKey = new List < string > ( ) { "FirstName" } ,
442+ PrimaryKey = new List < string > ( ) { columnName } ,
336443 }
337444 } ;
338- _databaseStoredProcedure . StoredProcedureDefinition . Columns . Add ( "FirstName" , _columnDefinition ) ;
445+ _databaseStoredProcedure . StoredProcedureDefinition . Columns . Add ( columnName , _columnDefinition ) ;
339446 _databaseStoredProcedure . StoredProcedureDefinition . Parameters . Add ( "Id" , _parameterDefinition ) ;
340447 }
341448
0 commit comments