4
4
using Elasticsearch . Net ;
5
5
using FluentAssertions ;
6
6
using Nest ;
7
+ using Newtonsoft . Json . Linq ;
7
8
using Tests . Framework ;
8
9
using Tests . Framework . Integration ;
9
10
using Tests . Framework . MockData ;
@@ -69,16 +70,19 @@ protected override LazyResponses ClientUsage() => Calls(
69
70
[ Collection ( IntegrationContext . Indexing ) ]
70
71
public class IndexIntegrationTests : SimpleIntegration
71
72
{
72
- public IndexIntegrationTests ( IndexingCluster cluster ) : base ( cluster ) { }
73
+ public IndexIntegrationTests ( IndexingCluster cluster ) : base ( cluster )
74
+ {
75
+ }
73
76
74
- [ I ] public void OpTypeCreate ( )
77
+ [ I ]
78
+ public void OpTypeCreate ( )
75
79
{
76
80
var indexName = this . RandomString ( ) ;
77
81
var project = Project . Generator . Generate ( 1 ) . First ( ) ;
78
82
var indexResult = this . Client . Index ( project , f => f
79
83
. Index ( indexName )
80
84
. OpType ( OpType . Create )
81
- ) ;
85
+ ) ;
82
86
indexResult . IsValid . Should ( ) . BeTrue ( ) ;
83
87
indexResult . ApiCall . HttpStatusCode . Should ( ) . Be ( 201 ) ;
84
88
indexResult . Created . Should ( ) . BeTrue ( ) ;
@@ -89,18 +93,19 @@ [I] public void OpTypeCreate()
89
93
indexResult = this . Client . Index ( project , f => f
90
94
. Index ( indexName )
91
95
. OpType ( OpType . Create )
92
- ) ;
96
+ ) ;
93
97
94
98
indexResult . IsValid . Should ( ) . BeFalse ( ) ;
95
99
indexResult . Created . Should ( ) . BeFalse ( ) ;
96
100
indexResult . ApiCall . HttpStatusCode . Should ( ) . Be ( 409 ) ;
97
101
}
98
102
99
- [ I ] public void Index ( )
103
+ [ I ]
104
+ public void Index ( )
100
105
{
101
106
var indexName = this . RandomString ( ) ;
102
107
var project = Project . Generator . Generate ( 1 ) . First ( ) ;
103
- var indexResult = this . Client . Index ( project , f => f . Index ( indexName ) ) ;
108
+ var indexResult = this . Client . Index ( project , f => f . Index ( indexName ) ) ;
104
109
indexResult . IsValid . Should ( ) . BeTrue ( ) ;
105
110
indexResult . ApiCall . HttpStatusCode . Should ( ) . Be ( 201 ) ;
106
111
indexResult . Created . Should ( ) . BeTrue ( ) ;
@@ -109,13 +114,68 @@ [I] public void Index()
109
114
indexResult . Id . Should ( ) . Be ( project . Name ) ;
110
115
indexResult . Version . Should ( ) . Be ( 1 ) ;
111
116
112
- indexResult = this . Client . Index ( project , f => f . Index ( indexName ) ) ;
117
+ indexResult = this . Client . Index ( project , f => f . Index ( indexName ) ) ;
113
118
114
119
indexResult . IsValid . Should ( ) . BeTrue ( ) ;
115
120
indexResult . Created . Should ( ) . BeFalse ( ) ;
116
121
indexResult . ApiCall . HttpStatusCode . Should ( ) . Be ( 200 ) ;
117
122
indexResult . Version . Should ( ) . Be ( 2 ) ;
118
123
}
119
124
125
+ [ Collection ( IntegrationContext . Indexing ) ]
126
+ public class IndexJObjectIntegrationTests : SimpleIntegration
127
+ {
128
+ public IndexJObjectIntegrationTests ( IndexingCluster cluster ) : base ( cluster ) { }
129
+
130
+ [ I ]
131
+ public void Index ( )
132
+ {
133
+ var indexName = this . RandomString ( ) ;
134
+
135
+ var jObjects = Enumerable . Range ( 1 , 1000 )
136
+ . Select ( i =>
137
+ new JObject
138
+ {
139
+ { "id" , i } ,
140
+ { "name" , $ "name { i } "} ,
141
+ { "value" , Math . Pow ( i , 2 ) } ,
142
+ { "date" , new DateTime ( 2016 , 1 , 1 ) } ,
143
+ { "child" , new JObject
144
+ {
145
+ { "child_name" , $ "child_name { i } { i } " } ,
146
+ { "child_value" , 3 }
147
+ }
148
+ }
149
+ } ) ;
150
+
151
+ var jObject = jObjects . First ( ) ;
152
+
153
+ var indexResult = this . Client . Index ( jObject , f => f
154
+ . Index ( indexName )
155
+ . Type ( "example" )
156
+ . Id ( jObject [ "id" ] . Value < int > ( ) )
157
+ ) ;
158
+
159
+ indexResult . IsValid . Should ( ) . BeTrue ( ) ;
160
+ indexResult . ApiCall . HttpStatusCode . Should ( ) . Be ( 201 ) ;
161
+ indexResult . Created . Should ( ) . BeTrue ( ) ;
162
+ indexResult . Index . Should ( ) . Be ( indexName ) ;
163
+
164
+ var bulkResponse = this . Client . Bulk ( b => b
165
+ . IndexMany ( jObjects . Skip ( 1 ) , ( bi , d ) => bi
166
+ . Document ( d )
167
+ . Id ( d [ "id" ] . Value < int > ( ) )
168
+ . Index ( indexName )
169
+ . Type ( "example" )
170
+ )
171
+ ) ;
172
+
173
+ foreach ( var response in bulkResponse . Items )
174
+ {
175
+ response . IsValid . Should ( ) . BeTrue ( ) ;
176
+ response . Status . Should ( ) . Be ( 201 ) ;
177
+ }
178
+ }
179
+ }
120
180
}
121
181
}
0 commit comments