@@ -277,8 +277,96 @@ public void TestDictionaryDatabaseObjectSerializationDeserialization()
277277 VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . TableDefinition , _databaseTable . TableDefinition , "FirstName" ) ;
278278 }
279279
280- private void InitializeObjects ( )
280+ /// <summary>
281+ /// Validates serialization and deserilization 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+ Dictionary < string , DatabaseObject > deserializedDict = JsonSerializer . Deserialize < Dictionary < string , DatabaseObject > > ( serializedDict , _options ) ! ;
303+
304+ DatabaseTable deserializedDatabaseTable = ( DatabaseTable ) deserializedDict [ "person" ] ;
305+
306+ Assert . AreEqual ( deserializedDatabaseTable . SourceType , _databaseTable . SourceType ) ;
307+ Assert . AreEqual ( deserializedDatabaseTable . FullName , _databaseTable . FullName ) ;
308+ deserializedDatabaseTable . Equals ( _databaseTable ) ;
309+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . SourceDefinition , _databaseTable . SourceDefinition , "$FirstName" ) ;
310+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . TableDefinition , _databaseTable . TableDefinition , "$FirstName" ) ;
311+ }
312+
313+ /// <summary>
314+ /// Validates serialization and deserilization of Dictionary containing DatabaseView
315+ /// The table will have dollar sign prefix ($) in the column name
316+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
317+ /// </summary>
318+ [ TestMethod ]
319+ public void TestDatabaseViewSerializationDeserialization_WithDollarColumn ( )
320+ {
321+ InitializeObjects ( generateDollaredColumn : true ) ;
322+
323+ TestTypeNameChanges ( _databaseView , "DatabaseView" ) ;
324+
325+ // Test to catch if there is change in number of properties/fields
326+ // Note: On Addition of property make sure it is added in following object creation _databaseView and include in serialization
327+ // and deserialization test.
328+ int fields = typeof ( DatabaseView ) . GetProperties ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) . Length ;
329+ Assert . AreEqual ( fields , 6 ) ;
330+
331+ string serializedDatabaseView = JsonSerializer . Serialize ( _databaseView , _options ) ;
332+ DatabaseView deserializedDatabaseView = JsonSerializer . Deserialize < DatabaseView > ( serializedDatabaseView , _options ) ! ;
333+
334+ Assert . AreEqual ( deserializedDatabaseView . SourceType , _databaseView . SourceType ) ;
335+ deserializedDatabaseView . Equals ( _databaseView ) ;
336+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseView . SourceDefinition , _databaseView . SourceDefinition , "$FirstName" ) ;
337+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseView . ViewDefinition , _databaseView . ViewDefinition , "$FirstName" ) ;
338+ }
339+
340+ /// <summary>
341+ /// Validates serialization and deserilization of Dictionary containing DatabaseStoredProcedure
342+ /// The table will have dollar sign prefix ($) in the column name
343+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
344+ /// </summary>
345+ [ TestMethod ]
346+ public void TestDatabaseStoredProcedureSerializationDeserialization_WithDollarColumn ( )
281347 {
348+ InitializeObjects ( generateDollaredColumn : true ) ;
349+
350+ TestTypeNameChanges ( _databaseStoredProcedure , "DatabaseStoredProcedure" ) ;
351+
352+ // Test to catch if there is change in number of properties/fields
353+ // Note: On Addition of property make sure it is added in following object creation _databaseStoredProcedure and include in serialization
354+ // and deserialization test.
355+ int fields = typeof ( DatabaseStoredProcedure ) . GetProperties ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) . Length ;
356+ Assert . AreEqual ( fields , 6 ) ;
357+
358+ string serializedDatabaseSP = JsonSerializer . Serialize ( _databaseStoredProcedure , _options ) ;
359+ DatabaseStoredProcedure deserializedDatabaseSP = JsonSerializer . Deserialize < DatabaseStoredProcedure > ( serializedDatabaseSP , _options ) ! ;
360+
361+ Assert . AreEqual ( deserializedDatabaseSP . SourceType , _databaseStoredProcedure . SourceType ) ;
362+ deserializedDatabaseSP . Equals ( _databaseStoredProcedure ) ;
363+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseSP . SourceDefinition , _databaseStoredProcedure . SourceDefinition , "$FirstName" , true ) ;
364+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseSP . StoredProcedureDefinition , _databaseStoredProcedure . StoredProcedureDefinition , "$FirstName" , true ) ;
365+ }
366+
367+ private void InitializeObjects ( bool generateDollaredColumn = false )
368+ {
369+ string columnName = generateDollaredColumn ? "$FirstName" : "FirstName" ;
282370 _options = new ( )
283371 {
284372 // ObjectConverter behavior different in .NET8 most likely due to
@@ -290,10 +378,11 @@ private void InitializeObjects()
290378 new DatabaseObjectConverter ( ) ,
291379 new TypeConverter ( )
292380 }
381+
293382 } ;
294383
295384 _columnDefinition = GetColumnDefinition ( typeof ( string ) , DbType . String , true , false , false , new string ( "John" ) , false ) ;
296- _sourceDefinition = GetSourceDefinition ( false , false , new List < string > ( ) { "FirstName" } , _columnDefinition ) ;
385+ _sourceDefinition = GetSourceDefinition ( false , false , new List < string > ( ) { columnName } , _columnDefinition ) ;
297386
298387 _databaseTable = new DatabaseTable ( )
299388 {
@@ -312,10 +401,10 @@ private void InitializeObjects()
312401 {
313402 IsInsertDMLTriggerEnabled = false ,
314403 IsUpdateDMLTriggerEnabled = false ,
315- PrimaryKey = new List < string > ( ) { "FirstName" } ,
404+ PrimaryKey = new List < string > ( ) { columnName } ,
316405 } ,
317406 } ;
318- _databaseView . ViewDefinition . Columns . Add ( "FirstName" , _columnDefinition ) ;
407+ _databaseView . ViewDefinition . Columns . Add ( columnName , _columnDefinition ) ;
319408
320409 _parameterDefinition = new ( )
321410 {
@@ -332,10 +421,10 @@ private void InitializeObjects()
332421 SourceType = EntitySourceType . StoredProcedure ,
333422 StoredProcedureDefinition = new ( )
334423 {
335- PrimaryKey = new List < string > ( ) { "FirstName" } ,
424+ PrimaryKey = new List < string > ( ) { columnName } ,
336425 }
337426 } ;
338- _databaseStoredProcedure . StoredProcedureDefinition . Columns . Add ( "FirstName" , _columnDefinition ) ;
427+ _databaseStoredProcedure . StoredProcedureDefinition . Columns . Add ( columnName , _columnDefinition ) ;
339428 _databaseStoredProcedure . StoredProcedureDefinition . Parameters . Add ( "Id" , _parameterDefinition ) ;
340429 }
341430
0 commit comments