-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathGetMultiTests.cs
139 lines (111 loc) · 4.11 KB
/
GetMultiTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nest.Tests.MockData;
using NUnit.Framework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Nest;
using Newtonsoft.Json.Converters;
using Nest.Resolvers.Converters;
using Nest.Tests.MockData.Domain;
using FluentAssertions;
namespace Nest.Tests.Integration.Core.Get
{
[TestFixture]
public class GetMultiTests : IntegrationTests
{
[Test]
public void GetMultiSimple()
{
var result = this._client.MultiGet(a => a
.Get<ElasticsearchProject>(g=>g.Id(NestTestData.Data[1].Id))
.Get<Person>(g => g.Id(NestTestData.People[1].Id))
);
var objects = result.Documents;
objects.Should().NotBeNull().And.HaveCount(2);
var person = result.Source<Person>(NestTestData.People[1].Id);
person.Should().NotBeNull();
person.FirstName.Should().NotBeNullOrEmpty();
}
[Test]
public void GetMultiSimpleWithMissingItem()
{
var project = -200;
var frank = -204;
var lewisId = NestTestData.People[5].Id;
var result = this._client.MultiGet(a => a
.Get<Person>(g => g.Id(project))
.Get<Person>(g => g.Id(frank))
.Get<Person>(g => g.Id(lewisId))
);
var objects = result.Documents;
objects.Should().NotBeNull()
.And.HaveCount(3);
var missingPerson = result.Get<Person>(project);
missingPerson.Should().NotBeNull();
missingPerson.Found.Should().BeFalse();
var missingPersonDirect = result.Source<Person>(frank);
missingPersonDirect.Should().BeNull();
var lewis = result.Source<Person>(lewisId);
lewis.Should().NotBeNull();
lewis.FirstName.Should().NotBeNullOrEmpty();
}
[Test]
public void GetMultiWithMetaData()
{
var projectId = NestTestData.Data[14].Id;
var authorId = NestTestData.People[11].Id;
var result = this._client.MultiGet(a => a
.Get<ElasticsearchProject>(g => g.Id(projectId).Fields(p=>p.Id, p=>p.Followers.First().FirstName))
.Get<Person>(g => g.Id(authorId).Type("person").Index(ElasticsearchConfiguration.DefaultIndex).Fields(p => p.Id, p => p.FirstName))
);
var objects = result.Documents;
objects.Should().NotBeNull()
.And.HaveCount(2);
var people = objects.OfType<MultiGetHit<Person>>();
people.Should().HaveCount(1);
var personHit = people.FirstOrDefault(p => p.Id == authorId.ToString());
personHit.Should().NotBeNull();
personHit.Found.Should().BeTrue();
personHit.Version.Should().NotBeNullOrEmpty().And.Match("1");
var fieldSelection = personHit.FieldSelection;
fieldSelection.Should().NotBeNull();
fieldSelection.FieldValues<Person, int>(p=>p.Id).Should().BeEquivalentTo(new []{authorId});
fieldSelection.FieldValues<Person, string>(p => p.FirstName)
.Should().NotBeEmpty();
}
[Test]
public void GetMultiWithMetaDataUsingCleanApi()
{
var projectId = NestTestData.Data[8].Id;
var authorId = NestTestData.People[5].Id;
var result = this._client.MultiGet(a => a
.Get<ElasticsearchProject>(g => g.Id(projectId).Fields(p => p.Id, p => p.Followers.First().FirstName))
.Get<Person>(g => g
.Id(authorId)
.Type("person")
.Index(ElasticsearchConfiguration.DefaultIndex)
.Fields(p => p.Id, p => p.FirstName)
)
);
var personHit = result.Get<Person>(authorId);
personHit.Should().NotBeNull();
personHit.Found.Should().BeTrue();
personHit.Version.Should().NotBeNullOrEmpty().And.Match("1");
//personHit.FieldSelection would work too
var personFieldSelection = result.GetFieldSelection<Person>(authorId);
personFieldSelection.Should().NotBeNull();
personFieldSelection.FieldValues<Person, int>(p => p.Id).Should().BeEquivalentTo(new []{authorId});
personFieldSelection.FieldValues<Person, string>(p => p.FirstName)
.Should().NotBeEmpty();
var projectFieldSelection = result.GetFieldSelection<ElasticsearchProject>(projectId);
projectFieldSelection.Should().NotBeNull();
projectFieldSelection.FieldValues<ElasticsearchProject, int>(p => p.Id)
.Should().BeEquivalentTo(new []{projectId});
projectFieldSelection.FieldValues<ElasticsearchProject, string>(p => p.Followers.First().FirstName)
.Should().NotBeEmpty();
}
}
}