File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
Algolia.Search.Test/Utils Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change
1
+ using Algolia . Search . Utils ;
2
+ using Newtonsoft . Json . Linq ;
3
+ using NUnit . Framework ;
4
+
5
+ namespace Algolia . Search . Test . Utils ;
6
+
7
+ class TestRecord
8
+ {
9
+ public string ObjectID { get ; set ; }
10
+ public string Name { get ; set ; }
11
+ }
12
+
13
+ [ TestFixture ]
14
+ [ Parallelizable ]
15
+ public class AlgoliaHelperTest
16
+ {
17
+ [ Test ]
18
+ [ Parallelizable ]
19
+ public void TestGetObjectIdFromClass ( )
20
+ {
21
+ var objectId = "1-2_1-2" ;
22
+ var record = new TestRecord
23
+ {
24
+ ObjectID = objectId ,
25
+ Name = "this is a test"
26
+ } ;
27
+ Assert . AreEqual ( objectId , AlgoliaHelper . GetObjectID ( record ) ) ;
28
+ }
29
+
30
+ [ Test ]
31
+ [ Parallelizable ]
32
+ public void TestGetObjectIdFromJObject ( )
33
+ {
34
+ var objectId = "1-2_1-2" ;
35
+ var record = new JObject
36
+ {
37
+ { "objectID" , objectId } ,
38
+ { "name" , "this is a test" }
39
+ } ;
40
+ Assert . AreEqual ( objectId , AlgoliaHelper . GetObjectID ( record ) ) ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -105,11 +105,11 @@ internal static string GetObjectID<T>(T data)
105
105
106
106
if ( itemType == typeof ( JObject ) )
107
107
{
108
- JProperty objectID = JObject . FromObject ( data ) . Property ( "objectID" ) ;
108
+ var objectIdJProperty = JObject . FromObject ( data ) . Property ( "objectID" ) ;
109
109
110
- if ( objectID != null && objectID . ToString ( ) != "" )
110
+ if ( objectIdJProperty != null && ! string . IsNullOrWhiteSpace ( objectIdJProperty . Value . ToString ( ) ) )
111
111
{
112
- return objectID . ToString ( ) ;
112
+ return objectIdJProperty . Value . ToString ( ) ;
113
113
}
114
114
}
115
115
You can’t perform that action at this time.
0 commit comments