File tree 3 files changed +73
-9
lines changed
src/Elastic.Clients.Elasticsearch/Serialization
tests/Tests/Document/Multiple/MGet
3 files changed +73
-9
lines changed Original file line number Diff line number Diff line change 27
27
' 8.3.3' ,
28
28
' 8.4.3' ,
29
29
" 8.5.3" ,
30
- ' 8.6.0-SNAPSHOT' ,
30
+ ' 8.6.1' ,
31
+ " 8.7.0-SNAPSHOT"
31
32
' latest-8'
32
33
]
33
34
Original file line number Diff line number Diff line change @@ -40,32 +40,32 @@ private sealed class ResponseItemConverter<TDocument> : JsonConverter<MultiGetRe
40
40
41
41
try
42
42
{
43
- var result = JsonSerializer . Deserialize < GetResult < TDocument > > ( ref readerCopy , options ) ;
43
+ var result = JsonSerializer . Deserialize < MultiGetError > ( ref reader , options ) ;
44
44
45
- // If we have a version number, we can be sure this isn't an error
46
- if ( result is not null && result . Version is not null )
45
+ if ( result is not null && result . Error is not null )
47
46
{
48
- reader = readerCopy ; // Ensure we swap the reader to reflect the data we have consumed.
49
47
return new MultiGetResponseItem < TDocument > ( result ) ;
50
48
}
51
49
}
52
50
catch ( Exception ex )
53
51
{
54
- getResultException = ex ;
52
+ errorException = ex ;
55
53
}
56
54
57
55
try
58
56
{
59
- var result = JsonSerializer . Deserialize < MultiGetError > ( ref reader , options ) ;
57
+ var result = JsonSerializer . Deserialize < GetResult < TDocument > > ( ref readerCopy , options ) ;
60
58
61
- if ( result is not null && result . Error is not null )
59
+ // If we have a version number, we can be sure this isn't an error
60
+ if ( result is not null )
62
61
{
62
+ reader = readerCopy ; // Ensure we swap the reader to reflect the data we have consumed.
63
63
return new MultiGetResponseItem < TDocument > ( result ) ;
64
64
}
65
65
}
66
66
catch ( Exception ex )
67
67
{
68
- errorException = ex ;
68
+ getResultException = ex ;
69
69
}
70
70
71
71
Exception innerException = null ;
Original file line number Diff line number Diff line change
1
+ // Licensed to Elasticsearch B.V under one or more agreements.
2
+ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
+ // See the LICENSE file in the project root for more information.
4
+
5
+ using System . Linq ;
6
+ using Tests . Serialization ;
7
+ using Xunit ;
8
+
9
+ namespace Tests . Document . Multiple . MGet ;
10
+
11
+ public class MGetResponseSerialization : SerializerTestBase
12
+ {
13
+ private const string ResponseJson = @"{
14
+ ""docs"": [
15
+ {
16
+ ""_index"": ""foos"",
17
+ ""_id"": ""001"",
18
+ ""_version"": 5,
19
+ ""_seq_no"": 8,
20
+ ""_primary_term"": 1,
21
+ ""found"": true,
22
+ ""_source"": {
23
+ ""id"": ""001"",
24
+ ""name"": ""FooA""
25
+ }
26
+ },
27
+ {
28
+ ""_index"": ""foos"",
29
+ ""_id"": ""002"",
30
+ ""_version"": 5,
31
+ ""_seq_no"": 9,
32
+ ""_primary_term"": 1,
33
+ ""found"": true,
34
+ ""_source"": {
35
+ ""id"": ""002"",
36
+ ""name"": ""FooB""
37
+ }
38
+ },
39
+ {
40
+ ""_index"": ""foos"",
41
+ ""_id"": ""nonexistant"",
42
+ ""found"": false
43
+ }
44
+ ]
45
+ }" ;
46
+
47
+ [ U ]
48
+ public void MultiGetResponse_DeserializesCorrectly_WhenIdsAreNotFound ( )
49
+ {
50
+ var response = DeserializeJsonString < MultiGetResponse < Foo > > ( ResponseJson ) ;
51
+
52
+ response . Docs . Should ( ) . HaveCount ( 3 ) ;
53
+ response . Docs . ElementAt ( 0 ) . Match ( r => r . Found . Should ( ) . BeTrue ( ) , _ => Assert . Fail ( "Union item should not have matched." ) ) ;
54
+ response . Docs . ElementAt ( 1 ) . Match ( r => r . Found . Should ( ) . BeTrue ( ) , _ => Assert . Fail ( "Union item should not have matched." ) ) ;
55
+ response . Docs . ElementAt ( 2 ) . Match ( r => r . Found . Should ( ) . BeFalse ( ) , _ => Assert . Fail ( "Union item should not have matched." ) ) ;
56
+ }
57
+ }
58
+
59
+ internal class Foo
60
+ {
61
+ public string Id { get ; set ; }
62
+ public string Name { get ; set ; }
63
+ }
You can’t perform that action at this time.
0 commit comments