File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
src/JsonApiDotNetCore/Models Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ public string StringId
3737 /// </summary>
3838 protected virtual string GetStringId ( object value )
3939 {
40+ if ( value == null )
41+ return string . Empty ;
42+
4043 var type = typeof ( T ) ;
4144 var stringValue = value . ToString ( ) ;
4245
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ public void Setting_StringId_To_Null_Sets_Id_As_Default()
2121 Assert . Equal ( 0 , resource . Id ) ;
2222 }
2323
24- private class IntId : Identifiable { }
24+ [ Fact ]
25+ public void GetStringId_Returns_EmptyString_If_Object_Is_Null ( )
26+ {
27+ var resource = new IntId ( ) ;
28+ var stringId = resource . ExposedGetStringId ( null ) ;
29+ Assert . Equal ( string . Empty , stringId ) ;
30+ }
31+
32+ private class IntId : Identifiable {
33+ public string ExposedGetStringId ( object value ) => GetStringId ( value ) ;
34+ }
2535 }
2636}
You can’t perform that action at this time.
0 commit comments