@@ -276,8 +276,96 @@ public void TestDictionaryDatabaseObjectSerializationDeserialization()
276276 VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . TableDefinition , _databaseTable . TableDefinition , "FirstName" ) ;
277277 }
278278
279- private void InitializeObjects ( )
279+ /// <summary>
280+ /// Validates serialization and deserilization of Dictionary containing DatabaseTable
281+ /// The table will have dollar sign prefix ($) in the column name
282+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
283+ /// </summary>
284+ [ TestMethod ]
285+ public void TestDictionaryDatabaseObjectSerializationDeserialization_WithDollarColumn ( )
280286 {
287+ InitializeObjects ( true ) ;
288+
289+ _options = new ( )
290+ {
291+ Converters = {
292+ new DatabaseObjectConverter ( ) ,
293+ new TypeConverter ( )
294+ } ,
295+ ReferenceHandler = ReferenceHandler . Preserve ,
296+ } ;
297+
298+ Dictionary < string , DatabaseObject > dict = new ( ) { { "person" , _databaseTable } } ;
299+
300+ string serializedDict = JsonSerializer . Serialize ( dict , _options ) ;
301+ Dictionary < string , DatabaseObject > deserializedDict = JsonSerializer . Deserialize < Dictionary < string , DatabaseObject > > ( serializedDict , _options ) ! ;
302+
303+ DatabaseTable deserializedDatabaseTable = ( DatabaseTable ) deserializedDict [ "person" ] ;
304+
305+ Assert . AreEqual ( deserializedDatabaseTable . SourceType , _databaseTable . SourceType ) ;
306+ Assert . AreEqual ( deserializedDatabaseTable . FullName , _databaseTable . FullName ) ;
307+ deserializedDatabaseTable . Equals ( _databaseTable ) ;
308+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . SourceDefinition , _databaseTable . SourceDefinition , "$FirstName" ) ;
309+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseTable . TableDefinition , _databaseTable . TableDefinition , "$FirstName" ) ;
310+ }
311+
312+ /// <summary>
313+ /// Validates serialization and deserilization of Dictionary containing DatabaseView
314+ /// The table will have dollar sign prefix ($) in the column name
315+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
316+ /// </summary>
317+ [ TestMethod ]
318+ public void TestDatabaseViewSerializationDeserialization_WithDollarColumn ( )
319+ {
320+ InitializeObjects ( true ) ;
321+
322+ TestTypeNameChanges ( _databaseView , "DatabaseView" ) ;
323+
324+ // Test to catch if there is change in number of properties/fields
325+ // Note: On Addition of property make sure it is added in following object creation _databaseView and include in serialization
326+ // and deserialization test.
327+ int fields = typeof ( DatabaseView ) . GetProperties ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) . Length ;
328+ Assert . AreEqual ( fields , 6 ) ;
329+
330+ string serializedDatabaseView = JsonSerializer . Serialize ( _databaseView , _options ) ;
331+ DatabaseView deserializedDatabaseView = JsonSerializer . Deserialize < DatabaseView > ( serializedDatabaseView , _options ) ! ;
332+
333+ Assert . AreEqual ( deserializedDatabaseView . SourceType , _databaseView . SourceType ) ;
334+ deserializedDatabaseView . Equals ( _databaseView ) ;
335+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseView . SourceDefinition , _databaseView . SourceDefinition , "$FirstName" ) ;
336+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseView . ViewDefinition , _databaseView . ViewDefinition , "$FirstName" ) ;
337+ }
338+
339+ /// <summary>
340+ /// Validates serialization and deserilization of Dictionary containing DatabaseStoredProcedure
341+ /// The table will have dollar sign prefix ($) in the column name
342+ /// this is how we serialize and deserialize metadataprovider.EntityToDatabaseObject dict.
343+ /// </summary>
344+ [ TestMethod ]
345+ public void TestDatabaseStoredProcedureSerializationDeserialization_WithDollarColumn ( )
346+ {
347+ InitializeObjects ( true ) ;
348+
349+ TestTypeNameChanges ( _databaseStoredProcedure , "DatabaseStoredProcedure" ) ;
350+
351+ // Test to catch if there is change in number of properties/fields
352+ // Note: On Addition of property make sure it is added in following object creation _databaseStoredProcedure and include in serialization
353+ // and deserialization test.
354+ int fields = typeof ( DatabaseStoredProcedure ) . GetProperties ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) . Length ;
355+ Assert . AreEqual ( fields , 6 ) ;
356+
357+ string serializedDatabaseSP = JsonSerializer . Serialize ( _databaseStoredProcedure , _options ) ;
358+ DatabaseStoredProcedure deserializedDatabaseSP = JsonSerializer . Deserialize < DatabaseStoredProcedure > ( serializedDatabaseSP , _options ) ! ;
359+
360+ Assert . AreEqual ( deserializedDatabaseSP . SourceType , _databaseStoredProcedure . SourceType ) ;
361+ deserializedDatabaseSP . Equals ( _databaseStoredProcedure ) ;
362+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseSP . SourceDefinition , _databaseStoredProcedure . SourceDefinition , "$FirstName" , true ) ;
363+ VerifySourceDefinitionSerializationDeserialization ( deserializedDatabaseSP . StoredProcedureDefinition , _databaseStoredProcedure . StoredProcedureDefinition , "$FirstName" , true ) ;
364+ }
365+
366+ private void InitializeObjects ( bool generateDollaredColumn = false )
367+ {
368+ string columnName = generateDollaredColumn ? "$FirstName" : "FirstName" ;
281369 _options = new ( )
282370 {
283371 // ObjectConverter behavior different in .NET8 most likely due to
@@ -289,10 +377,11 @@ private void InitializeObjects()
289377 new DatabaseObjectConverter ( ) ,
290378 new TypeConverter ( )
291379 }
380+
292381 } ;
293382
294383 _columnDefinition = GetColumnDefinition ( typeof ( string ) , DbType . String , true , false , false , new string ( "John" ) , false ) ;
295- _sourceDefinition = GetSourceDefinition ( false , false , new List < string > ( ) { "FirstName" } , _columnDefinition ) ;
384+ _sourceDefinition = GetSourceDefinition ( false , false , new List < string > ( ) { columnName } , _columnDefinition ) ;
296385
297386 _databaseTable = new DatabaseTable ( )
298387 {
@@ -311,10 +400,10 @@ private void InitializeObjects()
311400 {
312401 IsInsertDMLTriggerEnabled = false ,
313402 IsUpdateDMLTriggerEnabled = false ,
314- PrimaryKey = new List < string > ( ) { "FirstName" } ,
403+ PrimaryKey = new List < string > ( ) { columnName } ,
315404 } ,
316405 } ;
317- _databaseView . ViewDefinition . Columns . Add ( "FirstName" , _columnDefinition ) ;
406+ _databaseView . ViewDefinition . Columns . Add ( columnName , _columnDefinition ) ;
318407
319408 _parameterDefinition = new ( )
320409 {
@@ -331,10 +420,10 @@ private void InitializeObjects()
331420 SourceType = EntitySourceType . StoredProcedure ,
332421 StoredProcedureDefinition = new ( )
333422 {
334- PrimaryKey = new List < string > ( ) { "FirstName" } ,
423+ PrimaryKey = new List < string > ( ) { columnName } ,
335424 }
336425 } ;
337- _databaseStoredProcedure . StoredProcedureDefinition . Columns . Add ( "FirstName" , _columnDefinition ) ;
426+ _databaseStoredProcedure . StoredProcedureDefinition . Columns . Add ( columnName , _columnDefinition ) ;
338427 _databaseStoredProcedure . StoredProcedureDefinition . Parameters . Add ( "Id" , _parameterDefinition ) ;
339428 }
340429
0 commit comments